chartjs.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. $(function () {
  2. new Chart(document.getElementById("line_chart").getContext("2d"), getChartJs('line'));
  3. new Chart(document.getElementById("bar_chart").getContext("2d"), getChartJs('bar'));
  4. new Chart(document.getElementById("radar_chart").getContext("2d"), getChartJs('radar'));
  5. new Chart(document.getElementById("pie_chart").getContext("2d"), getChartJs('pie'));
  6. });
  7. function getChartJs(type) {
  8. var config = null;
  9. if (type === 'line') {
  10. config = {
  11. type: 'line',
  12. data: {
  13. labels: ["January", "February", "March", "April", "May", "June", "July"],
  14. datasets: [{
  15. label: "My First dataset",
  16. data: [65, 59, 80, 81, 56, 55, 40],
  17. borderColor: 'rgba(0, 188, 212, 0.75)',
  18. backgroundColor: 'rgba(0, 188, 212, 0.3)',
  19. pointBorderColor: 'rgba(0, 188, 212, 0)',
  20. pointBackgroundColor: 'rgba(0, 188, 212, 0.9)',
  21. pointBorderWidth: 1
  22. }, {
  23. label: "My Second dataset",
  24. data: [28, 48, 40, 19, 86, 27, 90],
  25. borderColor: 'rgba(233, 30, 99, 0.75)',
  26. backgroundColor: 'rgba(233, 30, 99, 0.3)',
  27. pointBorderColor: 'rgba(233, 30, 99, 0)',
  28. pointBackgroundColor: 'rgba(233, 30, 99, 0.9)',
  29. pointBorderWidth: 1
  30. }]
  31. },
  32. options: {
  33. responsive: true,
  34. legend: false
  35. }
  36. }
  37. }
  38. else if (type === 'bar') {
  39. config = {
  40. type: 'bar',
  41. data: {
  42. labels: ["January", "February", "March", "April", "May", "June", "July"],
  43. datasets: [{
  44. label: "My First dataset",
  45. data: [65, 59, 80, 81, 56, 55, 40],
  46. backgroundColor: 'rgba(0, 188, 212, 0.8)'
  47. }, {
  48. label: "My Second dataset",
  49. data: [28, 48, 40, 19, 86, 27, 90],
  50. backgroundColor: 'rgba(233, 30, 99, 0.8)'
  51. }]
  52. },
  53. options: {
  54. responsive: true,
  55. legend: false
  56. }
  57. }
  58. }
  59. else if (type === 'radar') {
  60. config = {
  61. type: 'radar',
  62. data: {
  63. labels: ["January", "February", "March", "April", "May", "June", "July"],
  64. datasets: [{
  65. label: "My First dataset",
  66. data: [65, 25, 90, 81, 56, 55, 40],
  67. borderColor: 'rgba(0, 188, 212, 0.8)',
  68. backgroundColor: 'rgba(0, 188, 212, 0.5)',
  69. pointBorderColor: 'rgba(0, 188, 212, 0)',
  70. pointBackgroundColor: 'rgba(0, 188, 212, 0.8)',
  71. pointBorderWidth: 1
  72. }, {
  73. label: "My Second dataset",
  74. data: [72, 48, 40, 19, 96, 27, 100],
  75. borderColor: 'rgba(233, 30, 99, 0.8)',
  76. backgroundColor: 'rgba(233, 30, 99, 0.5)',
  77. pointBorderColor: 'rgba(233, 30, 99, 0)',
  78. pointBackgroundColor: 'rgba(233, 30, 99, 0.8)',
  79. pointBorderWidth: 1
  80. }]
  81. },
  82. options: {
  83. responsive: true,
  84. legend: false
  85. }
  86. }
  87. }
  88. else if (type === 'pie') {
  89. config = {
  90. type: 'pie',
  91. data: {
  92. datasets: [{
  93. data: [225, 50, 100, 40],
  94. backgroundColor: [
  95. "rgb(233, 30, 99)",
  96. "rgb(255, 193, 7)",
  97. "rgb(0, 188, 212)",
  98. "rgb(139, 195, 74)"
  99. ],
  100. }],
  101. labels: [
  102. "Pink",
  103. "Amber",
  104. "Cyan",
  105. "Light Green"
  106. ]
  107. },
  108. options: {
  109. responsive: true,
  110. legend: false
  111. }
  112. }
  113. }
  114. return config;
  115. }