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
var dataTable = anychart.data.table();
3
// data comes from the function in https://cdn.anychart.com/csv-data/dji-daily-short.js
4
dataTable.addData(get_dji_daily_short_data());
5
6
var chart = anychart.stock();
7
8
chart.plot(0).area(dataTable.mapAs({value: 1}));
9
chart.plot(0).area(dataTable.mapAs({value: 2}));
10
chart.plot(0).area(dataTable.mapAs({value: 3}));
11
chart.plot(0).area(dataTable.mapAs({value: 4}));
12
13
// set y scale stack mode to percent
14
chart.plot(0).yScale().stackMode("percent");
15
16
// set minimum and maximum
17
chart.plot(0).yScale().minimum(0).maximum(100);
18
19
// format axis to show percents
20
chart.plot(0).yAxis().labels().format("{%value}%");
21
22
chart.title("Percent Stack Mode in Percent Charts");
23
chart.container("container");
24
chart.draw();
25
26
chart.selectRange("ytd");
27
});