HTMLcopy
1
<button id="zoomInButton" onclick="zoomIn()">Zoom In</button>
2
<button id="zoomOutButton" onclick="zoomOut()">Zoom Out</button>
3
<button id="moveButton" onclick="move()">Move</button>
4
<label>x: <input id="xInput" value="50"></label>
5
<label>y: <input id="yInput" value="-50"></label>
6
<button id="fitButton" onclick="fit()">Fit to Container</button>
7
<div id="container"></div>
CSScopy
26
1
html, body {
2
width: 100%;
3
height: 100%;
4
margin: 0;
5
padding: 0;
6
}
7
button {
8
margin: 10px 0 0 10px;
9
}
10
label {
11
display: inline-block;
12
margin: 10px 0 0 10px;
13
}
14
input {
15
width: 30px;
16
}
17
#fitButton {
18
position: absolute;
19
right: 10px;
20
}
21
#container {
22
position: absolute;
23
width: 100%;
24
top: 35px;
25
bottom: 0;
26
}
JavaScriptcopy
x
1
anychart.onDocumentReady(function () {
2
3
// create data
4
var data = {
5
nodes: [
6
{id: "Richard"},
7
{id: "Larry"},
8
{id: "Marta"},
9
{id: "Jane"},
10
{id: "Norma"},
11
{id: "Frank"},
12
{id: "Brett"},
13
{id: "Tommy"}
14
],
15
edges: [
16
{from: "Richard", to: "Larry"},
17
{from: "Richard", to: "Marta"},
18
{from: "Larry", to: "Marta"},
19
{from: "Marta", to: "Jane"},
20
{from: "Jane", to: "Norma"},
21
{from: "Jane", to: "Frank"},
22
{from: "Jane", to: "Brett"},
23
{from: "Brett", to: "Frank"}
24
]
25
};
26
27
// create a chart and set the data
28
chart = anychart.graph(data);
29
30
// prevent the default behavior of the chart
31
chart.interactivity().enabled(false);
32
33
// set the chart title
34
chart.title("Network Graph: Navigation (Methods)");
35
36
// set the container id
37
chart.container("container");
38
39
// initiate drawing the chart
40
chart.draw();
41
});
42
43
// zoom the chart in
44
function zoomIn() {
45
chart.zoomIn();
46
}
47
48
// zoom the chart out
49
function zoomOut() {
50
chart.zoomOut();
51
}
52
53
// move the chart by given values
54
function move() {
55
var x = document.getElementById("xInput").value;
56
var y = document.getElementById("yInput").value;
57
chart.move(x, y);
58
}
59
60
// fit the chart to the container
61
function fit() {
62
chart.fit();
63
}