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.

170 lines
6.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 chart;
  11. var chartData = [
  12. {
  13. "year": "2003",
  14. "europe": 2.5,
  15. "namerica": 2.5,
  16. "asia": 2.1,
  17. "lamerica": 1.3,
  18. "meast": 1.2,
  19. "africa": 0.3
  20. },
  21. {
  22. "year": "2004",
  23. "europe": 2.6,
  24. "namerica": 2.7,
  25. "asia": 2.2,
  26. "lamerica": 1.3,
  27. "meast": 1.3,
  28. "africa": 0.4
  29. },
  30. {
  31. "year": "2005",
  32. "europe": 2.8,
  33. "namerica": 2.9,
  34. "asia": 2.4,
  35. "lamerica": 1.3,
  36. "meast": 1.3,
  37. "africa": 0.5
  38. }
  39. ];
  40. AmCharts.ready(function () {
  41. // SERIAL CHART
  42. chart = new AmCharts.AmSerialChart();
  43. chart.dataProvider = chartData;
  44. chart.categoryField = "year";
  45. chart.plotAreaBorderAlpha = 0.2;
  46. // AXES
  47. // category
  48. var categoryAxis = chart.categoryAxis;
  49. categoryAxis.gridAlpha = 0.1;
  50. categoryAxis.axisAlpha = 0;
  51. categoryAxis.gridPosition = "start";
  52. // value
  53. var valueAxis = new AmCharts.ValueAxis();
  54. valueAxis.stackType = "regular";
  55. valueAxis.gridAlpha = 0.1;
  56. valueAxis.axisAlpha = 0;
  57. chart.addValueAxis(valueAxis);
  58. // GRAPHS
  59. // first graph
  60. var graph = new AmCharts.AmGraph();
  61. graph.title = "Europe";
  62. graph.labelText = "[[value]]";
  63. graph.valueField = "europe";
  64. graph.type = "column";
  65. graph.lineAlpha = 0;
  66. graph.fillAlphas = 1;
  67. graph.lineColor = "#C72C95";
  68. graph.balloonText = "<span style='color:#555555;'>[[category]]</span><br><span style='font-size:14px'>[[title]]:<b>[[value]]</b></span>";
  69. chart.addGraph(graph);
  70. // second graph
  71. graph = new AmCharts.AmGraph();
  72. graph.title = "North America";
  73. graph.labelText = "[[value]]";
  74. graph.valueField = "namerica";
  75. graph.type = "column";
  76. graph.lineAlpha = 0;
  77. graph.fillAlphas = 1;
  78. graph.lineColor = "#D8E0BD";
  79. graph.balloonText = "<span style='color:#555555;'>[[category]]</span><br><span style='font-size:14px'>[[title]]:<b>[[value]]</b></span>";
  80. chart.addGraph(graph);
  81. // third graph
  82. graph = new AmCharts.AmGraph();
  83. graph.title = "Asia-Pacific";
  84. graph.labelText = "[[value]]";
  85. graph.valueField = "asia";
  86. graph.type = "column";
  87. graph.newStack = true; // this line starts new stack
  88. graph.lineAlpha = 0;
  89. graph.fillAlphas = 1;
  90. graph.lineColor = "#B3DBD4";
  91. graph.balloonText = "<span style='color:#555555;'>[[category]]</span><br><span style='font-size:14px'>[[title]]:<b>[[value]]</b></span>";
  92. chart.addGraph(graph);
  93. // fourth graph
  94. graph = new AmCharts.AmGraph();
  95. graph.title = "Latin America";
  96. graph.labelText = "[[value]]";
  97. graph.valueField = "lamerica";
  98. graph.type = "column";
  99. graph.lineAlpha = 0;
  100. graph.fillAlphas = 1;
  101. graph.lineColor = "#69A55C";
  102. graph.balloonText = "<span style='color:#555555;'>[[category]]</span><br><span style='font-size:14px'>[[title]]:<b>[[value]]</b></span>";
  103. chart.addGraph(graph);
  104. // fifth graph
  105. graph = new AmCharts.AmGraph();
  106. graph.title = "Middle-East";
  107. graph.labelText = "[[value]]";
  108. graph.valueField = "meast";
  109. graph.type = "column";
  110. graph.lineAlpha = 0;
  111. graph.fillAlphas = 1;
  112. graph.lineColor = "#B5B8D3";
  113. graph.balloonText = "<span style='color:#555555;'>[[category]]</span><br><span style='font-size:14px'>[[title]]:<b>[[value]]</b></span>";
  114. chart.addGraph(graph);
  115. // sixth graph
  116. graph = new AmCharts.AmGraph();
  117. graph.title = "Africa";
  118. graph.labelText = "[[value]]";
  119. graph.valueField = "africa";
  120. graph.type = "column";
  121. graph.lineAlpha = 0;
  122. graph.fillAlphas = 1;
  123. graph.lineColor = "#F4E23B";
  124. graph.balloonText = "<span style='color:#555555;'>[[category]]</span><br><span class='font-size:14px'>[[title]]:<b>[[value]]</b></span>";
  125. chart.addGraph(graph);
  126. // LEGEND
  127. var legend = new AmCharts.AmLegend();
  128. legend.borderAlpha = 0.2;
  129. legend.horizontalGap = 10;
  130. chart.addLegend(legend);
  131. // WRITE
  132. chart.write("chartdiv");
  133. });
  134. // this method sets chart 2D/3D
  135. function setDepth() {
  136. if (document.getElementById("rb1").checked) {
  137. chart.depth3D = 0;
  138. chart.angle = 0;
  139. } else {
  140. chart.depth3D = 25;
  141. chart.angle = 30;
  142. }
  143. chart.validateNow();
  144. }
  145. </script>
  146. </head>
  147. <body>
  148. <div id="chartdiv" style="width: 600px; height: 400px;"></div>
  149. <div style="margin-left:30px;">
  150. <input type="radio" checked="true" name="group" id="rb1" onclick="setDepth()">2D
  151. <input type="radio" name="group" id="rb2" onclick="setDepth()">3D
  152. </div>
  153. </body>
  154. </html>