pieWithLegend.html
4.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>amCharts examples</title>
<link rel="stylesheet" href="style.css" type="text/css">
<script src="../amcharts/amcharts.js" type="text/javascript"></script>
<script src="../amcharts/pie.js" type="text/javascript"></script>
<script type="text/javascript">
var chart;
var legend;
var chartData = [
{
"country": "Czech Republic",
"litres": 156.9
},
{
"country": "Ireland",
"litres": 131.1
},
{
"country": "Germany",
"litres": 115.8
},
{
"country": "Australia",
"litres": 109.9
},
{
"country": "Austria",
"litres": 108.3
},
{
"country": "UK",
"litres": 65
},
{
"country": "Belgium",
"litres": 50
}
];
AmCharts.ready(function () {
// PIE CHART
chart = new AmCharts.AmPieChart();
chart.dataProvider = chartData;
chart.titleField = "country";
chart.valueField = "litres";
// LEGEND
legend = new AmCharts.AmLegend();
legend.align = "center";
legend.markerType = "circle";
chart.balloonText = "[[title]]<br><span style='font-size:14px'><b>[[value]]</b> ([[percents]]%)</span>";
chart.addLegend(legend);
// WRITE
chart.write("chartdiv");
});
// changes label position (labelRadius)
function setLabelPosition() {
if (document.getElementById("rb1").checked) {
chart.labelRadius = 30;
chart.labelText = "[[title]]: [[value]]";
} else {
chart.labelRadius = -30;
chart.labelText = "[[percents]]%";
}
chart.validateNow();
}
// makes chart 2D/3D
function set3D() {
if (document.getElementById("rb3").checked) {
chart.depth3D = 10;
chart.angle = 10;
} else {
chart.depth3D = 0;
chart.angle = 0;
}
chart.validateNow();
}
// changes switch of the legend (x or v)
function setSwitch() {
if (document.getElementById("rb5").checked) {
legend.switchType = "x";
} else {
legend.switchType = "v";
}
legend.validateNow();
}
</script>
</head>
<body>
<div id="chartdiv" style="width: 100%; height: 400px;"></div>
<table align="center" cellspacing="20">
<tr>
<td>
<input type="radio" checked="true" name="group" id="rb1" onclick="setLabelPosition()">labels outside
<input type="radio" name="group" id="rb2" onclick="setLabelPosition()">labels inside</td>
<td>
<input type="radio" name="group2" id="rb3" onclick="set3D()">3D
<input type="radio" checked="true" name="group2" id="rb4" onclick="set3D()">2D</td>
<td>Legend switch type:
<input type="radio" checked="true" name="group3" id="rb5"
onclick="setSwitch()">x
<input type="radio" name="group3" id="rb6" onclick="setSwitch()">v</td>
</tr>
</table>
</body>
</html>