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
['P1', 96.5, 2040, 1200, 1600],
5
['P2', 77.1, 1794, 1124, 1724],
6
['P3', 73.2, 2026, 1006, 1806],
7
['P4', 61.1, 2341, 921, 1621],
8
['P5', 70.0, 1800, 1500, 1700],
9
['P6', 60.7, 1507, 1007, 1907],
10
['P7', 62.1, 2701, 921, 1821],
11
['P8', 75.1, 1671, 971, 1671],
12
['P9', 80.0, 1980, 1080, 1880],
13
['P10', 54.1, 1041, 1041, 1641],
14
['P11', 51.3, 813, 1113, 1913],
15
['P12', 59.1, 691, 1091, 1691]
16
]);
17
18
// map data for the first series, take x from the zero column and value from the first column of data set
19
var firstSeriesData = dataSet.mapAs({ x: 0, value: 1 });
20
21
// map data for the second series, take x from the zero column and value from the second column of data set
22
var secondSeriesData = dataSet.mapAs({ x: 0, value: 2 });
23
24
// map data for the third series, take x from the zero column and value from the third column of data set
25
var thirdSeriesData = dataSet.mapAs({ x: 0, value: 3 });
26
27
// map data for the fourth series, take x from the zero column and value from the fourth column of data set
28
var fourthSeriesData = dataSet.mapAs({ x: 0, value: 4 });
29
30
// create column chart
31
var chart = anychart.column();
32
33
// turn on chart animation
34
chart.animation(true);
35
36
// set chart title text settings
37
chart.title(
38
'Combination of Stacked Column and Line Chart (Dual Y-Axis)'
39
);
40
41
// force chart scale to stuck series values
42
chart.yScale().stackMode('value');
43
44
// create scale for line series and extraYAxis
45
// it force line series to not stuck with over series
46
var scale = anychart.scales.linear();
47
scale.minimum(0).maximum(100).ticks({ interval: 20 });
48
49
// create extra axis on the right side of chart
50
// and set scale for it
51
var extraYAxis = chart.yAxis(1);
52
extraYAxis.orientation('right').scale(scale);
53
extraYAxis.labels().padding(0, 0, 0, 5);
54
55
// setup axis to append '%' symbol to label values
56
extraYAxis.labels().format('{%Value}%');
57
58
// create second series with mapped data
59
chart.column(secondSeriesData);
60
61
chart.crosshair(true);
62
63
// create line series and set scale for it
64
var lineSeries = chart.line(firstSeriesData);
65
lineSeries.yScale(scale).markers(true);
66
67
// create third series with mapped data
68
chart.column(thirdSeriesData);
69
70
// create fourth series with mapped data
71
chart.column(fourthSeriesData);
72
73
// set container id for the chart
74
chart.container('container');
75
76
// initiate chart drawing
77
chart.draw();
78
});