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
// create data set on our data
3
var dataSet = anychart.data.set([
4
['Tree', .406, .253, .182, .037, .034, .034, 0, 0, 0],
5
['Weeds', 0, 0, 0, 0, 0, 0, .020, .021, 0],
6
['Grass', 0, 0, 0, 0, 0, 0, 0, 0, .013]
7
]);
8
9
// map data for the first series, take x from the zero column and value from the first column of data set
10
var seriesData_1 = dataSet.mapAs({'x': 0, 'value': 1});
11
12
// map data for the second series, take x from the zero column and value from the second column of data set
13
var seriesData_2 = dataSet.mapAs({'x': 0, 'value': 2});
14
15
// map data for the second series, take x from the zero column and value from the third column of data set
16
var seriesData_3 = dataSet.mapAs({'x': 0, 'value': 3});
17
18
// map data for the fourth series, take x from the zero column and value from the fourth column of data set
19
var seriesData_4 = dataSet.mapAs({'x': 0, 'value': 4});
20
21
// map data for the fourth series, take x from the zero column and value from the fourth column of data set
22
var seriesData_5 = dataSet.mapAs({'x': 0, 'value': 5});
23
24
// map data for the fourth series, take x from the zero column and value from the fourth column of data set
25
var seriesData_6 = dataSet.mapAs({'x': 0, 'value': 6});
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 seriesData_7 = dataSet.mapAs({'x': 0, 'value': 7});
29
30
// map data for the fourth series, take x from the zero column and value from the fourth column of data set
31
var seriesData_8 = dataSet.mapAs({'x': 0, 'value': 8});
32
33
// map data for the fourth series, take x from the zero column and value from the fourth column of data set
34
var seriesData_9 = dataSet.mapAs({'x': 0, 'value': 9});
35
36
37
// create bar chart
38
var chart = anychart.column();
39
40
// turn on chart animation
41
chart.animation(true);
42
43
// force chart to stack values by Y scale.
44
chart.yScale().stackMode('percent');
45
46
// set chart title text settings
47
chart.title('Major Pollen Producers in Atlanta, GA');
48
chart.title().padding([0, 0, 5, 0]);
49
50
// helper function to setup label settings for all series
51
var setupSeriesLabels = function (series, name) {
52
series.name(name)
53
.stroke('3 #fff 1');
54
series.hovered().stroke('3 #fff 1');
55
};
56
57
// temp variable to store series instance
58
var series;
59
60
// create first series with mapped data
61
series = chart.column(seriesData_1);
62
setupSeriesLabels(series, 'Oak');
63
64
// create second series with mapped data
65
series = chart.column(seriesData_2);
66
setupSeriesLabels(series, 'Pine');
67
68
// create third series with mapped data
69
series = chart.column(seriesData_3);
70
setupSeriesLabels(series, 'Other Tree');
71
72
// create fourth series with mapped data
73
series = chart.column(seriesData_4);
74
setupSeriesLabels(series, 'Willow');
75
76
// create fourth series with mapped data
77
series = chart.column(seriesData_5);
78
setupSeriesLabels(series, 'Cypress');
79
80
// create fourth series with mapped data
81
series = chart.column(seriesData_6);
82
setupSeriesLabels(series, 'Mulberry');
83
84
// create fourth series with mapped data
85
series = chart.column(seriesData_7);
86
setupSeriesLabels(series, 'Ragweed');
87
88
// create fourth series with mapped data
89
series = chart.column(seriesData_8);
90
setupSeriesLabels(series, 'Other Weed');
91
92
// create fourth series with mapped data
93
series = chart.column(seriesData_9);
94
setupSeriesLabels(series, 'Grass');
95
96
// turn on legend
97
chart.legend().enabled(true).fontSize(13).padding([0, 0, 20, 0]);
98
// set yAxis labels formatter
99
chart.yAxis().labels().format('{%Value}{groupsSeparator: }');
100
101
// set titles for axes
102
chart.xAxis().title('Grouped Pollen Types');
103
chart.yAxis().title('Percent');
104
105
// set interactivity hover
106
chart.interactivity().hoverMode('by-x');
107
108
chart.tooltip()
109
.valuePrefix('')
110
.displayMode('union');
111
112
// set container id for the chart
113
chart.container('container');
114
115
// initiate chart drawing
116
chart.draw();
117
});