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
['Espresso', 1, null, null, null, null, null],
5
['Doppio', 2, null, null, null, null, null],
6
['Trippio', 3, null, null, null, null, null],
7
['Americano', 1, 3, null, null, null, null],
8
['Cappuchino', 1, null, 1, 2, null, null],
9
['Macchiato', 2.5, null, null, 1, null, null],
10
['Latte', 1, null, 2, 1, null, null],
11
['Latte Macchiato', 1, null, 2, null, 1, null],
12
['Vienna Coffee', 1, null, null, null, 2, null],
13
['Mocco', 1, null, 1, null, 1, 1]
14
]);
15
16
// map data for the first series, take x from the zero column and value from the first column of data set
17
var espresso = dataSet.mapAs({ x: 0, value: 1 });
18
19
// map data for the second series, take x from the zero column and value from the second column of data set
20
var water = dataSet.mapAs({ x: 0, value: 2 });
21
22
// map data for the second series, take x from the zero column and value from the third column of data set
23
var milk = dataSet.mapAs({ x: 0, value: 3 });
24
25
// map data for the fourth series, take x from the zero column and value from the fourth column of data set
26
var steamedMilk = dataSet.mapAs({ x: 0, value: 4 });
27
28
// map data for the fifth series, take x from the zero column and value from the fourth column of data set
29
var cream = dataSet.mapAs({ x: 0, value: 5 });
30
31
// map data for the sixth series, take x from the zero column and value from the fourth column of data set
32
var chocolate = dataSet.mapAs({ x: 0, value: 6 });
33
34
// create bar chart
35
var chart = anychart.column3d();
36
37
// force chart to stack values by Y scale.
38
chart.yScale().stackMode('value');
39
40
// turn on chart animation
41
chart.animation(true);
42
43
// set chart title text settings
44
chart.title('Types of Coffee');
45
chart.title().padding([0, 0, 15, 0]);
46
47
// helper function to setup label settings for all series
48
var setupSeriesLabels = function (series, name, color) {
49
series.name(name).fill(color).stroke('1 #f7f3f3 1');
50
series.hovered().stroke('3 #f7f3f3 1');
51
};
52
53
// temp variable to store series instance
54
var series;
55
56
// create first series with mapped data
57
series = chart.column(espresso);
58
setupSeriesLabels(series, 'Espresso', '#3e2723');
59
60
// create second series with mapped data
61
series = chart.column(water);
62
setupSeriesLabels(series, 'Water', '#64b5f6');
63
64
// create third series with mapped data
65
series = chart.column(milk);
66
setupSeriesLabels(series, 'Milk', '#fff3e0');
67
68
// create fourth series with mapped data
69
series = chart.column(steamedMilk);
70
setupSeriesLabels(series, 'Steamed milk', '#bcaaa4');
71
72
// create fifth series with mapped data
73
series = chart.column(cream);
74
setupSeriesLabels(series, 'Cream', '#e6c1b5');
75
76
// create sixth series with mapped data
77
series = chart.column(chocolate);
78
setupSeriesLabels(series, 'Chocolate', '#bf360c');
79
80
// turn on legend
81
chart.legend().enabled(true).fontSize(13).padding([0, 0, 20, 0]);
82
83
// set yAxis labels formatter
84
chart.yScale().ticks([0, 1, 2, 3, 4, 5]);
85
chart.xAxis().stroke('#a18b7e');
86
chart.xAxis().labels().fontColor('#a18b7e');
87
chart.yAxis().stroke('#a18b7e');
88
chart
89
.yAxis()
90
.labels()
91
.fontColor('#a18b7e')
92
.format('{%Value}{groupsSeparator: }');
93
94
// set titles for axises
95
chart
96
.yAxis()
97
.title()
98
.enabled(true)
99
.text('Portions of Ingredients')
100
.fontColor('#a18b7e');
101
102
// set interactivity settings
103
chart.interactivity().hoverMode('by-x');
104
105
// set tooltip settings
106
chart.tooltip().displayMode('union').format('{%Value} {%SeriesName}');
107
108
// set grid settings
109
chart.yGrid().stroke('#a18b7e');
110
chart.xGrid().stroke('#a18b7e');
111
112
// set container id for the chart
113
chart.container('container');
114
115
// initiate chart drawing
116
chart.draw();
117
});