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
3
// create a data set
4
var data = anychart.data.set([
5
["QTR1", 3.8, 5.5, 6.9, 7.9],
6
["QTR2", 5.5, 7.0, 9.6, 8.6],
7
["QTR3", 9.9, 9.7, 8.3, 7.3],
8
["QTR4", 5.7, 7.6, 9.7, 18.7]
9
]);
10
11
// map the data
12
var seriesData_1 = data.mapAs({x: 0, value: 1});
13
var seriesData_2 = data.mapAs({x: 0, value: 2});
14
var seriesData_3 = data.mapAs({x: 0, value: 3});
15
var seriesData_4 = data.mapAs({x: 0, value: 4});
16
17
// create a chart
18
var chart = anychart.column();
19
20
// create scales and set stacking modes
21
yScale1 = anychart.scales.linear();
22
yScale1.stackMode("value");
23
24
yScale2 = anychart.scales.linear();
25
yScale2.stackMode("value");
26
27
// create column series and bind them to different scales
28
chart.column(seriesData_1).yScale(yScale1);
29
chart.column(seriesData_2).yScale(yScale1);
30
31
chart.column(seriesData_3).yScale(yScale2);
32
chart.column(seriesData_4).yScale(yScale2);
33
34
/* bind the Y-axis to the first scale
35
you can avoid this setting by reusing the primary Y-scale
36
when you create yScale1:
37
var yScale1 = chart.yScale();*/
38
chart.yAxis().scale(yScale1);
39
40
// set the chart title
41
chart.title("Value Stacked Chart: Clustered");
42
43
// set the container id
44
chart.container("container");
45
46
// initiate drawing the chart
47
chart.draw();
48
49
// sync minimums and maximums of the scales
50
globalMax = chart.getStat("yScalesMax");
51
globalMin = chart.getStat("yScalesMin");
52
// get all y scales
53
var yScales = chart.getYScales();
54
// set the same minimum and maximum
55
for (var i = 0; i < yScales.length; i++) {
56
yScales[i].minimum(globalMin);
57
yScales[i].maximum(globalMax);
58
}
59
60
});