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 sankey chart
3
var chart = anychart.sankey();
4
5
// set chart's data
6
chart.data(getData());
7
8
// set chart's node width
9
chart.nodeWidth(100);
10
11
// set chart's node padding
12
chart.nodePadding(30);
13
14
// set tooltips position for node
15
chart.node().tooltip().anchor('center-bottom');
16
17
// Set flow's normal and hovered fill
18
chart.flow({
19
normal: {
20
fill: function () {
21
return anychart.color.lighten(this.sourceColor, .5) + ' ' + .3
22
},
23
},
24
hovered: {
25
fill: function () {
26
return this.sourceColor + ' ' + .9
27
},
28
}
29
});
30
31
// set container id for the chart
32
chart.container('container');
33
34
// initiate chart drawing
35
chart.draw();
36
});
37
38
function getData() {
39
return [
40
['Coal', 'Reserves', 64],
41
['Coal', 'Coal Exports', 31],
42
['Coal', 'Heating', 82],
43
['Coal', 'Electricity', 234],
44
['Electricity', 'Lighting', 34],
45
['Electricity', 'Heating', 200],
46
['Natural Gas', 'Reserves', 30],
47
['Natural Gas', 'Electricity', 100],
48
['Natural Gas', 'Heating', 100],
49
50
]
51
}