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.

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