HTMLcopy
1
<div id="container"></div>
CSScopy
6
1
html, body, #container {
2
width: 100%;
3
height: 80%;
4
margin: 0;
5
padding: 0;
6
}
JavaScriptcopy
x
1
anychart.onDocumentReady(function () {
2
// create data set on our data
3
var dataSet = anychart.data.set([
4
['Ownership', 68, 32, 0 ],
5
['Interaction', 64.7, 25.3, 10],
6
['Ngh_outdoor', 53.89, 36.94, 9.17 ],
7
['oth_indoor', 83.3, 6.4, 10.3],
8
]);
9
10
// map data for the first series, take x from the zero column and value from the first column of data set
11
var seriesData_1 = dataSet.mapAs({'x': 0, 'value': 1});
12
13
// map data for the second series, take x from the zero column and value from the second column of data set
14
var seriesData_2 = dataSet.mapAs({'x': 0, 'value': 2});
15
16
// map data for the third series, take x from the zero column and value from the third column of data set
17
var seriesData_3 = dataSet.mapAs({'x': 0, 'value': 3});
18
19
20
21
// create bar chart
22
var chart = anychart.bar();
23
24
// turn on chart animation
25
chart.animation(false);
26
27
// set container id for the chart
28
chart.container('container');
29
chart.padding([4, 10, 5, 10]);
30
31
// set scale minimum
32
chart.yScale().minimum(0);
33
34
// force chart to stack values by Y scale.
35
chart.yScale().stackMode('percent');
36
37
chart.yAxis().labels().format(function () {
38
return this.value.toLocaleString();
39
});
40
41
// set titles for axises
42
chart.xAxis().title('Products');
43
chart.yAxis().title('Revenue in Dollars');
44
45
// helper function to setup label settings for all series
46
var setupSeriesLabels = function (series, name) {
47
series.name(name);
48
series.tooltip().valuePrefix('$');
49
series.stroke('3 #fff 1');
50
series.hovered().stroke('3 #fff 1');
51
};
52
53
// temp variable to store series instance
54
var series;
55
56
// create first series with mapped data
57
series = chart.bar(seriesData_1);
58
setupSeriesLabels(series, 'Yes');
59
60
// create second series with mapped data
61
series = chart.bar(seriesData_2);
62
setupSeriesLabels(series, 'No');
63
64
// create third series with mapped data
65
series = chart.bar(seriesData_3);
66
setupSeriesLabels(series, 'Unsure');
67
68
chart.barGroupsPadding(0);
69
70
// turn on legend
71
chart.legend().enabled(true).fontSize(13).padding([0, 0, 5, 0]);
72
chart.interactivity().hoverMode('by-x');
73
chart.tooltip().displayMode('union');
74
// initiate chart drawing
75
chart.draw();
76
});