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
['Jan-2022', 5250, 5250, 0],
5
['Feb-2022', 7125, 1875, 0],
6
['Mar-2022', 25993, 5850, 13018],
7
['Apr-2022', 30755.5, 1500, 3262.5],
8
['May-2022', 35818.5, 0, 5063],
9
['Jun-2022', 49693.5, 3750, 10125],
10
['Jul-2022', 51568.5, 1875, 0],
11
['Aug-2022', 63880, 0, 12311.5],
12
['Sep-2022', 73286, 3750, 5656],
13
['Oct-2022', 81911, 3975, 4650],
14
['Nov-2022', 93161, 3750, 7500],
15
['Dec-2022', 98828, 1500, 4167]
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(100000).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).name("Experience Cost Savings").color("Green");
60
61
chart.crosshair(true);
62
63
// create line series and set scale for it
64
var lineSeries = chart.line(firstSeriesData).name("Incremental Cost Savings").color("#f1c232");
65
lineSeries.yScale(scale).markers(true);
66
67
// create third series with mapped data
68
chart.column(thirdSeriesData).name("Fulfilment Cost Savings").color("#0080ff");
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
79
80
var legend = chart.legend();
81
legend.enabled(true);
82
legend.position('center');
83
legend.itemsLayout('horizontal');
84
85
//var labels = chart.labels();
86
//labels.enabled(true);
87
//labels.color("#000000");
88
});