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
nodes: [
6
{id: "Richard", url: 'https://google.com'},
7
{id: "Larry", url: 'https://www.wikipedia.org'},
8
9
],
10
edges: [
11
{from: "Richard", to: "Larry"},
12
]
13
};
14
15
// create a chart and set the data
16
var chart = anychart.graph(data);
17
18
// set the chart title
19
chart.title("Click nodes");
20
chart.container("container").draw();
21
22
chart.listen('click', function(e) {
23
var tag = e.domTarget.tag;
24
if (tag) {
25
console.log(`Clicked ${tag.type} with ID ${tag.id}`);
26
27
if (tag.type === 'node') {
28
// get url from data directly
29
var url;
30
for (var i = 0; i < data.nodes.length; i++) {
31
if (data.nodes[i].id === tag.id) {
32
url = data.nodes[i].url;
33
break;
34
}
35
}
36
37
// open url
38
window.open(url, '_blank');
39
}
40
}
41
});
42
43
44
45
});