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
['TEST', 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
.risingFill('#3c5e79')
33
.fallingFill('#3c5e79')
34
.normal()
35
.stroke('#3c5e79')
36
.risingStroke('#3c5e79')
37
.fallingStroke('#3c5e79');
38
39
// create waterfall series, Oklahoma series
40
chart.waterfall()
41
.data(data2)
42
.name('Oklahoma')
43
.fill('#5686ad')
44
.risingFill('#5686ad')
45
.fallingFill('#5686ad')
46
.normal()
47
.stroke('#3c5e79')
48
.risingStroke('#3c5e79')
49
.fallingStroke('#3c5e79');
50
51
// create waterfall series, Texas series
52
chart.waterfall()
53
.data(data3)
54
.name('Texas')
55
.fill('#7bc0f7')
56
.risingFill('#7bc0f7')
57
.fallingFill('#7bc0f7')
58
.normal()
59
.stroke('#3c5e79')
60
.risingStroke('#3c5e79')
61
.fallingStroke('#3c5e79');
62
63
// set labels settings
64
chart.labels()
65
.enabled(true)
66
.fontColor('#fff')
67
.position('center');
68
69
// set legend settings
70
chart.legend()
71
.enabled(true)
72
.itemsSourceMode('default');
73
74
// set title tooltip
75
chart.tooltip().titleFormat('{%SeriesName}');
76
77
// set container id for the chart
78
chart.container('container');
79
// initiate chart drawing
80
chart.draw();
81
});