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.

198 lines
7.5 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 chartData = [
  11. {
  12. "date": "2012-01-01",
  13. "distance": 227,
  14. "duration": 408
  15. },
  16. {
  17. "date": "2012-01-02",
  18. "distance": 371,
  19. "duration": 482
  20. },
  21. {
  22. "date": "2012-01-03",
  23. "distance": 433,
  24. "duration": 562
  25. },
  26. {
  27. "date": "2012-01-04",
  28. "distance": 345,
  29. "duration": 379
  30. },
  31. {
  32. "date": "2012-01-05",
  33. "distance": 480,
  34. "duration": 501
  35. },
  36. {
  37. "date": "2012-01-06",
  38. "distance": 386,
  39. "duration": 443
  40. },
  41. {
  42. "date": "2012-01-07",
  43. "distance": 348,
  44. "duration": 405
  45. },
  46. {
  47. "date": "2012-01-08",
  48. "distance": 238,
  49. "duration": 309
  50. },
  51. {
  52. "date": "2012-01-09",
  53. "distance": 218,
  54. "duration": 287
  55. },
  56. {
  57. "date": "2012-01-10",
  58. "distance": 349,
  59. "duration": 485
  60. },
  61. {
  62. "date": "2012-01-11",
  63. "distance": 603,
  64. "duration": 890
  65. },
  66. {
  67. "date": "2012-01-12",
  68. "distance": 534,
  69. "duration": 810
  70. }
  71. ];
  72. var chart;
  73. AmCharts.ready(function () {
  74. // SERIAL CHART
  75. chart = new AmCharts.AmSerialChart();
  76. chart.dataProvider = chartData;
  77. chart.categoryField = "date";
  78. chart.dataDateFormat = "YYYY-MM-DD";
  79. chart.marginTop = 0;
  80. // AXES
  81. // category axis
  82. var categoryAxis = chart.categoryAxis;
  83. categoryAxis.parseDates = true; // as our data is date-based, we set parseDates to true
  84. categoryAxis.minPeriod = "DD"; // our data is daily, so we set minPeriod to DD
  85. categoryAxis.autoGridCount = false;
  86. categoryAxis.gridCount = 50;
  87. categoryAxis.gridAlpha = 0;
  88. categoryAxis.gridColor = "#000000";
  89. categoryAxis.axisColor = "#555555";
  90. // we want custom date formatting, so we change it in next line
  91. categoryAxis.dateFormats = [{
  92. period: 'DD',
  93. format: 'DD'
  94. }, {
  95. period: 'WW',
  96. format: 'MMM DD'
  97. }, {
  98. period: 'MM',
  99. format: 'MMM'
  100. }, {
  101. period: 'YYYY',
  102. format: 'YYYY'
  103. }];
  104. // as we have data of different units, we create two different value axes
  105. // Duration value axis
  106. var durationAxis = new AmCharts.ValueAxis();
  107. durationAxis.title = "duration";
  108. durationAxis.gridAlpha = 0.05;
  109. durationAxis.axisAlpha = 0;
  110. durationAxis.tickLength = 0;
  111. durationAxis.inside = true;
  112. // the following line makes this value axis to convert values to duration
  113. // it tells the axis what duration unit it should use. mm - minute, hh - hour...
  114. durationAxis.duration = "mm";
  115. durationAxis.durationUnits = {
  116. DD: "d. ",
  117. hh: "h ",
  118. mm: "min",
  119. ss: ""
  120. };
  121. chart.addValueAxis(durationAxis);
  122. // Distance value axis
  123. var distanceAxis = new AmCharts.ValueAxis();
  124. distanceAxis.title = "distance";
  125. distanceAxis.gridAlpha = 0;
  126. distanceAxis.position = "right";
  127. distanceAxis.inside = true;
  128. distanceAxis.unit = "mi";
  129. distanceAxis.axisAlpha = 0;
  130. distanceAxis.tickLength = 0;
  131. chart.addValueAxis(distanceAxis);
  132. // GRAPHS
  133. // duration graph
  134. var durationGraph = new AmCharts.AmGraph();
  135. durationGraph.title = "duration";
  136. durationGraph.valueField = "duration";
  137. durationGraph.type = "line";
  138. durationGraph.valueAxis = durationAxis; // indicate which axis should be used
  139. durationGraph.lineColor = "#CC0000";
  140. durationGraph.balloonText = "[[value]]";
  141. durationGraph.lineThickness = 1;
  142. durationGraph.legendValueText = "[[value]]";
  143. durationGraph.bullet = "square";
  144. durationGraph.bulletBorderColor = "#CC0000";
  145. durationGraph.bulletBorderAlpha = 1;
  146. durationGraph.bulletBorderThickness = 1;
  147. chart.addGraph(durationGraph);
  148. // distance graph
  149. var distanceGraph = new AmCharts.AmGraph();
  150. distanceGraph.valueField = "distance";
  151. distanceGraph.title = "distance";
  152. distanceGraph.type = "column";
  153. distanceGraph.fillAlphas = 0.1;
  154. distanceGraph.valueAxis = distanceAxis; // indicate which axis should be used
  155. distanceGraph.balloonText = "[[value]] miles";
  156. distanceGraph.legendValueText = "[[value]] mi";
  157. distanceGraph.legendPeriodValueText = "total: [[value.sum]] mi";
  158. distanceGraph.lineColor = "#000000";
  159. distanceGraph.lineAlpha = 0;
  160. chart.addGraph(distanceGraph);
  161. // CURSOR
  162. var chartCursor = new AmCharts.ChartCursor();
  163. chartCursor.zoomable = false;
  164. chartCursor.categoryBalloonDateFormat = "DD";
  165. chartCursor.cursorAlpha = 0;
  166. chartCursor.valueLineEnabled = true;
  167. chartCursor.valueLineBalloonEnabled = true;
  168. chartCursor.valueLineAxis = distanceAxis;
  169. chart.addChartCursor(chartCursor);
  170. // LEGEND
  171. var legend = new AmCharts.AmLegend();
  172. legend.bulletType = "round";
  173. legend.equalWidths = false;
  174. legend.valueWidth = 120;
  175. legend.color = "#000000";
  176. legend.useGraphSettings = true;
  177. chart.addLegend(legend);
  178. // WRITE
  179. chart.write("chartdiv");
  180. });
  181. </script>
  182. </head>
  183. <body>
  184. <div id="chartdiv" style="width:100%; height:400px;"></div>
  185. </body>
  186. </html>