HTMLcopy
1
<div id="container"></div>
CSScopy
6
1
html, body, #container {
2
width: 100%;
3
height: 100%;
4
margin: 0;
5
padding: 0;
6
}
JavaScriptcopy
x
1
anychart.onDocumentReady(function () {
2
//create data set on our data
3
var dataSet = anychart.data.set([
4
['GDP', 1, 0.11982978723404256, 0.6180425531914894],
5
['GDP Real Growth Rate', 0.3666666666666667, 0.5583333333333333, 0.7583333333333333],
6
['Infant Mortality', 0.06578947368421052, 0.15576923076923077, 0.24473684210526317],
7
['Life Expectancy', 0.9576093653727663, 0.8268638324091188, 0.8905730129390017],
8
['Population', 0.22638827767366515, 0.10979008847837246, 1],
9
['Area', 0.5390698290165805, 1, 0.5487479259581779],
10
['Density', 0.02995156531259858, 0.00783120233080335, 0.1299664111937944],
11
['Population Growth Rate', 0.3087248322147651, -0.12416107382550336, 0.19463087248322147]
12
]);
13
14
//map data for the first series, take x from the zero column and value from the first column of data set
15
var data1 = dataSet.mapAs({x: [0], value: [1]});
16
//map data for the second series, take x from the zero column and value from the second column of data set
17
var data2 = dataSet.mapAs({x: [0], value: [2]});
18
//map data for the third series, take x from the zero column and value from the third column of data set
19
var data3 = dataSet.mapAs({x: [0], value: [3]});
20
21
//create radar chart
22
var chart = anychart.radar();
23
24
//set container id for the chart
25
chart.container('container');
26
27
//set chart title text settings
28
chart.title().text('Comparison Chart');
29
30
//set chart yScale settings
31
chart.yScale()
32
.minimum(-.2)
33
.maximum(1)
34
.ticks().interval(.2);
35
36
//set chart legend settings
37
chart.legend()
38
.enabled(true)
39
.margin().top(20);
40
41
//set chart grinds settings
42
chart.grid(0)
43
.oddFill('white')
44
.evenFill('white')
45
.stroke('rgb(221,221,221)');
46
chart.grid(1)
47
.oddFill(null)
48
.evenFill(null)
49
.stroke('rgb(192,192,192)');
50
51
52
//set chart margin settings
53
chart.margin().bottom(50);
54
55
//create chart label with description
56
var label = chart.label();
57
label.text("This chart compares countries by using specific indicators.\n" +
58
"For each indicator, the value 1 is assigned to the country that has the highest value.\n" +
59
"Other countries have their value computed as a proportion of the country with the highest value.");
60
label.anchor(acgraph.vector.Anchor.CENTER_BOTTOM);
61
label.position(acgraph.vector.Anchor.CENTER_BOTTOM);
62
label.fontWeight('normal');
63
label.fontSize(11);
64
label.fontFamily('tahoma');
65
label.fontColor('rgb(35,35,35)');
66
label.offsetY(15);
67
68
//create point data labels formation function
69
var labelFormattingFunction = function () {
70
return this.x + ': ' + this.value.toFixed(2)
71
};
72
73
//create first series with mapped data
74
chart.line(data1)
75
.name('USA')
76
.tooltip().contentFormatter(labelFormattingFunction);
77
//create second series with mapped data
78
chart.line(data2)
79
.name('Russia').tooltip()
80
.contentFormatter(labelFormattingFunction);
81
//create third series with mapped data
82
chart.line(data3)
83
.name('China')
84
.tooltip().contentFormatter(labelFormattingFunction);
85
86
//initiate chart drawing
87
chart.draw();
88
});