dashboard.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. (function($) {
  2. 'use strict';
  3. $(function() {
  4. Chart.defaults.global.legend.labels.usePointStyle = true;
  5. if ($("#serviceSaleProgress").length) {
  6. var bar = new ProgressBar.Circle(serviceSaleProgress, {
  7. color: 'url(#gradient)',
  8. // This has to be the same size as the maximum width to
  9. // prevent clipping
  10. strokeWidth: 8,
  11. trailWidth: 8,
  12. easing: 'easeInOut',
  13. duration: 1400,
  14. text: {
  15. autoStyleContainer: false
  16. },
  17. from: { color: '#aaa', width: 6 },
  18. to: { color: '#57c7d4', width: 6 }
  19. });
  20. bar.animate(.65); // Number from 0.0 to 1.0
  21. bar.path.style.strokeLinecap = 'round';
  22. let linearGradient = '<defs><linearGradient id="gradient" x1="0%" y1="0%" x2="100%" y2="0%" gradientUnits="userSpaceOnUse"><stop offset="20%" stop-color="#da8cff"/><stop offset="50%" stop-color="#9a55ff"/></linearGradient></defs>';
  23. bar.svg.insertAdjacentHTML('afterBegin', linearGradient);
  24. }
  25. if ($("#productSaleProgress").length) {
  26. var bar = new ProgressBar.Circle(productSaleProgress, {
  27. color: 'url(#productGradient)',
  28. // This has to be the same size as the maximum width to
  29. // prevent clipping
  30. strokeWidth: 8,
  31. trailWidth: 8,
  32. easing: 'easeInOut',
  33. duration: 1400,
  34. text: {
  35. autoStyleContainer: false
  36. },
  37. from: { color: '#aaa', width: 6 },
  38. to: { color: '#57c7d4', width: 6 }
  39. });
  40. bar.animate(.6); // Number from 0.0 to 1.0
  41. bar.path.style.strokeLinecap = 'round';
  42. let linearGradient = '<defs><linearGradient id="productGradient" x1="0%" y1="0%" x2="100%" y2="0%" gradientUnits="userSpaceOnUse"><stop offset="40%" stop-color="#36d7e8"/><stop offset="70%" stop-color="#b194fa"/></linearGradient></defs>';
  43. bar.svg.insertAdjacentHTML('afterBegin', linearGradient);
  44. }
  45. if ($("#points-chart").length) {
  46. var ctx = document.getElementById('points-chart').getContext("2d");
  47. var gradientStrokeViolet = ctx.createLinearGradient(0, 0, 0, 181);
  48. gradientStrokeViolet.addColorStop(0, 'rgba(218, 140, 255, 1)');
  49. gradientStrokeViolet.addColorStop(1, 'rgba(154, 85, 255, 1)');
  50. var myChart = new Chart(ctx, {
  51. type: 'bar',
  52. data: {
  53. labels: [1, 2, 3, 4, 5, 6, 7, 8],
  54. datasets: [
  55. {
  56. label: "North Zone",
  57. borderColor: gradientStrokeViolet,
  58. backgroundColor: gradientStrokeViolet,
  59. hoverBackgroundColor: gradientStrokeViolet,
  60. pointRadius: 0,
  61. fill: false,
  62. borderWidth: 1,
  63. fill: 'origin',
  64. data: [20, 40, 15, 35, 25, 50, 30, 20]
  65. },
  66. {
  67. label: "South Zone",
  68. borderColor: '#e9eaee',
  69. backgroundColor: '#e9eaee',
  70. hoverBackgroundColor: '#e9eaee',
  71. pointRadius: 0,
  72. fill: false,
  73. borderWidth: 1,
  74. fill: 'origin',
  75. data: [40, 30, 20, 10, 50, 15, 35, 20]
  76. }
  77. ]
  78. },
  79. options: {
  80. legend: {
  81. display: false
  82. },
  83. scales: {
  84. yAxes: [{
  85. ticks: {
  86. display: false,
  87. min: 0,
  88. stepSize: 10
  89. },
  90. gridLines: {
  91. drawBorder: false,
  92. display: false
  93. }
  94. }],
  95. xAxes: [{
  96. gridLines: {
  97. display:false,
  98. drawBorder: false,
  99. color: 'rgba(0,0,0,1)',
  100. zeroLineColor: '#eeeeee'
  101. },
  102. ticks: {
  103. padding: 20,
  104. fontColor: "#9c9fa6",
  105. autoSkip: true,
  106. },
  107. barPercentage: 0.7
  108. }]
  109. }
  110. },
  111. elements: {
  112. point: {
  113. radius: 0
  114. }
  115. }
  116. })
  117. }
  118. if ($("#events-chart").length) {
  119. var ctx = document.getElementById('events-chart').getContext("2d");
  120. var gradientStrokeBlue = ctx.createLinearGradient(0, 0, 0, 181);
  121. gradientStrokeBlue.addColorStop(0, 'rgba(54, 215, 232, 1)');
  122. gradientStrokeBlue.addColorStop(1, 'rgba(177, 148, 250, 1)');
  123. var myChart = new Chart(ctx, {
  124. type: 'bar',
  125. data: {
  126. labels: [1, 2, 3, 4, 5, 6, 7, 8],
  127. datasets: [
  128. {
  129. label: "Domestic",
  130. borderColor: gradientStrokeBlue,
  131. backgroundColor: gradientStrokeBlue,
  132. hoverBackgroundColor: gradientStrokeBlue,
  133. pointRadius: 0,
  134. fill: false,
  135. borderWidth: 1,
  136. fill: 'origin',
  137. data: [20, 40, 15, 35, 25, 50, 30, 20]
  138. },
  139. {
  140. label: "International",
  141. borderColor: '#e9eaee',
  142. backgroundColor: '#e9eaee',
  143. hoverBackgroundColor: '#e9eaee',
  144. pointRadius: 0,
  145. fill: false,
  146. borderWidth: 1,
  147. fill: 'origin',
  148. data: [40, 30, 20, 10, 50, 15, 35, 20]
  149. }
  150. ]
  151. },
  152. options: {
  153. legend: {
  154. display: false
  155. },
  156. scales: {
  157. yAxes: [{
  158. ticks: {
  159. display: false,
  160. min: 0,
  161. stepSize: 10
  162. },
  163. gridLines: {
  164. drawBorder: false,
  165. display: false
  166. }
  167. }],
  168. xAxes: [{
  169. gridLines: {
  170. display:false,
  171. drawBorder: false,
  172. color: 'rgba(0,0,0,1)',
  173. zeroLineColor: '#eeeeee'
  174. },
  175. ticks: {
  176. padding: 20,
  177. fontColor: "#9c9fa6",
  178. autoSkip: true,
  179. },
  180. barPercentage: 0.7
  181. }]
  182. }
  183. },
  184. elements: {
  185. point: {
  186. radius: 0
  187. }
  188. }
  189. })
  190. }
  191. if ($("#visit-sale-chart").length) {
  192. Chart.defaults.global.legend.labels.usePointStyle = true;
  193. var ctx = document.getElementById('visit-sale-chart').getContext("2d");
  194. var gradientStrokeViolet = ctx.createLinearGradient(0, 0, 0, 181);
  195. gradientStrokeViolet.addColorStop(0, 'rgba(218, 140, 255, 1)');
  196. gradientStrokeViolet.addColorStop(1, 'rgba(154, 85, 255, 1)');
  197. var gradientLegendViolet = 'linear-gradient(to right, rgba(218, 140, 255, 1), rgba(154, 85, 255, 1))';
  198. var gradientStrokeBlue = ctx.createLinearGradient(0, 0, 0, 360);
  199. gradientStrokeBlue.addColorStop(0, 'rgba(54, 215, 232, 1)');
  200. gradientStrokeBlue.addColorStop(1, 'rgba(177, 148, 250, 1)');
  201. var gradientLegendBlue = 'linear-gradient(to right, rgba(54, 215, 232, 1), rgba(177, 148, 250, 1))';
  202. var gradientStrokeRed = ctx.createLinearGradient(0, 0, 0, 300);
  203. gradientStrokeRed.addColorStop(0, 'rgba(255, 191, 150, 1)');
  204. gradientStrokeRed.addColorStop(1, 'rgba(254, 112, 150, 1)');
  205. var gradientLegendRed = 'linear-gradient(to right, rgba(255, 191, 150, 1), rgba(254, 112, 150, 1))';
  206. var myChart = new Chart(ctx, {
  207. type: 'bar',
  208. data: {
  209. labels: ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG'],
  210. datasets: [
  211. {
  212. label: "CHN",
  213. borderColor: gradientStrokeViolet,
  214. backgroundColor: gradientStrokeViolet,
  215. hoverBackgroundColor: gradientStrokeViolet,
  216. legendColor: gradientLegendViolet,
  217. pointRadius: 0,
  218. fill: false,
  219. borderWidth: 1,
  220. fill: 'origin',
  221. data: [20, 40, 15, 35, 25, 50, 30, 20]
  222. },
  223. {
  224. label: "USA",
  225. borderColor: gradientStrokeRed,
  226. backgroundColor: gradientStrokeRed,
  227. hoverBackgroundColor: gradientStrokeRed,
  228. legendColor: gradientLegendRed,
  229. pointRadius: 0,
  230. fill: false,
  231. borderWidth: 1,
  232. fill: 'origin',
  233. data: [40, 30, 20, 10, 50, 15, 35, 40]
  234. },
  235. {
  236. label: "UK",
  237. borderColor: gradientStrokeBlue,
  238. backgroundColor: gradientStrokeBlue,
  239. hoverBackgroundColor: gradientStrokeBlue,
  240. legendColor: gradientLegendBlue,
  241. pointRadius: 0,
  242. fill: false,
  243. borderWidth: 1,
  244. fill: 'origin',
  245. data: [70, 10, 30, 40, 25, 50, 15, 30]
  246. }
  247. ]
  248. },
  249. options: {
  250. responsive: true,
  251. legend: false,
  252. legendCallback: function(chart) {
  253. var text = [];
  254. text.push('<ul>');
  255. for (var i = 0; i < chart.data.datasets.length; i++) {
  256. text.push('<li><span class="legend-dots" style="background:' +
  257. chart.data.datasets[i].legendColor +
  258. '"></span>');
  259. if (chart.data.datasets[i].label) {
  260. text.push(chart.data.datasets[i].label);
  261. }
  262. text.push('</li>');
  263. }
  264. text.push('</ul>');
  265. return text.join('');
  266. },
  267. scales: {
  268. yAxes: [{
  269. ticks: {
  270. display: false,
  271. min: 0,
  272. stepSize: 20,
  273. max: 80
  274. },
  275. gridLines: {
  276. drawBorder: false,
  277. color: 'rgba(235,237,242,1)',
  278. zeroLineColor: 'rgba(235,237,242,1)'
  279. }
  280. }],
  281. xAxes: [{
  282. gridLines: {
  283. display:false,
  284. drawBorder: false,
  285. color: 'rgba(0,0,0,1)',
  286. zeroLineColor: 'rgba(235,237,242,1)'
  287. },
  288. ticks: {
  289. padding: 20,
  290. fontColor: "#9c9fa6",
  291. autoSkip: true,
  292. },
  293. categoryPercentage: 0.5,
  294. barPercentage: 0.5
  295. }]
  296. }
  297. },
  298. elements: {
  299. point: {
  300. radius: 0
  301. }
  302. }
  303. })
  304. $("#visit-sale-chart-legend").html(myChart.generateLegend());
  305. }
  306. if ($("#traffic-chart").length) {
  307. var gradientStrokeBlue = ctx.createLinearGradient(0, 0, 0, 181);
  308. gradientStrokeBlue.addColorStop(0, 'rgba(54, 215, 232, 1)');
  309. gradientStrokeBlue.addColorStop(1, 'rgba(177, 148, 250, 1)');
  310. var gradientLegendBlue = 'linear-gradient(to right, rgba(54, 215, 232, 1), rgba(177, 148, 250, 1))';
  311. var gradientStrokeRed = ctx.createLinearGradient(0, 0, 0, 50);
  312. gradientStrokeRed.addColorStop(0, 'rgba(255, 191, 150, 1)');
  313. gradientStrokeRed.addColorStop(1, 'rgba(254, 112, 150, 1)');
  314. var gradientLegendRed = 'linear-gradient(to right, rgba(255, 191, 150, 1), rgba(254, 112, 150, 1))';
  315. var gradientStrokeGreen = ctx.createLinearGradient(0, 0, 0, 300);
  316. gradientStrokeGreen.addColorStop(0, 'rgba(6, 185, 157, 1)');
  317. gradientStrokeGreen.addColorStop(1, 'rgba(132, 217, 210, 1)');
  318. var gradientLegendGreen = 'linear-gradient(to right, rgba(6, 185, 157, 1), rgba(132, 217, 210, 1))';
  319. var trafficChartData = {
  320. datasets: [{
  321. data: [30, 30, 40],
  322. backgroundColor: [
  323. gradientStrokeBlue,
  324. gradientStrokeGreen,
  325. gradientStrokeRed
  326. ],
  327. hoverBackgroundColor: [
  328. gradientStrokeBlue,
  329. gradientStrokeGreen,
  330. gradientStrokeRed
  331. ],
  332. borderColor: [
  333. gradientStrokeBlue,
  334. gradientStrokeGreen,
  335. gradientStrokeRed
  336. ],
  337. legendColor: [
  338. gradientLegendBlue,
  339. gradientLegendGreen,
  340. gradientLegendRed
  341. ]
  342. }],
  343. // These labels appear in the legend and in the tooltips when hovering different arcs
  344. labels: [
  345. 'Search Engines',
  346. 'Direct Click',
  347. 'Bookmarks Click',
  348. ]
  349. };
  350. var trafficChartOptions = {
  351. responsive: true,
  352. animation: {
  353. animateScale: true,
  354. animateRotate: true
  355. },
  356. legend: false,
  357. legendCallback: function(chart) {
  358. var text = [];
  359. text.push('<ul>');
  360. for (var i = 0; i < trafficChartData.datasets[0].data.length; i++) {
  361. text.push('<li><span class="legend-dots" style="background:' +
  362. trafficChartData.datasets[0].legendColor[i] +
  363. '"></span>');
  364. if (trafficChartData.labels[i]) {
  365. text.push(trafficChartData.labels[i]);
  366. }
  367. text.push('<span class="float-right">'+trafficChartData.datasets[0].data[i]+"%"+'</span>')
  368. text.push('</li>');
  369. }
  370. text.push('</ul>');
  371. return text.join('');
  372. }
  373. };
  374. var trafficChartCanvas = $("#traffic-chart").get(0).getContext("2d");
  375. var trafficChart = new Chart(trafficChartCanvas, {
  376. type: 'doughnut',
  377. data: trafficChartData,
  378. options: trafficChartOptions
  379. });
  380. $("#traffic-chart-legend").html(trafficChart.generateLegend());
  381. }
  382. if ($("#inline-datepicker").length) {
  383. $('#inline-datepicker').datepicker({
  384. enableOnReadonly: true,
  385. todayHighlight: true,
  386. });
  387. }
  388. });
  389. })(jQuery);