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 a data set
4
var data = anychart.data.set([
5
["Start", 23, 30, 21],
6
["Jan", 22, 22, 54],
7
["Feb", -46, 45, -32],
8
["Mar", -91, -30, -28],
9
["Apr", 37, -27, 36],
10
["May", -24, 62, -48],
11
["Jun", 55, 40, -29],
12
["Jul", 31, 33, 41],
13
["Aug", -25, -46, 36],
14
["Sep", 42, 23, 22],
15
["Oct", 67, -44, -40],
16
["Nov", -24, -31, 37],
17
["Dec", 51, 28, 25],
18
["End", {isTotal: true}, {isTotal: true}, {isTotal: true}],
19
]);
20
21
// map the data
22
var seriesData_1 = data.mapAs({x: 0, value: 1});
23
var seriesData_2 = data.mapAs({x: 0, value: 2});
24
var seriesData_3 = data.mapAs({x: 0, value: 3});
25
26
// create a waterfall chart
27
var chart = anychart.waterfall();
28
29
// create the first series, set the name and data
30
var series1 = chart.waterfall(seriesData_1);
31
series1.name("Product A");
32
33
// create the second series, set the name and data
34
var series2 = chart.waterfall(seriesData_2);
35
series2.name("Product B");
36
37
// create the third series, set the name and data
38
var series3 = chart.waterfall(seriesData_3);
39
series3.name("Product C");
40
41
// disable labels
42
series1.labels(false);
43
series2.labels(false);
44
series3.labels(false);
45
46
// add hatch fills
47
series1.hatchFill("percent05", "white", 1, 9);
48
series1.fallingHatchFill("percent05", "white", 1, 9);
49
series1.risingHatchFill("percent05", "white", 1, 9);
50
51
series2.hatchFill("dashed-backward-diagonal", "white", 1, 9);
52
series2.fallingHatchFill("dashed-backward-diagonal", "white", 1, 9);
53
series2.risingHatchFill("dashed-backward-diagonal", "white", 1, 9);
54
55
series3.hatchFill("forward-diagonal", "white", 1, 6);
56
series3.fallingHatchFill("forward-diagonal", "white", 1, 6);
57
series3.risingHatchFill("forward-diagonal", "white", 1, 6);
58
59
// configure the legend
60
chart.legend().itemsSourceMode("default");
61
62
// set the chart title
63
chart.title("Waterfall Chart: Legend");
64
65
// set the container id
66
chart.container("container");
67
68
// initiate drawing the chart
69
chart.draw();
70
});