HTMLcopy
1
<div id="container"></div>
CSScopy
8
1
html,
2
body,
3
#container {
4
width: 100%;
5
height: 100%;
6
margin: 0;
7
padding: 0;
8
}
JavaScriptcopy
x
1
anychart.onDocumentReady(function () {
2
// create data set on our data
3
var dataSet = anychart.data.set([
4
['2012', 51, 125, 12],
5
['\'13', 91, 102, 14],
6
['\'14', 34, 90, 13],
7
['\'15', 47, 80, 21],
8
['\'16', 63, 103, 19]
9
]);
10
11
// map data for the first series, take x from the zero area and value from the first area of data set
12
var firstSeriesData = dataSet.mapAs({ x: 0, value: 1 });
13
14
// map data for the second series, take x from the zero area and value from the second area of data set
15
var secondSeriesData = dataSet.mapAs({ x: 0, value: 2 });
16
17
// map data for the third series, take x from the zero area and value from the third area of data set
18
var thirdSeriesData = dataSet.mapAs({ x: 0, value: 3 });
19
20
// create area chart
21
var chart = anychart.area();
22
23
// turn on chart animation
24
chart.animation(true);
25
26
// turn on the crosshair
27
var crosshair = chart.crosshair();
28
crosshair.enabled(true).yStroke(null).xStroke('#fff').zIndex(39);
29
crosshair.yLabel().enabled(false);
30
31
chart.yAxis().title('Amount of comments collected');
32
33
// force chart to stack values by Y scale.
34
chart.yScale().stackMode('value');
35
36
// set chart title text settings
37
chart.title('Customer satisfaction according to collected comments');
38
39
// create first series with mapped data
40
var firstSeries = chart.stepArea(firstSeriesData);
41
firstSeries.name('Grateful');
42
firstSeries.markers().zIndex(100);
43
firstSeries
44
.hovered()
45
.markers()
46
.type('circle')
47
.size(4)
48
.stroke('1.5 #fff');
49
50
// create second series with mapped data
51
var secondSeries = chart.stepArea(secondSeriesData);
52
secondSeries.name('Neutral');
53
secondSeries.markers().zIndex(100);
54
secondSeries
55
.hovered()
56
.markers()
57
.type('circle')
58
.size(4)
59
.stroke('1.5 #fff');
60
61
// create third series with mapped data
62
var thirdSeries = chart.stepArea(thirdSeriesData);
63
thirdSeries.name('Disgruntled');
64
thirdSeries.markers().zIndex(100);
65
thirdSeries
66
.hovered()
67
.markers()
68
.type('circle')
69
.size(4)
70
.stroke('1.5 #fff');
71
72
// turn the legend on
73
chart.legend().enabled(true).fontSize(13).padding([0, 0, 20, 0]);
74
75
// set container id for the chart
76
chart.container('container');
77
// initiate chart drawing
78
chart.draw();
79
});