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
const data = {
5
"nodes": [
6
// parent company
7
{"id": "Volkswagen Group", "group": "CoreCompany"},
8
// child companies
9
{"id": "Audi", "group": "ChildCompany"},
10
{"id": "CUPRA", "group": "ChildCompany"},
11
{"id": "Ducati", "group": "ChildCompany"},
12
{"id": "Lamborghini", "group": "ChildCompany"},
13
{"id": "MAN", "group": "ChildCompany"},
14
{"id": "Porsche", "group": "ChildCompany"},
15
{"id": "Scania", "group": "ChildCompany"},
16
{"id": "SEAT", "group": "ChildCompany"},
17
{"id": "Škoda", "group": "ChildCompany"},
18
{"id": "Volkswagen", "group": "ChildCompany"},
19
// products
20
{"id": "Audi Cars", "group": "Product"},
21
{"id": "Audi SUVs", "group": "Product"},
22
{"id": "Audi Electric Vehicles", "group": "Product"},
23
{"id": "CUPRA Performance Cars", "group": "Product"},
24
{"id": "CUPRA SUVs", "group": "Product"},
25
{"id": "Ducati Motorcycles", "group": "Product"},
26
{"id": "Lamborghini Sports Cars", "group": "Product"},
27
{"id": "Lamborghini SUVs", "group": "Product"},
28
{"id": "MAN Trucks", "group": "Product"},
29
{"id": "MAN Buses", "group": "Product"},
30
{"id": "Porsche Sports Cars", "group": "Product"},
31
{"id": "Porsche SUVs", "group": "Product"},
32
{"id": "Porsche Sedans", "group": "Product"},
33
{"id": "Scania Trucks", "group": "Product"},
34
{"id": "Scania Buses", "group": "Product"},
35
{"id": "SEAT Cars", "group": "Product"},
36
{"id": "SEAT SUVs", "group": "Product"},
37
{"id": "SEAT Electric Vehicles", "group": "Product"},
38
{"id": "Škoda Cars", "group": "Product"},
39
{"id": "Škoda SUVs", "group": "Product"},
40
{"id": "Škoda Electric Vehicles", "group": "Product"},
41
{"id": "Volkswagen Cars", "group": "Product"},
42
{"id": "Volkswagen SUVs", "group": "Product"},
43
{"id": "Volkswagen Vans", "group": "Product"},
44
{"id": "Volkswagen Trucks", "group": "Product"}
45
],
46
"edges": [
47
// parent to child companies
48
{"from": "Volkswagen Group", "to": "Audi"},
49
{"from": "Volkswagen Group", "to": "CUPRA"},
50
{"from": "Volkswagen Group", "to": "Ducati"},
51
{"from": "Volkswagen Group", "to": "Lamborghini"},
52
{"from": "Volkswagen Group", "to": "MAN"},
53
{"from": "Volkswagen Group", "to": "Porsche"},
54
{"from": "Volkswagen Group", "to": "Scania"},
55
{"from": "Volkswagen Group", "to": "SEAT"},
56
{"from": "Volkswagen Group", "to": "Škoda"},
57
{"from": "Volkswagen Group", "to": "Volkswagen"},
58
// child companies to products
59
{"from": "Audi", "to": "Audi Cars"},
60
{"from": "Audi", "to": "Audi SUVs"},
61
{"from": "Audi", "to": "Audi Electric Vehicles"},
62
{"from": "CUPRA", "to": "CUPRA Performance Cars"},
63
{"from": "CUPRA", "to": "CUPRA SUVs"},
64
{"from": "Ducati", "to": "Ducati Motorcycles"},
65
{"from": "Lamborghini", "to": "Lamborghini Sports Cars"},
66
{"from": "Lamborghini", "to": "Lamborghini SUVs"},
67
{"from": "MAN", "to": "MAN Trucks"},
68
{"from": "MAN", "to": "MAN Buses"},
69
{"from": "Porsche", "to": "Porsche Sports Cars"},
70
{"from": "Porsche", "to": "Porsche SUVs"},
71
{"from": "Porsche", "to": "Porsche Sedans"},
72
{"from": "Scania", "to": "Scania Trucks"},
73
{"from": "Scania", "to": "Scania Buses"},
74
{"from": "SEAT", "to": "SEAT Cars"},
75
{"from": "SEAT", "to": "SEAT SUVs"},
76
{"from": "SEAT", "to": "SEAT Electric Vehicles"},
77
{"from": "Škoda", "to": "Škoda Cars"},
78
{"from": "Škoda", "to": "Škoda SUVs"},
79
{"from": "Škoda", "to": "Škoda Electric Vehicles"},
80
{"from": "Volkswagen", "to": "Volkswagen Cars"},
81
{"from": "Volkswagen", "to": "Volkswagen SUVs"},
82
{"from": "Volkswagen", "to": "Volkswagen Vans"},
83
{"from": "Volkswagen", "to": "Volkswagen Trucks"}
84
]};
85
86
// initialize the network graph with the provided data structure
87
const chart = anychart.graph(data);
88
89
// Customization step #1:
90
// display chart node labels
91
chart.nodes().labels().enabled(true);
92
93
// Customization step #2:
94
// configure edge tooltips
95
chart.edges().tooltip().format("{%from} owns {%to}");
96
97
// Customization step #3:
98
// customizing node appearance:
99
// 1) configure settings for nodes representing the core company
100
chart.group('CoreCompany')
101
.stroke('none')
102
.height(45)
103
.fill('red')
104
.labels().fontSize(15);
105
// 2) configure settings for nodes representing child companies
106
chart.group('ChildCompany')
107
.stroke('none')
108
.height(25)
109
.labels().fontSize(12);
110
// 3) configure settings for nodes representing products
111
chart.group('Product')
112
.shape('square')
113
.stroke('black', 1)
114
.height(15)
115
.labels().enabled(false);
116
117
// Customization step #4:
118
// set the title of the chart for context
119
chart.title("Volkswagen Group Network");
120
121
// specify the HTML container ID where the chart will be rendered
122
chart.container("container");
123
124
// initiate the rendering of the chart
125
chart.draw();
126
127
});