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", group: "family"},
7
{id: "Larry", group: "family"},
8
{id: "Marta", group: "family"},
9
{id: "Jane", group: "friends"},
10
{id: "Norma", group: "friends"},
11
{id: "Frank", group: "friends"},
12
{id: "Brett", group: "friends"},
13
{id: "Tommy", group: "lone wolf"}
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
var chart = anychart.graph(data);
29
30
// prevent zooming the chart with the mouse wheel
31
chart.interactivity().zoomOnMouseWheel(false);
32
33
// access groups of nodes
34
var family = chart.group("family");
35
var friends = chart.group("friends");
36
var loneWolf = chart.group("lone wolf");
37
38
// set the size of nodes in groups
39
family.normal().height(40);
40
family.hovered().height(55);
41
family.selected().height(55);
42
friends.normal().height(20);
43
friends.hovered().height(27);
44
friends.selected().height(27);
45
loneWolf.normal().height(20);
46
loneWolf.hovered().height(27);
47
loneWolf.selected().height(27);
48
49
// set the shape of nodes in groups
50
family.normal().shape("star5");
51
friends.normal().shape("diamond");
52
loneWolf.normal().shape("diagonal-cross");
53
54
// set the fill of nodes in groups
55
family.normal().fill("#ffa000");
56
family.hovered().fill("white");
57
family.selected().fill("#ffa000");
58
friends.normal().fill("#00bfa5");
59
friends.hovered().fill("white");
60
friends.selected().fill("#00bfa5");
61
loneWolf.normal().fill("#ff3300");
62
loneWolf.hovered().fill("white");
63
loneWolf.selected().fill("#ff3300");
64
65
// set the stroke of nodes in groups
66
family.normal().stroke(null);
67
family.hovered().stroke("#ffa000", 3);
68
family.selected().stroke("#333333", 3);
69
friends.normal().stroke(null);
70
friends.hovered().stroke("#00bfa5", 3);
71
friends.selected().stroke("#333333", 3);
72
loneWolf.normal().stroke(null);
73
loneWolf.hovered().stroke("#ff3300", 3);
74
loneWolf.selected().stroke("#333333", 3);
75
76
77
// set the chart title
78
chart.title("Network Graph: Nodes (Groups)");
79
80
// set the container id
81
chart.container("container");
82
83
// initiate drawing the chart
84
chart.draw();
85
});