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
{from: "Canada", to: "France", weight: 2230000},
6
{from: "Canada", to: "Germany", weight: 1990000},
7
{from: "Canada", to: "Italy", weight: 1180000},
8
{from: "Canada", to: "Spain", weight: 990000},
9
{from: "USA", to: "France", weight: 950000},
10
{from: "USA", to: "Germany", weight: 2020000},
11
{from: "USA", to: "Spain", weight: 1110000}
12
];
13
14
// create a chart and set the data
15
var chart = anychart.sankey(data);
16
17
// set the width of nodes
18
chart.nodeWidth("30%");
19
20
// set the chart title
21
chart.title("Sankey Diagram: Basic Sample");
22
23
24
25
// set the container id
26
chart.container("container");
27
28
// initiate drawing the chart
29
chart.draw();
30
31
chart.listen('click', function(e) {
32
if (e.domTarget.tag && e.domTarget.tag.element) {
33
var el = e.domTarget.tag.element;
34
var type = el.type ? 'flow' : 'node';
35
if (type === 'node') {
36
var level = el.level;
37
var name = el.name;
38
console.log(`Node on level ${level} with name ${name}`);
39
}
40
if (type === 'flow') {
41
console.log('Flow was clicked');
42
}
43
}
44
45
});
46
});