HTMLcopy
1
<div id="WaterfallContainer"></div>
CSScopy
6
1
html, body, #WaterfallContainer {
2
width: 100%;
3
height: 100%;
4
margin: 0;
5
padding: 0;
6
}
JavaScriptcopy
x
1
anychart.onDocumentReady(function () {
2
3
// set the data
4
var data = [
5
{ x: 'Total Revenue', value: 182527 },
6
{ x: 'Cost of Revenue', value: -84732 },
7
{ x: 'Gross Profit', isTotal: true },
8
{ x: 'Operating Expenses', value: -56571 },
9
{ x: 'Operating Income', isTotal: true },
10
{ x: 'Other Income', value: 8583 },
11
{ x: 'Other Expenses', value: -1725 },
12
{ x: 'Income Before Taxes', isTotal: true },
13
{ x: 'Provision for Taxes', value: -7813 },
14
{ x: 'Net Income', isTotal: true }
15
];
16
17
// create a waterfall chart
18
var chart = anychart.waterfall();
19
20
// set the chart title
21
chart.title('Income Statement for Alphabet Inc. (GOOGL), 2020');
22
23
// set the y-axis title
24
chart.yAxis().title('Amount (in millions)');
25
26
// add the usd symbol to the y-axis labels
27
chart.yAxis().labels().format('${%Value}');
28
29
// rotate the x-axis labels
30
chart.xAxis().labels().rotation(-90);
31
32
// customize the connector stroke
33
chart.connectorStroke("#ff6666", 2, "2 2", "round");
34
35
// enable HTML for the labels
36
chart.labels().useHtml(true);
37
38
// customize the labels
39
chart.labels().format(function() {
40
if (this.isTotal)
41
return "<span style='color:#dd2c00;font-weight:bold'>" +
42
this.absolute + "</span>";
43
return this.diff;
44
});
45
46
// create a series and set the data
47
var series = chart.waterfall(data);
48
49
// customize the appearance of the waterfall chart columns
50
// first, columns indicating total values
51
series.normal().fill("#ff6666", 0.3);
52
series.normal().hatchFill("forward-diagonal", "#ff6666", 0.5, 10);
53
series.normal().stroke("#ff6666");
54
series.hovered().fill("#ff6666", 0.1);
55
series.hovered().hatchFill("forward-diagonal", "#ff6666", 0.5, 10);
56
series.hovered().stroke("#ff6666", 2);
57
series.selected().fill("#ff6666", 0.5);
58
series.selected().hatchFill("forward-diagonal", "#ff6666", 0.5, 10);
59
series.selected().stroke("#ff6666", 4);
60
61
// second, falling columns
62
series.normal().fallingFill("#00cc99", 0.3);
63
series.normal().fallingStroke("#00cc99", 1, "10 5", "round");
64
series.hovered().fallingFill("#00cc99", 0.1);
65
series.hovered().fallingStroke("#00cc99", 2, "10 5", "round");
66
series.selected().fallingFill("#00cc99", 0.5);
67
series.selected().fallingStroke("#00cc99", 4, "10 5", "round");
68
69
// third, rising columns
70
series.normal().risingFill("#0066cc", 0.3);
71
series.normal().risingStroke("#0066cc");
72
series.hovered().risingFill("#0066cc", 0.1);
73
series.hovered().risingStroke("#0066cc", 2);
74
series.selected().risingFill("#0066cc", 0.5);
75
series.selected().risingStroke("#0066cc", 4);
76
77
// set the container id for the waterfall chart
78
chart.container('WaterfallContainer');
79
80
// draw the resulting chart
81
chart.draw();
82
83
});