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
['Nail polish', 12814, 3054, 4376, 4229],
5
['Eyebrow pencil', 13012, 5067, 3987, 3932],
6
['Rouge', 11624, 7004, 3574, 5221],
7
['Lipstick', 8814, 9054, 4376, 9256],
8
['Eyeshadows', 12998, 12043, 4572, 3308],
9
['Eyeliner', 12321, 15067, 3417, 5432]
10
]);
11
12
// map data for the first series, take x from the zero column and value from the first column of data set
13
var firstSeriesData = dataSet.mapAs();
14
15
// map data for the second series, take x from the zero column and value from the second column of data set
16
var secondSeriesData = dataSet.mapAs();
17
18
// create bar chart
19
var chart = anychart.column();
20
21
// turn on chart animation
22
chart.animation(true);
23
24
// force chart to stack values by Y scale.
25
chart.yScale().stackMode('percent');
26
27
// set chart title text settings
28
chart.title('Regional ratio of cosmetic products sales');
29
30
// set yAxis labels formatting, force it to add % to values
31
chart.yAxis(0).labels().format('{%Value}%');
32
33
// temp variable to store series instance
34
var series;
35
var seriesArray= [firstSeriesData, secondSeriesData]
36
37
for(let i=0;i<seriesArray.length;i++){
38
const view = chart.column(seriesArray[i]);
39
if (i==0)view.select([0]);
40
}
41
chart.interactivity().hoverMode('by-x');
42
chart.tooltip().titleFormat('{%X}').displayMode('union');
43
// turn on legend
44
chart.legend().enabled(true).fontSize(13);
45
46
// set container id for the chart
47
chart.container('container');
48
49
// initiate chart drawing
50
chart.draw();
51
});