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
['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
['Total', {isTotal: true}, {isTotal: true}, {isTotal: true}]
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 data1 = dataSet.mapAs({'x': 0, 'value': 1});
14
// map data for the second series, take x from the zero column and value from the second column of data set
15
var data2 = dataSet.mapAs({'x': 0, 'value': 2});
16
// map data for the third series, take x from the zero column and value from the third column of data set
17
var data3 = dataSet.mapAs({'x': 0, 'value': 3});
18
19
// create waterfall chart
20
var chart = anychart.waterfall();
21
22
// set chart title
23
chart.title('Income Statement by Region');
24
// set data mode
25
chart.dataMode('absolute');
26
27
// create waterfall series, Iowa series
28
chart.waterfall()
29
.data(data1)
30
.name('Iowa')
31
.fill('#3c5e79')
32
.stroke('#3c5e79')
33
.risingFill('#3c5e79')
34
.fallingFill('#3c5e79')
35
.risingStroke('#3c5e79')
36
.fallingStroke('#3c5e79');
37
38
// create waterfall series, Oklahoma series
39
chart.waterfall()
40
.data(data2)
41
.name('Oklahoma')
42
.fill('#5686ad')
43
.stroke('#3c5e79')
44
.risingFill('#5686ad')
45
.fallingFill('#5686ad')
46
.risingStroke('#3c5e79')
47
.fallingStroke('#3c5e79');
48
49
// create waterfall series, Texas series
50
chart.waterfall()
51
.data(data3)
52
.name('Texas')
53
.fill('#7bc0f7')
54
.stroke('#3c5e79')
55
.risingFill('#7bc0f7')
56
.fallingFill('#7bc0f7')
57
.risingStroke('#3c5e79')
58
.fallingStroke('#3c5e79');
59
60
// set labels settings
61
chart.labels()
62
.enabled(true)
63
.fontColor('#fff')
64
.position('center');
65
66
// set legend settings
67
chart.legend()
68
.enabled(true)
69
.itemsSourceMode('default');
70
71
// set title tooltip
72
chart.tooltip().titleFormat('{%SeriesName}');
73
74
// set container id for the chart
75
chart.container('container');
76
// initiate chart drawing
77
chart.draw();
78
});