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: "Solar Energy", to: "Shading", weight: 10, custom_field: "info 1"},
6
{from: "Shading", to: null, weight: 7, custom_field: "info 2"},
7
{from: "Shading", to: "Facade", weight: 3, custom_field: "info 3"},
8
{from: "Facade", to: null, weight: 2, custom_field: "info 4"},
9
{from: "Facade", to: "Interior", weight: 1, custom_field: "info 5"}
10
];
11
12
// create a chart and set the data
13
var chart = anychart.sankey(data);
14
15
// set the width of nodes
16
chart.nodeWidth("50%");
17
18
// configure labels
19
chart.node().labels().useHtml(true);
20
chart.node().labels().format(
21
"<span style='font-weight:bold'>{%name}</span><br>{%value}"
22
);
23
chart.flow().hovered().labels().enabled(false);
24
chart.dropoff().normal().labels().enabled(true);
25
chart.dropoff().labels().padding(10);
26
27
// configure tooltips
28
chart.node().tooltip().format("value: {%value}");
29
chart.flow().tooltip().format("value: {%value}\n\n{%custom_field}");
30
chart.dropoff().tooltip().format("value: {%value}\n\n{%custom_field}");
31
32
// configure the chart title
33
chart.title("Sankey Diagram: Labels and Tooltips (Tokens)");
34
35
// set the container id
36
chart.container("container");
37
38
// initiate drawing the chart
39
chart.draw();
40
});