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: "China", weight: 1250000},
10
{from: "USA", to: "France", weight: 950000},
11
{from: "USA", to: "Germany", weight: 2020000},
12
{from: "USA", to: "Spain", weight: 1110000},
13
{from: "France", to: "China", weight: 1100000},
14
{from: "France", to: "Japan", weight: 1050000},
15
{from: "France", to: "India", weight: 1030000},
16
{from: "Germany", to: "China", weight: 2150000},
17
{from: "Germany", to: "Japan", weight: 660000},
18
{from: "Germany", to: "India", weight: 1200000},
19
{from: "Italy", to: "China", weight: 1180000},
20
{from: "Spain", to: "China", weight: 1120000},
21
{from: "Spain", to: "Japan", weight: 980000}
22
];
23
24
// create a chart and set the data
25
var chart = anychart.sankey(data);
26
27
// set the width of nodes
28
chart.nodeWidth("30%");
29
30
// set the chart title
31
chart.title("Sankey Diagram: Data");
32
33
// set the container id
34
chart.container("container");
35
36
// initiate drawing the chart
37
chart.draw();
38
});