chart-chartjs.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. /*=========================================================================================
  2. File Name: chart-chartjs.js
  3. Description: Chartjs Examples
  4. ----------------------------------------------------------------------------------------
  5. Item name: Vuexy - Vuejs, HTML & Laravel Admin Dashboard Template
  6. Author: PIXINVENT
  7. Author URL: http://www.themeforest.net/user/pixinvent
  8. ==========================================================================================*/
  9. $(window).on("load", function () {
  10. var $primary = '#7367F0';
  11. var $success = '#28C76F';
  12. var $danger = '#EA5455';
  13. var $warning = '#FF9F43';
  14. var $label_color = '#1E1E1E';
  15. var grid_line_color = '#dae1e7';
  16. var scatter_grid_color = '#f3f3f3';
  17. var $scatter_point_light = '#D1D4DB';
  18. var $scatter_point_dark = '#5175E0';
  19. var $white = '#fff';
  20. var $black = '#000';
  21. var themeColors = [$primary, $success, $danger, $warning, $label_color];
  22. // Line Chart
  23. // ------------------------------------------
  24. //Get the context of the Chart canvas element we want to select
  25. var lineChartctx = $("#line-chart");
  26. // Chart Options
  27. var linechartOptions = {
  28. responsive: true,
  29. maintainAspectRatio: false,
  30. legend: {
  31. position: 'top',
  32. },
  33. hover: {
  34. mode: 'label'
  35. },
  36. scales: {
  37. xAxes: [{
  38. display: true,
  39. gridLines: {
  40. color: grid_line_color,
  41. },
  42. scaleLabel: {
  43. display: true,
  44. }
  45. }],
  46. yAxes: [{
  47. display: true,
  48. gridLines: {
  49. color: grid_line_color,
  50. },
  51. scaleLabel: {
  52. display: true,
  53. }
  54. }]
  55. },
  56. title: {
  57. display: true,
  58. text: 'World population per region (in millions)'
  59. }
  60. };
  61. // Chart Data
  62. var linechartData = {
  63. labels: [1500, 1600, 1700, 1750, 1800, 1850, 1900, 1950, 1999, 2050],
  64. datasets: [{
  65. label: "Africa",
  66. data: [86, 114, 106, 106, 107, 111, 133, 221, 783, 2478],
  67. borderColor: $primary,
  68. fill: false
  69. }, {
  70. data: [282, 350, 411, 502, 635, 809, 947, 1402, 3700, 5267],
  71. label: "Asia",
  72. borderColor: $success,
  73. fill: false
  74. }, {
  75. data: [168, 170, 178, 190, 203, 276, 408, 547, 675, 734],
  76. label: "Europe",
  77. borderColor: $danger,
  78. fill: false
  79. }, {
  80. data: [40, 20, 10, 16, 24, 38, 74, 167, 508, 784],
  81. label: "Latin America",
  82. borderColor: $warning,
  83. fill: false
  84. }, {
  85. data: [6, 3, 2, 2, 7, 26, 82, 172, 312, 433],
  86. label: "North America",
  87. borderColor: $label_color,
  88. fill: false
  89. }]
  90. };
  91. var lineChartconfig = {
  92. type: 'line',
  93. // Chart Options
  94. options: linechartOptions,
  95. data: linechartData
  96. };
  97. // Create the chart
  98. var lineChart = new Chart(lineChartctx, lineChartconfig);
  99. // Bar Chart
  100. // ------------------------------------------
  101. //Get the context of the Chart canvas element we want to select
  102. var barChartctx = $("#bar-chart");
  103. // Chart Options
  104. var barchartOptions = {
  105. // Elements options apply to all of the options unless overridden in a dataset
  106. // In this case, we are setting the border of each bar to be 2px wide
  107. elements: {
  108. rectangle: {
  109. borderWidth: 2,
  110. borderSkipped: 'left'
  111. }
  112. },
  113. responsive: true,
  114. maintainAspectRatio: false,
  115. responsiveAnimationDuration: 500,
  116. legend: { display: false },
  117. scales: {
  118. xAxes: [{
  119. display: true,
  120. gridLines: {
  121. color: grid_line_color,
  122. },
  123. scaleLabel: {
  124. display: true,
  125. }
  126. }],
  127. yAxes: [{
  128. display: true,
  129. gridLines: {
  130. color: grid_line_color,
  131. },
  132. scaleLabel: {
  133. display: true,
  134. },
  135. ticks: {
  136. stepSize: 1000
  137. },
  138. }],
  139. },
  140. title: {
  141. display: true,
  142. text: 'Predicted world population (millions) in 2050'
  143. },
  144. };
  145. // Chart Data
  146. var barchartData = {
  147. labels: ["Africa", "Asia", "Europe", "Latin America", "North America"],
  148. datasets: [{
  149. label: "Population (millions)",
  150. data: [2478, 5267, 734, 784, 433],
  151. backgroundColor: themeColors,
  152. borderColor: "transparent"
  153. }]
  154. };
  155. var barChartconfig = {
  156. type: 'bar',
  157. // Chart Options
  158. options: barchartOptions,
  159. data: barchartData
  160. };
  161. // Create the chart
  162. var barChart = new Chart(barChartctx, barChartconfig);
  163. // Horizontal Chart
  164. // -------------------------------------
  165. // Get the context of the Chart canvas element we want to select
  166. var horizontalChartctx = $("#horizontal-bar");
  167. var horizontalchartOptions = {
  168. // Elements options apply to all of the options unless overridden in a dataset
  169. // In this case, we are setting the border of each horizontal bar to be 2px wide
  170. elements: {
  171. rectangle: {
  172. borderWidth: 2,
  173. borderSkipped: 'right',
  174. borderSkipped: 'top',
  175. }
  176. },
  177. responsive: true,
  178. maintainAspectRatio: false,
  179. responsiveAnimationDuration: 500,
  180. legend: {
  181. display: false,
  182. },
  183. scales: {
  184. xAxes: [{
  185. display: true,
  186. gridLines: {
  187. color: grid_line_color,
  188. },
  189. scaleLabel: {
  190. display: true,
  191. }
  192. }],
  193. yAxes: [{
  194. display: true,
  195. gridLines: {
  196. color: grid_line_color,
  197. },
  198. scaleLabel: {
  199. display: true,
  200. }
  201. }]
  202. },
  203. title: {
  204. display: true,
  205. text: 'Predicted world population (millions) in 2050'
  206. }
  207. };
  208. // Chart Data
  209. var horizontalchartData = {
  210. labels: ["Africa", "Asia", "Europe", "Latin America", "North America"],
  211. datasets: [{
  212. label: "Population (millions)",
  213. data: [2478, 5267, 734, 784, 433],
  214. backgroundColor: themeColors,
  215. borderColor: "transparent"
  216. }]
  217. };
  218. var horizontalChartconfig = {
  219. type: 'horizontalBar',
  220. // Chart Options
  221. options: horizontalchartOptions,
  222. data: horizontalchartData
  223. };
  224. // Create the chart
  225. var horizontalChart = new Chart(horizontalChartctx, horizontalChartconfig);
  226. // Pie Chart
  227. // --------------------------------
  228. //Get the context of the Chart canvas element we want to select
  229. var pieChartctx = $("#simple-pie-chart");
  230. // Chart Options
  231. var piechartOptions = {
  232. responsive: true,
  233. maintainAspectRatio: false,
  234. responsiveAnimationDuration: 500,
  235. title: {
  236. display: true,
  237. text: 'Predicted world population (millions) in 2050'
  238. }
  239. };
  240. // Chart Data
  241. var piechartData = {
  242. labels: ["Africa", "Asia", "Europe", "Latin America", "North America"],
  243. datasets: [{
  244. label: "My First dataset",
  245. data: [2478, 5267, 734, 784, 433],
  246. backgroundColor: themeColors,
  247. }]
  248. };
  249. var pieChartconfig = {
  250. type: 'pie',
  251. // Chart Options
  252. options: piechartOptions,
  253. data: piechartData
  254. };
  255. // Create the chart
  256. var pieSimpleChart = new Chart(pieChartctx, pieChartconfig);
  257. // Doughnut Chart
  258. // ---------------------------------------------
  259. //Get the context of the Chart canvas element we want to select
  260. var doughnutChartctx = $("#simple-doughnut-chart");
  261. // Chart Options
  262. var doughnutchartOptions = {
  263. responsive: true,
  264. maintainAspectRatio: false,
  265. responsiveAnimationDuration: 500,
  266. title: {
  267. display: true,
  268. text: 'Predicted world population (millions) in 2050'
  269. }
  270. };
  271. // Chart Data
  272. var doughnutchartData = {
  273. labels: ["Africa", "Asia", "Europe", "Latin America", "North America"],
  274. datasets: [{
  275. label: "My First dataset",
  276. data: [2478, 5267, 734, 784, 433],
  277. backgroundColor: themeColors,
  278. }]
  279. };
  280. var doughnutChartconfig = {
  281. type: 'doughnut',
  282. // Chart Options
  283. options: doughnutchartOptions,
  284. data: doughnutchartData
  285. };
  286. // Create the chart
  287. var doughnutSimpleChart = new Chart(doughnutChartctx, doughnutChartconfig);
  288. // Radar Chart
  289. // ----------------------------------------
  290. //Get the context of the Chart canvas element we want to select
  291. var radarChartctx = $("#radar-chart");
  292. // Chart Options
  293. var radarchartOptions = {
  294. responsive: true,
  295. maintainAspectRatio: false,
  296. responsiveAnimationDuration: 500,
  297. legend: {
  298. position: 'top',
  299. },
  300. tooltips: {
  301. callbacks: {
  302. label: function (tooltipItems, data) {
  303. return data.datasets[tooltipItems.datasetIndex].label + ": " + tooltipItems.yLabel;
  304. }
  305. }
  306. },
  307. title: {
  308. display: true,
  309. text: 'Distribution in % of world population'
  310. },
  311. scale: {
  312. reverse: false,
  313. ticks: {
  314. beginAtZero: true,
  315. stepSize: 10
  316. }
  317. }
  318. };
  319. // Chart Data
  320. var radarchartData = {
  321. labels: ["Africa", "Asia", "Europe", "Latin America", "North America"],
  322. datasets: [{
  323. label: "1950",
  324. fill: true,
  325. backgroundColor: "rgba(179,181,198,0.2)",
  326. borderColor: "rgba(179,181,198,1)",
  327. pointBorderColor: $white,
  328. pointBackgroundColor: "rgba(179,181,198,1)",
  329. data: [8.77, 55.61, 21.69, 6.62, 6.82],
  330. }, {
  331. label: "2050",
  332. fill: true,
  333. backgroundColor: "rgba(255,99,132,0.2)",
  334. borderColor: "rgba(255,99,132,1)",
  335. pointBorderColor: $white,
  336. pointBackgroundColor: "rgba(255,99,132,1)",
  337. data: [25.48, 54.16, 7.61, 8.06, 4.45],
  338. },]
  339. };
  340. var radarChartconfig = {
  341. type: 'radar',
  342. // Chart Options
  343. options: radarchartOptions,
  344. data: radarchartData
  345. };
  346. // Create the chart
  347. var polarChart = new Chart(radarChartctx, radarChartconfig);
  348. // Polar Chart
  349. // -----------------------------------
  350. //Get the context of the Chart canvas element we want to select
  351. var polarChartctx = $("#polar-chart");
  352. // Chart Options
  353. var polarchartOptions = {
  354. responsive: true,
  355. maintainAspectRatio: false,
  356. responsiveAnimationDuration: 500,
  357. legend: {
  358. position: 'top',
  359. },
  360. title: {
  361. display: true,
  362. text: 'Predicted world population (millions) in 2050'
  363. },
  364. scale: {
  365. ticks: {
  366. beginAtZero: true,
  367. stepSize: 2000
  368. },
  369. reverse: false
  370. },
  371. animation: {
  372. animateRotate: false
  373. }
  374. };
  375. // Chart Data
  376. var polarchartData = {
  377. labels: ["Africa", "Asia", "Europe", "Latin America", "North America"],
  378. datasets: [{
  379. label: "Population (millions)",
  380. backgroundColor: themeColors,
  381. data: [2478, 5267, 734, 784, 433]
  382. }],
  383. };
  384. var polarChartconfig = {
  385. type: 'polarArea',
  386. // Chart Options
  387. options: polarchartOptions,
  388. data: polarchartData
  389. };
  390. // Create the chart
  391. var polarChart = new Chart(polarChartctx, polarChartconfig);
  392. // Bubble Chart
  393. // ---------------------------------------
  394. //Get the context of the Chart canvas element we want to select
  395. var bubbleChartctx = $("#bubble-chart");
  396. var randomScalingFactor = function () {
  397. return (Math.random() > 0.5 ? 1.0 : -1.0) * Math.round(Math.random() * 100);
  398. };
  399. // Chart Options
  400. var bubblechartOptions = {
  401. responsive: true,
  402. maintainAspectRatio: false,
  403. scales: {
  404. xAxes: [{
  405. display: true,
  406. gridLines: {
  407. color: grid_line_color,
  408. },
  409. scaleLabel: {
  410. display: true,
  411. labelString: "GDP (PPP)"
  412. }
  413. }],
  414. yAxes: [{
  415. display: true,
  416. gridLines: {
  417. color: grid_line_color,
  418. },
  419. scaleLabel: {
  420. display: true,
  421. labelString: "Happiness"
  422. },
  423. ticks: {
  424. stepSize: 0.5
  425. },
  426. }]
  427. },
  428. title: {
  429. display: true,
  430. text: 'Predicted world population (millions) in 2050'
  431. }
  432. };
  433. // Chart Data
  434. var bubblechartData = {
  435. animation: {
  436. duration: 10000
  437. },
  438. datasets: [{
  439. label: ["China"],
  440. backgroundColor: "rgba(255,221,50,0.2)",
  441. borderColor: "rgba(255,221,50,1)",
  442. data: [{
  443. x: 21269017,
  444. y: 5.245,
  445. r: 15
  446. }],
  447. }, {
  448. label: ["Denmark"],
  449. backgroundColor: "rgba(60,186,159,0.2)",
  450. borderColor: "rgba(60,186,159,1)",
  451. data: [{
  452. x: 258702,
  453. y: 7.526,
  454. r: 10
  455. }]
  456. }, {
  457. label: ["Germany"],
  458. backgroundColor: "rgba(0,0,0,0.2)",
  459. borderColor: $black,
  460. data: [{
  461. x: 3979083,
  462. y: 6.994,
  463. r: 15
  464. }]
  465. }, {
  466. label: ["Japan"],
  467. backgroundColor: "rgba(193,46,12,0.2)",
  468. borderColor: "rgba(193,46,12,1)",
  469. data: [{
  470. x: 4931877,
  471. y: 5.921,
  472. r: 15
  473. }]
  474. }]
  475. };
  476. var bubbleChartconfig = {
  477. type: 'bubble',
  478. // Chart Options
  479. options: bubblechartOptions,
  480. data: bubblechartData
  481. };
  482. // Create the chart
  483. var bubbleChart = new Chart(bubbleChartctx, bubbleChartconfig);
  484. // Scatter Chart
  485. // ------------------------------------
  486. //Get the context of the Chart canvas element we want to select
  487. var scatterChartctx = $("#scatter-chart");
  488. // Chart Options
  489. var scatterchartOptions = {
  490. responsive: true,
  491. maintainAspectRatio: false,
  492. responsiveAnimationDuration: 800,
  493. title: {
  494. display: false,
  495. text: 'Chart.js Scatter Chart'
  496. },
  497. scales: {
  498. xAxes: [{
  499. position: 'top',
  500. gridLines: {
  501. color: scatter_grid_color,
  502. drawTicks: false,
  503. },
  504. scaleLabel: {
  505. display: true,
  506. labelString: 'x axis'
  507. }
  508. }],
  509. yAxes: [{
  510. position: 'right',
  511. gridLines: {
  512. color: scatter_grid_color,
  513. drawTicks: false,
  514. },
  515. scaleLabel: {
  516. display: true,
  517. labelString: 'y axis'
  518. }
  519. }]
  520. }
  521. };
  522. // Chart Data
  523. var scatterchartData = {
  524. datasets: [{
  525. label: "My First dataset",
  526. data: [{
  527. x: 65,
  528. y: 28,
  529. }, {
  530. x: 59,
  531. y: 48,
  532. }, {
  533. x: 80,
  534. y: 40,
  535. }, {
  536. x: 81,
  537. y: 19,
  538. }, {
  539. x: 56,
  540. y: 86,
  541. }, {
  542. x: 55,
  543. y: 27,
  544. }, {
  545. x: 40,
  546. y: 89,
  547. }],
  548. backgroundColor: "rgba(209,212,219,.3)",
  549. borderColor: "transparent",
  550. pointBorderColor: $scatter_point_light,
  551. pointBackgroundColor: $white,
  552. pointBorderWidth: 2,
  553. pointHoverBorderWidth: 2,
  554. pointRadius: 4,
  555. }, {
  556. label: "My Second dataset",
  557. data: [{
  558. x: 45,
  559. y: 17,
  560. }, {
  561. x: 25,
  562. y: 62,
  563. }, {
  564. x: 16,
  565. y: 78,
  566. }, {
  567. x: 36,
  568. y: 88,
  569. }, {
  570. x: 67,
  571. y: 26,
  572. }, {
  573. x: 18,
  574. y: 48,
  575. }, {
  576. x: 76,
  577. y: 73,
  578. }],
  579. backgroundColor: "rgba(81,117,224,.6)",
  580. borderColor: "transparent",
  581. pointBorderColor: $scatter_point_dark,
  582. pointBackgroundColor: $white,
  583. pointBorderWidth: 2,
  584. pointHoverBorderWidth: 2,
  585. pointRadius: 4,
  586. }]
  587. };
  588. var scatterChartconfig = {
  589. type: 'scatter',
  590. // Chart Options
  591. options: scatterchartOptions,
  592. data: scatterchartData
  593. };
  594. // Create the chart
  595. var scatterChart = new Chart(scatterChartctx, scatterChartconfig);
  596. });