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.

120 lines
4.2 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/pie.js" type="text/javascript"></script>
  9. <script>
  10. var chart;
  11. var legend;
  12. var chartData = [
  13. {
  14. "country": "Czech Republic",
  15. "litres": 156.9
  16. },
  17. {
  18. "country": "Ireland",
  19. "litres": 131.1
  20. },
  21. {
  22. "country": "Germany",
  23. "litres": 115.8
  24. },
  25. {
  26. "country": "Australia",
  27. "litres": 109.9
  28. },
  29. {
  30. "country": "Austria",
  31. "litres": 108.3
  32. },
  33. {
  34. "country": "UK",
  35. "litres": 65
  36. },
  37. {
  38. "country": "Belgium",
  39. "litres": 50
  40. }
  41. ];
  42. AmCharts.ready(function () {
  43. // PIE CHART
  44. chart = new AmCharts.AmPieChart();
  45. chart.dataProvider = chartData;
  46. chart.titleField = "country";
  47. chart.valueField = "litres";
  48. chart.gradientRatio = [0, 0, 0 ,-0.2, -0.4];
  49. chart.gradientType = "radial";
  50. // LEGEND
  51. legend = new AmCharts.AmLegend();
  52. legend.align = "center";
  53. legend.markerType = "circle";
  54. chart.balloonText = "[[title]]<br><span style='font-size:14px'><b>[[value]]</b> ([[percents]]%)</span>";
  55. chart.addLegend(legend);
  56. // WRITE
  57. chart.write("chartdiv");
  58. });
  59. // changes label position (labelRadius)
  60. function setLabelPosition() {
  61. if (document.getElementById("rb1").checked) {
  62. chart.labelRadius = 30;
  63. chart.labelText = "[[title]]: [[value]]";
  64. } else {
  65. chart.labelRadius = -30;
  66. chart.labelText = "[[percents]]%";
  67. }
  68. chart.validateNow();
  69. }
  70. // makes chart 2D/3D
  71. function set3D() {
  72. if (document.getElementById("rb3").checked) {
  73. chart.depth3D = 10;
  74. chart.angle = 10;
  75. } else {
  76. chart.depth3D = 0;
  77. chart.angle = 0;
  78. }
  79. chart.validateNow();
  80. }
  81. // changes switch of the legend (x or v)
  82. function setSwitch() {
  83. if (document.getElementById("rb5").checked) {
  84. legend.switchType = "x";
  85. } else {
  86. legend.switchType = "v";
  87. }
  88. legend.validateNow();
  89. }
  90. </script>
  91. </head>
  92. <body>
  93. <div id="chartdiv" style="width: 100%; height: 400px;"></div>
  94. <table align="center" cellspacing="20">
  95. <tr>
  96. <td>
  97. <input type="radio" checked="true" name="group" id="rb1" onclick="setLabelPosition()">labels outside
  98. <input type="radio" name="group" id="rb2" onclick="setLabelPosition()">labels inside</td>
  99. <td>
  100. <input type="radio" name="group2" id="rb3" onclick="set3D()">3D
  101. <input type="radio" checked="true" name="group2" id="rb4" onclick="set3D()">2D</td>
  102. <td>Legend switch type:
  103. <input type="radio" checked="true" name="group3" id="rb5"
  104. onclick="setSwitch()">x
  105. <input type="radio" name="group3" id="rb6" onclick="setSwitch()">v</td>
  106. </tr>
  107. </table>
  108. </body>
  109. </html>