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: "Revenue", value: 5077.482 },
6
{ x: "Cost of revenue", value: -1797.510 },
7
{ x: "Gross profit", isTotal: true },
8
{ x: "Operating expenses", value: -3772.711 },
9
{ x: "Income (loss) from operations", isTotal: true },
10
{ x: "Interest expense", value: -51.186 },
11
{ x: "Interest income", value: 35.683 },
12
{ x: "Other income (expense), net", value: 97.129 },
13
{ x: "Income (loss) before income taxes", isTotal: true },
14
{ x: "(Provision) benefit for income taxes", value: 189.704 },
15
{ x: "Net income (loss)", isTotal: true }
16
];
17
18
// create a waterfall chart
19
var chart = anychart.waterfall();
20
21
// add the zero line
22
var line = chart.lineMarker().value(0);
23
24
// rotate the chart
25
chart.isVertical(true);
26
27
// set the reverse order of the bars
28
chart.xScale().inverted(true);
29
30
// customize the labels
31
chart.labels()
32
.useHtml(true)
33
.format(function() {
34
if (this.isTotal)
35
return "<span style='color: #dd2c00; font-weight: 100; font-size: 11'>" +
36
this.absolute.toFixed(0) + "M" + "</span>";
37
return "<span style='color: gray; font-weight: 100; font-size: 11'>" +
38
this.diff.toFixed(0) + "M" + "</span>";
39
});
40
41
// set the chart title
42
chart.title("Income Statement for Twitter Inc. (2021)");
43
44
// customize the format of the y-axis labels
45
chart.yAxis().labels().format("{%Value}{scale:(1000)(1)|(B)}");
46
47
// set the y-axis title
48
chart.yAxis().title("USD");
49
50
// create a series and set the data
51
var series = chart.waterfall(data);
52
53
// configure the tooltip title
54
chart.tooltip().titleFormat("{%x}" + " (M USD)");
55
56
// customize the connector stroke
57
chart.connectorStroke("#ff6666", 2, "2 2", "round");
58
59
// configure the visual settings of the series:
60
// normal state
61
series.normal()
62
.fill("#8C8C8C", 0.7)
63
.hatchFill("forward-diagonal", "#BEBEBE", 1, 10)
64
.stroke("#8C8C8C")
65
.fallingFill("#FC4E6F", 0.8)
66
.fallingStroke("#FC4E6F", 1, )
67
.risingFill("#44C882", 0.8)
68
.risingStroke("44C882");
69
// hovered state
70
series.hovered()
71
.fill("#8C8C8C", 0.1)
72
.hatchFill("forward-diagonal", "#117A65", 1, 10)
73
.stroke("#8C8C8C", 2)
74
.fallingFill("#FC4E6F", 0.1)
75
.fallingStroke("#FC4E6F", 2, "10 5", )
76
.risingFill("44C882", 0.1)
77
.risingStroke("44C882", 2);
78
// selected state
79
series.selected()
80
.fill("#8C8C8C", 0.5)
81
.hatchFill("forward-diagonal", "#8C8C8C", 1, 10)
82
.stroke("#8C8C8C", 4)
83
.fallingFill("#922B21", 0.5)
84
.fallingStroke("#B03A2E", 4, )
85
.risingFill("#117864", 0.5)
86
.risingStroke("#148F77", 1);
87
88
// add an arrow
89
var totalChangeArrow = chart.addArrow({
90
from: "Revenue",
91
to: "Net income (loss)"
92
});
93
94
// set arrow's label format
95
totalChangeArrow.label().format("{%Value}{numDecimals:0}" + "M");
96
97
// set the container id for the waterfall chart
98
chart.container("WaterfallContainer");
99
100
// draw the resulting chart
101
chart.draw();
102
103
});