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.

194 lines
6.0 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. // since v3, chart can accept data in JSON format
  11. // if your category axis parses dates, you should only
  12. // set date format of your data (dataDateFormat property of AmSerialChart)
  13. var chartData = [
  14. {
  15. "date": "2009-10-02",
  16. "value": 5
  17. },
  18. {
  19. "date": "2009-10-03",
  20. "value": 15
  21. },
  22. {
  23. "date": "2009-10-04",
  24. "value": 13
  25. },
  26. {
  27. "date": "2009-10-05",
  28. "value": 17
  29. },
  30. {
  31. "date": "2009-10-06",
  32. "value": 15
  33. },
  34. {
  35. "date": "2009-10-09",
  36. "value": 19
  37. },
  38. {
  39. "date": "2009-10-10",
  40. "value": 21
  41. },
  42. {
  43. "date": "2009-10-11",
  44. "value": 20
  45. },
  46. {
  47. "date": "2009-10-12",
  48. "value": 20
  49. },
  50. {
  51. "date": "2009-10-13",
  52. "value": 19
  53. },
  54. {
  55. "date": "2009-10-16",
  56. "value": 25
  57. },
  58. {
  59. "date": "2009-10-17",
  60. "value": 24
  61. },
  62. {
  63. "date": "2009-10-18",
  64. "value": 26
  65. },
  66. {
  67. "date": "2009-10-19",
  68. "value": 27
  69. },
  70. {
  71. "date": "2009-10-20",
  72. "value": 25
  73. },
  74. {
  75. "date": "2009-10-23",
  76. "value": 29
  77. },
  78. {
  79. "date": "2009-10-24",
  80. "value": 28
  81. },
  82. {
  83. "date": "2009-10-25",
  84. "value": 30
  85. },
  86. {
  87. "date": "2009-10-26",
  88. "value": 72
  89. },
  90. {
  91. "date": "2009-10-27",
  92. "value": 43
  93. },
  94. {
  95. "date": "2009-10-30",
  96. "value": 31
  97. },
  98. {
  99. "date": "2009-11-01",
  100. "value": 30
  101. },
  102. {
  103. "date": "2009-11-02",
  104. "value": 29
  105. },
  106. {
  107. "date": "2009-11-03",
  108. "value": 27
  109. },
  110. {
  111. "date": "2009-11-04",
  112. "value": 26
  113. }
  114. ];
  115. createFromToFields();
  116. // create from/to field values programatically
  117. function createFromToFields(){
  118. for(var i = 0; i < chartData.length; i++){
  119. var value = chartData[i].value;
  120. chartData[i].fromValue = value - value * 0.2;
  121. chartData[i].toValue = value + value * 0.2;
  122. }
  123. }
  124. AmCharts.ready(function () {
  125. var chart = new AmCharts.AmSerialChart();
  126. chart.dataProvider = chartData;
  127. chart.categoryField = "date";
  128. chart.dataDateFormat = "YYYY-MM-DD";
  129. // AXES
  130. // category
  131. var categoryAxis = chart.categoryAxis;
  132. categoryAxis.parseDates = true; // as our data is date-based, we set parseDates to true
  133. categoryAxis.minPeriod = "DD"; // our data is daily, so we set minPeriod to DD
  134. categoryAxis.gridAlpha = 0;
  135. categoryAxis.tickLength = 0;
  136. categoryAxis.axisAlpha = 0;
  137. // value
  138. var valueAxis = new AmCharts.ValueAxis();
  139. valueAxis.dashLength = 4;
  140. valueAxis.axisAlpha = 0;
  141. chart.addValueAxis(valueAxis);
  142. // FROM GRAPH
  143. var fromGraph = new AmCharts.AmGraph();
  144. fromGraph.type = "line";
  145. fromGraph.valueField = "fromValue";
  146. fromGraph.lineAlpha = 0;
  147. fromGraph.showBalloon = false;
  148. chart.addGraph(fromGraph);
  149. // TO GRAPH
  150. var toGraph = new AmCharts.AmGraph();
  151. toGraph.type = "line";
  152. toGraph.valueField = "toValue";
  153. toGraph.lineAlpha = 0;
  154. toGraph.fillAlphas = 0.2;
  155. toGraph.fillToGraph = fromGraph;
  156. toGraph.showBalloon = false;
  157. chart.addGraph(toGraph);
  158. // GRAPH
  159. var graph = new AmCharts.AmGraph();
  160. graph.type = "line";
  161. graph.valueField = "value";
  162. graph.lineColor = "#000000";
  163. chart.addGraph(graph);
  164. // CURSOR
  165. var chartCursor = new AmCharts.ChartCursor();
  166. chart.addChartCursor(chartCursor);
  167. chart.creditsPosition = "top-right";
  168. // WRITE
  169. chart.write("chartdiv");
  170. });
  171. </script>
  172. </head>
  173. <body>
  174. <div id="chartdiv" style="width:100%; height:400px;"></div>
  175. </body>
  176. </html>