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
3
// create data
4
var data = [
5
{x: "Start", value: 23, custom_field: "info 1"},
6
{x: "Jan", value: 22, custom_field: "info 2"},
7
{x: "Feb", value: -46, custom_field: "info 3"},
8
{x: "Mar", value: -91, custom_field: "info 4"},
9
{x: "Apr", value: 37, custom_field: "info 5"},
10
{x: "May", value: -21, custom_field: "info 6"},
11
{x: "Jun", value: 53, custom_field: "info 7"},
12
{x: "Jul", value: 31, custom_field: "info 8"},
13
{x: "Aug", value: -15, custom_field: "info 9"},
14
{x: "Sep", value: 42, custom_field: "info 10"},
15
{x: "Oct", value: 53, custom_field: "info 11"},
16
{x: "Nov", value: -15, custom_field: "info 12"},
17
{x: "Dec", value: 51, custom_field: "info 13"},
18
{x: "End", isTotal: true, custom_field: "info 14"}
19
];
20
21
// create a waterfall chart
22
var chart = anychart.waterfall();
23
24
// create a series and set the data
25
var series = chart.waterfall(data);
26
27
// enable HTML for labels
28
chart.labels().useHtml(true);
29
30
// configure labels
31
chart.labels().format(function() {
32
if (this.isTotal)
33
return "<span style='color:#dd2c00;font-weight:bold'>" +
34
this.absolute + "</span>";
35
return this.absolute;
36
});
37
38
// configure tooltips
39
chart.tooltip().titleFormat(function() {
40
if (this.isTotal)
41
return "TOTAL (" + this.getData("custom_field") + ")";
42
return this.x + " (" + this.getData("custom_field") + ")";
43
});
44
45
// set the chart title
46
chart.title("Waterfall Chart: Labels and Tooltips (Formatting Functions)");
47
48
// set the container id
49
chart.container("container");
50
51
// initiate drawing the chart
52
chart.draw();
53
});