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.

208 lines
7.4 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.categoryField = "year";
  126. chart.addTitle("Traffic incidents per year", 15);
  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.title = "percent"; // this line makes the chart "stacked"
  136. valueAxis.stackType = "100%";
  137. valueAxis.gridAlpha = 0.07;
  138. chart.addValueAxis(valueAxis);
  139. // GRAPHS
  140. // first graph
  141. var graph = new AmCharts.AmGraph();
  142. graph.type = "line"; // it's simple line graph
  143. graph.title = "Cars";
  144. graph.valueField = "cars";
  145. graph.lineAlpha = 0;
  146. graph.fillAlphas = 0.6; // setting fillAlphas to > 0 value makes it area graph
  147. 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>";
  148. chart.addGraph(graph);
  149. // second graph
  150. graph = new AmCharts.AmGraph();
  151. graph.type = "line";
  152. graph.title = "Motorcycles";
  153. graph.valueField = "motorcycles";
  154. graph.lineAlpha = 0;
  155. graph.fillAlphas = 0.6;
  156. 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>";
  157. chart.addGraph(graph);
  158. // third graph
  159. graph = new AmCharts.AmGraph();
  160. graph.type = "line";
  161. graph.title = "Bicycles";
  162. graph.valueField = "bicycles";
  163. graph.lineAlpha = 0;
  164. graph.fillAlphas = 0.6;
  165. 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>";
  166. chart.addGraph(graph);
  167. // LEGEND
  168. var legend = new AmCharts.AmLegend();
  169. legend.align = "center";
  170. legend.valueText = "[[value]] ([[percents]]%)";
  171. legend.valueWidth = 100;
  172. legend.valueAlign = "left";
  173. legend.equalWidths = false;
  174. legend.periodValueText = "total: [[value.sum]]"; // this is displayed when mouse is not over the chart.
  175. chart.addLegend(legend);
  176. // CURSOR
  177. var chartCursor = new AmCharts.ChartCursor();
  178. chartCursor.zoomable = false; // as the chart displayes not too many values, we disabled zooming
  179. chartCursor.cursorAlpha = 0;
  180. chartCursor.valueZoomable = true;
  181. chartCursor.pan = true;
  182. chart.addChartCursor(chartCursor);
  183. // VALUE SCROLLBAR
  184. chart.valueScrollbar = new AmCharts.ChartScrollbar();
  185. // WRITE
  186. chart.write("chartdiv");
  187. });
  188. </script>
  189. </head>
  190. <body>
  191. <div id="chartdiv" style="width:100%; height:400px;"></div>
  192. </body>
  193. </html>