You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

231 lines
8.2 KiB

1 year ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5. <title>amCharts examples</title>
  6. <link rel="stylesheet" href="style.css" type="text/css">
  7. <script src="../amcharts/amcharts.js" type="text/javascript"></script>
  8. <script src="../amcharts/serial.js" type="text/javascript"></script>
  9. <script>
  10. var chart;
  11. var chartData = [
  12. {
  13. "year": 1995,
  14. "cars": 1567,
  15. "motorcycles": 683,
  16. "bicycles": 146
  17. },
  18. {
  19. "year": 1996,
  20. "cars": 1617,
  21. "motorcycles": 691,
  22. "bicycles": 138
  23. },
  24. {
  25. "year": 1997,
  26. "cars": 1630,
  27. "motorcycles": 642,
  28. "bicycles": 127
  29. },
  30. {
  31. "year": 1998,
  32. "cars": 1660,
  33. "motorcycles": 699,
  34. "bicycles": 105
  35. },
  36. {
  37. "year": 1999,
  38. "cars": 1683,
  39. "motorcycles": 721,
  40. "bicycles": 109
  41. },
  42. {
  43. "year": 2000,
  44. "cars": 1691,
  45. "motorcycles": 737,
  46. "bicycles": 112
  47. },
  48. {
  49. "year": 2001,
  50. "cars": 1298,
  51. "motorcycles": 680,
  52. "bicycles": 101
  53. },
  54. {
  55. "year": 2002,
  56. "cars": 1275,
  57. "motorcycles": 664,
  58. "bicycles": 97
  59. },
  60. {
  61. "year": 2003,
  62. "cars": 1246,
  63. "motorcycles": 648,
  64. "bicycles": 93
  65. },
  66. {
  67. "year": 2004,
  68. "cars": 1218,
  69. "motorcycles": 637,
  70. "bicycles": 101
  71. },
  72. {
  73. "year": 2005,
  74. "cars": 1213,
  75. "motorcycles": 633,
  76. "bicycles": 87
  77. },
  78. {
  79. "year": 2006,
  80. "cars": 1199,
  81. "motorcycles": 621,
  82. "bicycles": 79
  83. },
  84. {
  85. "year": 2007,
  86. "cars": 1110,
  87. "motorcycles": 210,
  88. "bicycles": 81
  89. },
  90. {
  91. "year": 2008,
  92. "cars": 1165,
  93. "motorcycles": 232,
  94. "bicycles": 75
  95. },
  96. {
  97. "year": 2009,
  98. "cars": 1145,
  99. "motorcycles": 219,
  100. "bicycles": 88
  101. },
  102. {
  103. "year": 2010,
  104. "cars": 1163,
  105. "motorcycles": 201,
  106. "bicycles": 82
  107. },
  108. {
  109. "year": 2011,
  110. "cars": 1180,
  111. "motorcycles": 285,
  112. "bicycles": 87
  113. },
  114. {
  115. "year": 2012,
  116. "cars": 1159,
  117. "motorcycles": 277,
  118. "bicycles": 71
  119. }
  120. ];
  121. AmCharts.ready(function () {
  122. // SERIAL CHART
  123. chart = new AmCharts.AmSerialChart();
  124. chart.dataProvider = chartData;
  125. chart.marginTop = 10;
  126. chart.categoryField = "year";
  127. // AXES
  128. // Category
  129. var categoryAxis = chart.categoryAxis;
  130. categoryAxis.gridAlpha = 0.07;
  131. categoryAxis.axisColor = "#DADADA";
  132. categoryAxis.startOnAxis = true;
  133. // Value
  134. var valueAxis = new AmCharts.ValueAxis();
  135. valueAxis.stackType = "regular"; // this line makes the chart "stacked"
  136. valueAxis.gridAlpha = 0.07;
  137. valueAxis.title = "Traffic incidents";
  138. chart.addValueAxis(valueAxis);
  139. // GUIDES are vertical (can also be horizontal) lines (or areas) marking some event.
  140. // first guide
  141. var guide1 = new AmCharts.Guide();
  142. guide1.category = "2001";
  143. guide1.lineColor = "#CC0000";
  144. guide1.lineAlpha = 1;
  145. guide1.dashLength = 2;
  146. guide1.inside = true;
  147. guide1.labelRotation = 90;
  148. guide1.label = "fines for speeding increased";
  149. categoryAxis.addGuide(guide1);
  150. // second guide
  151. var guide2 = new AmCharts.Guide();
  152. guide2.category = "2007";
  153. guide2.lineColor = "#CC0000";
  154. guide2.lineAlpha = 1;
  155. guide2.dashLength = 2;
  156. guide2.inside = true;
  157. guide2.labelRotation = 90;
  158. guide2.label = "motorcycle maintenance fee introduced";
  159. categoryAxis.addGuide(guide2);
  160. // GRAPHS
  161. // first graph
  162. var graph = new AmCharts.AmGraph();
  163. graph.type = "line"; // it's simple line graph
  164. graph.title = "Cars";
  165. graph.valueField = "cars";
  166. graph.lineAlpha = 0;
  167. graph.fillAlphas = 0.6; // setting fillAlphas to > 0 value makes it area graph
  168. graph.balloonText = "<img src='images/car.png' style='vertical-align:bottom; margin-right: 10px; width:28px; height:21px;'><span style='font-size:14px; color:#000000;'><b>[[value]]</b></span>";
  169. graph.hidden = true;
  170. chart.addGraph(graph);
  171. // second graph
  172. graph = new AmCharts.AmGraph();
  173. graph.type = "line";
  174. graph.title = "Motorcycles";
  175. graph.valueField = "motorcycles";
  176. graph.lineAlpha = 0;
  177. graph.fillAlphas = 0.6;
  178. graph.balloonText = "<img src='images/motorcycle.png' style='vertical-align:bottom; margin-right: 10px; width:28px; height:21px;'><span style='font-size:14px; color:#000000;'><b>[[value]]</b></span>";
  179. chart.addGraph(graph);
  180. // third graph
  181. graph = new AmCharts.AmGraph();
  182. graph.type = "line";
  183. graph.title = "Bicycles";
  184. graph.valueField = "bicycles";
  185. graph.lineAlpha = 0;
  186. graph.fillAlphas = 0.6;
  187. graph.balloonText = "<img src='images/bicycle.png' style='vertical-align:bottom; margin-right: 10px; width:28px; height:21px;'><span style='font-size:14px; color:#000000;'><b>[[value]]</b></span>";
  188. chart.addGraph(graph);
  189. // LEGEND
  190. var legend = new AmCharts.AmLegend();
  191. legend.position = "top";
  192. legend.valueText = "[[value]]";
  193. legend.valueWidth = 100;
  194. legend.valueAlign = "left";
  195. legend.equalWidths = false;
  196. legend.periodValueText = "total: [[value.sum]]"; // this is displayed when mouse is not over the chart.
  197. chart.addLegend(legend);
  198. // CURSOR
  199. var chartCursor = new AmCharts.ChartCursor();
  200. chartCursor.cursorAlpha = 0;
  201. chart.addChartCursor(chartCursor);
  202. // SCROLLBAR
  203. var chartScrollbar = new AmCharts.ChartScrollbar();
  204. chartScrollbar.color = "#FFFFFF";
  205. chart.addChartScrollbar(chartScrollbar);
  206. // WRITE
  207. chart.write("chartdiv");
  208. });
  209. </script>
  210. </head>
  211. <body>
  212. <div id="chartdiv" style="width:100%; height:400px;"></div>
  213. </body>
  214. </html>