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
['Revenue', 175000, 140000, 250650],
5
['Services Revenue', 235050, 225250, 390580],
6
['Fixed Costs', 177950, 160550, 290890],
7
['Sales and Marketing Costs', 121050, 105500, 220500],
8
['Variable Costs', 65890, 55890, 105000]
9
]);
10
11
// map data for the first series, take x from the zero column and value from the first column of data set
12
var data1 = dataSet.mapAs({ x: 0, value: 1 });
13
// map data for the second series, take x from the zero column and value from the second column of data set
14
var data2 = dataSet.mapAs({ x: 0, value: 2 });
15
// map data for the third series, take x from the zero column and value from the third column of data set
16
var data3 = dataSet.mapAs({ x: 0, value: 3 });
17
18
// create waterfall chart
19
var chart = anychart.waterfall();
20
21
// set chart title
22
chart.title('Income Statement by Region');
23
// set data mode
24
chart.dataMode('absolute');
25
26
chart.pointWidth('85%');
27
28
// create waterfall series, Iowa series
29
chart
30
.waterfall()
31
.data(data1)
32
.name('Iowa')
33
.fill('#3c5e79')
34
.risingFill('#3c5e79')
35
.fallingFill('#3c5e79')
36
.normal()
37
.stroke('#3c5e79')
38
.risingStroke('#3c5e79')
39
.fallingStroke('#3c5e79');
40
41
// create waterfall series, Oklahoma series
42
chart
43
.waterfall()
44
.data(data2)
45
.name('Oklahoma')
46
.fill('#5686ad')
47
.risingFill('#5686ad')
48
.fallingFill('#5686ad')
49
.normal()
50
.stroke('#3c5e79')
51
.risingStroke('#3c5e79')
52
.fallingStroke('#3c5e79');
53
54
// create waterfall series, Texas series
55
chart
56
.waterfall()
57
.data(data3)
58
.name('Texas')
59
.fill('#7bc0f7')
60
.risingFill('#7bc0f7')
61
.fallingFill('#7bc0f7')
62
.normal()
63
.stroke('#3c5e79')
64
.risingStroke('#3c5e79')
65
.fallingStroke('#3c5e79');
66
67
// set labels settings
68
chart.labels().enabled(true).fontColor('#fff').position('center');
69
70
// get stack labels
71
var stackLabels = chart.stackLabels();
72
73
// enable stack labels and set Y offset for them
74
stackLabels
75
.enabled(true)
76
.format('{%stack}')
77
.offsetY(10);
78
79
// setup stack labels background
80
stackLabels.background()
81
.enabled(true)
82
.stroke('#e6e6e6')
83
.fill('#f6f6f6');
84
85
// set legend settings
86
chart.legend().enabled(true).itemsSourceMode('default');
87
88
chart.addTotal({x: 'Variable Costs', name: 'Total'});
89
chart.splitTotal([
90
{name: 'Texas', value: 105000, fill: '#3c5e79'},
91
{name: 'Oklahoma', value: 55890, fill: '#5686ad'},
92
{name: 'Iowa', value: 65890, fill: '#7bc0f7'}
93
]);
94
95
// set title tooltip
96
chart.tooltip().titleFormat('{%SeriesName}');
97
98
// set container id for the chart
99
chart.container('container');
100
// initiate chart drawing
101
chart.draw();
102
});