chart-demo.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. $(function(){
  2. /* Bar */
  3. var randomScalingFactor = function(){ return Math.round(Math.random()*100)};
  4. var barChartData = {
  5. labels : ["January","February","March","April","May","June","July"],
  6. datasets : [
  7. {
  8. fillColor : "rgba(220,220,220,0.5)",
  9. strokeColor : "rgba(220,220,220,0.8)",
  10. highlightFill: "rgba(220,220,220,0.75)",
  11. highlightStroke: "rgba(220,220,220,1)",
  12. data : [randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor()]
  13. },
  14. {
  15. fillColor : "rgba(151,187,205,0.5)",
  16. strokeColor : "rgba(151,187,205,0.8)",
  17. highlightFill : "rgba(151,187,205,0.75)",
  18. highlightStroke : "rgba(151,187,205,1)",
  19. data : [randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor()]
  20. }
  21. ]
  22. }
  23. var ctx = document.getElementById("canvas-1").getContext("2d");
  24. window.myBar = new Chart(ctx).Bar(barChartData, {
  25. responsive : true
  26. });
  27. /* Doughnut */
  28. var doughnutData = [
  29. {
  30. value: 300,
  31. color:"#F7464A",
  32. highlight: "#FF5A5E",
  33. label: "Red"
  34. },
  35. {
  36. value: 50,
  37. color: "#46BFBD",
  38. highlight: "#5AD3D1",
  39. label: "Green"
  40. },
  41. {
  42. value: 100,
  43. color: "#FDB45C",
  44. highlight: "#FFC870",
  45. label: "Yellow"
  46. },
  47. {
  48. value: 40,
  49. color: "#949FB1",
  50. highlight: "#A8B3C5",
  51. label: "Grey"
  52. },
  53. {
  54. value: 120,
  55. color: "#4D5360",
  56. highlight: "#616774",
  57. label: "Dark Grey"
  58. }
  59. ];
  60. var ctx = document.getElementById("chart-area").getContext("2d");
  61. window.myDoughnut = new Chart(ctx).Doughnut(doughnutData, {responsive : true});
  62. /* Line */
  63. var randomScalingFactor = function(){ return Math.round(Math.random()*100)};
  64. var lineChartData = {
  65. labels : ["January","February","March","April","May","June","July"],
  66. datasets : [
  67. {
  68. label: "My First dataset",
  69. fillColor : "rgba(220,220,220,0.2)",
  70. strokeColor : "rgba(220,220,220,1)",
  71. pointColor : "rgba(220,220,220,1)",
  72. pointStrokeColor : "#fff",
  73. pointHighlightFill : "#fff",
  74. pointHighlightStroke : "rgba(220,220,220,1)",
  75. data : [randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor()]
  76. },
  77. {
  78. label: "My Second dataset",
  79. fillColor : "rgba(151,187,205,0.2)",
  80. strokeColor : "rgba(151,187,205,1)",
  81. pointColor : "rgba(151,187,205,1)",
  82. pointStrokeColor : "#fff",
  83. pointHighlightFill : "#fff",
  84. pointHighlightStroke : "rgba(151,187,205,1)",
  85. data : [randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor()]
  86. }
  87. ]
  88. }
  89. var ctx = document.getElementById("canvas-2").getContext("2d");
  90. window.myLine = new Chart(ctx).Line(lineChartData, {
  91. responsive: true
  92. });
  93. /* Pie chart */
  94. var pieData = [
  95. {
  96. value: 300,
  97. color:"#F7464A",
  98. highlight: "#FF5A5E",
  99. label: "Red"
  100. },
  101. {
  102. value: 50,
  103. color: "#46BFBD",
  104. highlight: "#5AD3D1",
  105. label: "Green"
  106. },
  107. {
  108. value: 100,
  109. color: "#FDB45C",
  110. highlight: "#FFC870",
  111. label: "Yellow"
  112. },
  113. {
  114. value: 40,
  115. color: "#949FB1",
  116. highlight: "#A8B3C5",
  117. label: "Grey"
  118. },
  119. {
  120. value: 120,
  121. color: "#4D5360",
  122. highlight: "#616774",
  123. label: "Dark Grey"
  124. }
  125. ];
  126. var ctx = document.getElementById("chart-area-2").getContext("2d");
  127. window.myPie = new Chart(ctx).Pie(pieData, {
  128. responsive: true
  129. });
  130. /* Polar */
  131. var polarData = [
  132. {
  133. value: 300,
  134. color:"#F7464A",
  135. highlight: "#FF5A5E",
  136. label: "Red"
  137. },
  138. {
  139. value: 50,
  140. color: "#46BFBD",
  141. highlight: "#5AD3D1",
  142. label: "Green"
  143. },
  144. {
  145. value: 100,
  146. color: "#FDB45C",
  147. highlight: "#FFC870",
  148. label: "Yellow"
  149. },
  150. {
  151. value: 40,
  152. color: "#949FB1",
  153. highlight: "#A8B3C5",
  154. label: "Grey"
  155. },
  156. {
  157. value: 120,
  158. color: "#4D5360",
  159. highlight: "#616774",
  160. label: "Dark Grey"
  161. }
  162. ];
  163. var ctx = document.getElementById("chart-area-3").getContext("2d");
  164. window.myPolarArea = new Chart(ctx).PolarArea(polarData, {
  165. responsive:true
  166. });
  167. /* Radar chart */
  168. var radarChartData = {
  169. labels: ["Eating", "Drinking", "Sleeping", "Designing", "Coding", "Cycling", "Running"],
  170. datasets: [
  171. {
  172. label: "My First dataset",
  173. fillColor: "rgba(220,220,220,0.2)",
  174. strokeColor: "rgba(220,220,220,1)",
  175. pointColor: "rgba(220,220,220,1)",
  176. pointStrokeColor: "#fff",
  177. pointHighlightFill: "#fff",
  178. pointHighlightStroke: "rgba(220,220,220,1)",
  179. data: [65,59,90,81,56,55,40]
  180. },
  181. {
  182. label: "My Second dataset",
  183. fillColor: "rgba(151,187,205,0.2)",
  184. strokeColor: "rgba(151,187,205,1)",
  185. pointColor: "rgba(151,187,205,1)",
  186. pointStrokeColor: "#fff",
  187. pointHighlightFill: "#fff",
  188. pointHighlightStroke: "rgba(151,187,205,1)",
  189. data: [28,48,40,19,96,27,100]
  190. }
  191. ]
  192. };
  193. window.myRadar = new Chart(document.getElementById("canvas-4").getContext("2d")).Radar(radarChartData, {
  194. responsive: true
  195. });
  196. });