@amcharts/amcharts5-mcp 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitmodules +3 -0
- package/README.md +82 -0
- package/amcharts5-skill/README.md +50 -0
- package/amcharts5-skill/amcharts5-skill/SKILL.md +667 -0
- package/amcharts5-skill/amcharts5-skill/references/flow.md +523 -0
- package/amcharts5-skill/amcharts5-skill/references/gantt.md +410 -0
- package/amcharts5-skill/amcharts5-skill/references/hierarchy.md +568 -0
- package/amcharts5-skill/amcharts5-skill/references/map.md +574 -0
- package/amcharts5-skill/amcharts5-skill/references/pie.md +663 -0
- package/amcharts5-skill/amcharts5-skill/references/radar.md +584 -0
- package/amcharts5-skill/amcharts5-skill/references/stock.md +664 -0
- package/amcharts5-skill/amcharts5-skill/references/timeline.md +449 -0
- package/amcharts5-skill/amcharts5-skill/references/ui-elements.md +393 -0
- package/amcharts5-skill/amcharts5-skill/references/venn.md +368 -0
- package/amcharts5-skill/amcharts5-skill/references/wordcloud.md +339 -0
- package/amcharts5-skill/amcharts5-skill/references/xy.md +1150 -0
- package/amcharts5-skill/cursorrules +820 -0
- package/package.json +27 -0
- package/src/index.js +329 -0
- package/test.js +153 -0
|
@@ -0,0 +1,568 @@
|
|
|
1
|
+
# Hierarchy Charts — Treemap, Sunburst, Force-Directed
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
## Required imports
|
|
5
|
+
|
|
6
|
+
### ES modules
|
|
7
|
+
```ts
|
|
8
|
+
import * as am5 from "@amcharts/amcharts5";
|
|
9
|
+
import * as am5hierarchy from "@amcharts/amcharts5/hierarchy";
|
|
10
|
+
import am5themes_Animated from "@amcharts/amcharts5/themes/Animated";
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### CDN
|
|
14
|
+
```html
|
|
15
|
+
<script src="https://cdn.amcharts.com/lib/5/index.js"></script>
|
|
16
|
+
<script src="https://cdn.amcharts.com/lib/5/hierarchy.js"></script>
|
|
17
|
+
<script src="https://cdn.amcharts.com/lib/5/themes/Animated.js"></script>
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Data structure (shared by all hierarchy types)
|
|
21
|
+
|
|
22
|
+
```js
|
|
23
|
+
var data = [{
|
|
24
|
+
name: "Root",
|
|
25
|
+
children: [{
|
|
26
|
+
name: "Category A",
|
|
27
|
+
children: [
|
|
28
|
+
{ name: "Item A1", value: 100 },
|
|
29
|
+
{ name: "Item A2", value: 80 }
|
|
30
|
+
]
|
|
31
|
+
}, {
|
|
32
|
+
name: "Category B",
|
|
33
|
+
children: [
|
|
34
|
+
{ name: "Item B1", value: 60 },
|
|
35
|
+
{ name: "Item B2", value: 40 }
|
|
36
|
+
]
|
|
37
|
+
}]
|
|
38
|
+
}];
|
|
39
|
+
|
|
40
|
+
// Set on series:
|
|
41
|
+
series.data.setAll(data);
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Series types
|
|
45
|
+
|
|
46
|
+
| Class | Use for | Module |
|
|
47
|
+
|-------|---------|--------|
|
|
48
|
+
| `am5hierarchy.Treemap` | Nested rectangles showing proportions | hierarchy |
|
|
49
|
+
| `am5hierarchy.ForceDirected` | Force-directed bubble/node graph | hierarchy |
|
|
50
|
+
| `am5hierarchy.Sunburst` | Concentric ring chart (hierarchical pie) | hierarchy |
|
|
51
|
+
| `am5hierarchy.Pack` | Packed circles (bubble chart) | hierarchy |
|
|
52
|
+
| `am5hierarchy.Partition` | Rectangular partition layout | hierarchy |
|
|
53
|
+
| `am5hierarchy.Tree` | Traditional tree layout (org charts) | hierarchy |
|
|
54
|
+
| `am5hierarchy.VoronoiTreemap` | Voronoi-based treemap | hierarchy |
|
|
55
|
+
|
|
56
|
+
## Treemap
|
|
57
|
+
|
|
58
|
+
```js
|
|
59
|
+
const root = am5.Root.new("chartdiv");
|
|
60
|
+
root.setThemes([am5themes_Animated.new(root)]);
|
|
61
|
+
|
|
62
|
+
const container = root.container.children.push(am5.Container.new(root, {
|
|
63
|
+
width: am5.percent(100),
|
|
64
|
+
height: am5.percent(100),
|
|
65
|
+
layout: root.verticalLayout
|
|
66
|
+
}));
|
|
67
|
+
|
|
68
|
+
const series = container.children.push(am5hierarchy.Treemap.new(root, {
|
|
69
|
+
valueField: "value",
|
|
70
|
+
categoryField: "name",
|
|
71
|
+
childDataField: "children",
|
|
72
|
+
initialDepth: 2, // how many levels visible initially
|
|
73
|
+
topDepth: 1, // hide root node (start from first children)
|
|
74
|
+
layoutAlgorithm: "squarify", // "squarify" | "binary" | "slice" | "dice" | "sliceDice"
|
|
75
|
+
nodePaddingOuter: 4,
|
|
76
|
+
nodePaddingInner: 4
|
|
77
|
+
}));
|
|
78
|
+
|
|
79
|
+
// Configure rectangle appearance
|
|
80
|
+
series.rectangles.template.setAll({
|
|
81
|
+
strokeWidth: 2,
|
|
82
|
+
stroke: am5.color(0xffffff),
|
|
83
|
+
cornerRadiusTL: 4,
|
|
84
|
+
cornerRadiusTR: 4,
|
|
85
|
+
cornerRadiusBL: 4,
|
|
86
|
+
cornerRadiusBR: 4
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
// Tooltip
|
|
90
|
+
series.nodes.template.set("tooltipText", "{category}: [bold]{sum}[/]");
|
|
91
|
+
|
|
92
|
+
// Labels
|
|
93
|
+
series.labels.template.setAll({
|
|
94
|
+
text: "{category}",
|
|
95
|
+
fontSize: 14
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
series.data.setAll(data);
|
|
99
|
+
series.appear(1000);
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Force-Directed Tree
|
|
103
|
+
|
|
104
|
+
```js
|
|
105
|
+
const series = container.children.push(am5hierarchy.ForceDirected.new(root, {
|
|
106
|
+
valueField: "value",
|
|
107
|
+
categoryField: "name",
|
|
108
|
+
childDataField: "children",
|
|
109
|
+
idField: "name", // for cross-linking
|
|
110
|
+
linkWithField: "linkWith", // optional: cross-link nodes
|
|
111
|
+
minRadius: 20,
|
|
112
|
+
maxRadius: 80,
|
|
113
|
+
initialFrames: 200, // frames of physics simulation
|
|
114
|
+
centerStrength: 0.5,
|
|
115
|
+
manyBodyStrength: -15,
|
|
116
|
+
topDepth: 1
|
|
117
|
+
}));
|
|
118
|
+
|
|
119
|
+
// Circle appearance
|
|
120
|
+
series.circles.template.setAll({
|
|
121
|
+
fillOpacity: 0.8,
|
|
122
|
+
strokeWidth: 2,
|
|
123
|
+
stroke: am5.color(0xffffff)
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
// Labels
|
|
127
|
+
series.labels.template.setAll({
|
|
128
|
+
text: "{category}",
|
|
129
|
+
fill: am5.color(0xffffff),
|
|
130
|
+
fontSize: 12
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
// Links between nodes
|
|
134
|
+
series.links.template.setAll({
|
|
135
|
+
strokeWidth: 1,
|
|
136
|
+
strokeOpacity: 0.5
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
// Outer circles (parent nodes indicator)
|
|
140
|
+
series.outerCircles.template.setAll({
|
|
141
|
+
strokeWidth: 2,
|
|
142
|
+
strokeDasharray: [4, 4]
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
series.data.setAll(data);
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## Sunburst
|
|
149
|
+
|
|
150
|
+
```js
|
|
151
|
+
const series = container.children.push(am5hierarchy.Sunburst.new(root, {
|
|
152
|
+
valueField: "value",
|
|
153
|
+
categoryField: "name",
|
|
154
|
+
childDataField: "children",
|
|
155
|
+
radius: am5.percent(95),
|
|
156
|
+
innerRadius: am5.percent(20), // hole in center
|
|
157
|
+
// startAngle: -90, // default: -90
|
|
158
|
+
// endAngle: 270 // default: 270 (full circle)
|
|
159
|
+
}));
|
|
160
|
+
|
|
161
|
+
series.nodes.template.set("tooltipText", "{category}: [bold]{sum}[/]");
|
|
162
|
+
series.labels.template.set("forceHidden", true); // hide labels if crowded
|
|
163
|
+
|
|
164
|
+
series.data.setAll(data);
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## Pack (Packed Circles)
|
|
168
|
+
|
|
169
|
+
```js
|
|
170
|
+
const series = container.children.push(am5hierarchy.Pack.new(root, {
|
|
171
|
+
valueField: "value",
|
|
172
|
+
categoryField: "name",
|
|
173
|
+
childDataField: "children",
|
|
174
|
+
nodePadding: 5
|
|
175
|
+
}));
|
|
176
|
+
|
|
177
|
+
series.circles.template.setAll({
|
|
178
|
+
fillOpacity: 0.7,
|
|
179
|
+
strokeWidth: 2,
|
|
180
|
+
stroke: am5.color(0xffffff)
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
series.data.setAll(data);
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
## Tree
|
|
187
|
+
|
|
188
|
+
```js
|
|
189
|
+
const series = container.children.push(am5hierarchy.Tree.new(root, {
|
|
190
|
+
valueField: "value",
|
|
191
|
+
categoryField: "name",
|
|
192
|
+
childDataField: "children",
|
|
193
|
+
orientation: "horizontal", // "horizontal" | "vertical"
|
|
194
|
+
topDepth: 0
|
|
195
|
+
}));
|
|
196
|
+
|
|
197
|
+
series.circles.template.setAll({
|
|
198
|
+
radius: 15,
|
|
199
|
+
fillOpacity: 0.9
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
series.links.template.setAll({
|
|
203
|
+
strokeWidth: 2,
|
|
204
|
+
strokeOpacity: 0.5
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
series.labels.template.setAll({
|
|
208
|
+
text: "{category}",
|
|
209
|
+
fontSize: 12
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
series.data.setAll(data);
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
## Partition
|
|
216
|
+
|
|
217
|
+
```js
|
|
218
|
+
const series = container.children.push(am5hierarchy.Partition.new(root, {
|
|
219
|
+
valueField: "value",
|
|
220
|
+
categoryField: "name",
|
|
221
|
+
childDataField: "children",
|
|
222
|
+
orientation: "horizontal", // "horizontal" | "vertical"
|
|
223
|
+
initialDepth: 3
|
|
224
|
+
}));
|
|
225
|
+
|
|
226
|
+
series.rectangles.template.setAll({
|
|
227
|
+
strokeWidth: 1,
|
|
228
|
+
stroke: am5.color(0xffffff)
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
series.data.setAll(data);
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
## VoronoiTreemap
|
|
235
|
+
|
|
236
|
+
**Note:** VoronoiTreemap has NO `.rectangles` property. Unlike `Treemap` (which has `series.rectangles.template`), VoronoiTreemap renders organic polygon cells. Style via `series.nodes.template` and its children.
|
|
237
|
+
|
|
238
|
+
```js
|
|
239
|
+
const series = container.children.push(am5hierarchy.VoronoiTreemap.new(root, {
|
|
240
|
+
valueField: "value",
|
|
241
|
+
categoryField: "name",
|
|
242
|
+
childDataField: "children",
|
|
243
|
+
initialDepth: 2,
|
|
244
|
+
topDepth: 1
|
|
245
|
+
}));
|
|
246
|
+
|
|
247
|
+
series.data.setAll(data);
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
## Flat data with parentField (database-friendly)
|
|
251
|
+
|
|
252
|
+
Instead of nested `children` arrays, use flat data with `id` and `parentId` fields:
|
|
253
|
+
|
|
254
|
+
```js
|
|
255
|
+
const series = container.children.push(am5hierarchy.Treemap.new(root, {
|
|
256
|
+
valueField: "value",
|
|
257
|
+
categoryField: "name",
|
|
258
|
+
childDataField: "children", // still required
|
|
259
|
+
parentIdField: "parentId", // enables flat data
|
|
260
|
+
idField: "id"
|
|
261
|
+
}));
|
|
262
|
+
|
|
263
|
+
// Flat data (e.g., from a database query)
|
|
264
|
+
series.data.setAll([
|
|
265
|
+
{ id: "root", name: "Root", children: [] },
|
|
266
|
+
{ id: "a", name: "Group A", parentId: "root", children: [] },
|
|
267
|
+
{ id: "b", name: "Group B", parentId: "root", children: [] },
|
|
268
|
+
{ id: "a1", name: "Item A1", parentId: "a", value: 100 },
|
|
269
|
+
{ id: "a2", name: "Item A2", parentId: "a", value: 60 },
|
|
270
|
+
{ id: "b1", name: "Item B1", parentId: "b", value: 80 }
|
|
271
|
+
]);
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
## Common configuration
|
|
275
|
+
|
|
276
|
+
### Node colors
|
|
277
|
+
```js
|
|
278
|
+
// From color set (automatic)
|
|
279
|
+
series.get("colors").set("colors", [
|
|
280
|
+
am5.color(0x095256), am5.color(0x087f8c),
|
|
281
|
+
am5.color(0x5aaa95), am5.color(0x86a873)
|
|
282
|
+
]);
|
|
283
|
+
|
|
284
|
+
// Per-node via data + templateField
|
|
285
|
+
// { name: "A", value: 100, nodeSettings: { fill: am5.color(0xff0000) } }
|
|
286
|
+
// series.nodes.template.set("templateField", "nodeSettings");
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
### Drill-down (built-in for Treemap, Sunburst)
|
|
290
|
+
Clicking a node zooms into its children. Configure with:
|
|
291
|
+
```js
|
|
292
|
+
series.set("topDepth", 1); // hide root
|
|
293
|
+
series.set("initialDepth", 2); // initial visible depth
|
|
294
|
+
series.set("downDepth", 1); // how many levels to reveal on drill-down
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
### Breadcrumbs (for navigation)
|
|
298
|
+
|
|
299
|
+
amCharts 5 provides a built-in `BreadcrumbBar` component for hierarchy navigation:
|
|
300
|
+
|
|
301
|
+
```js
|
|
302
|
+
const breadcrumbs = container.children.push(am5hierarchy.BreadcrumbBar.new(root, {
|
|
303
|
+
series: series
|
|
304
|
+
}));
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
### Events on hierarchy nodes
|
|
308
|
+
|
|
309
|
+
```js
|
|
310
|
+
// Node click
|
|
311
|
+
series.nodes.template.events.on("click", function(ev) {
|
|
312
|
+
var data = ev.target.dataItem.dataContext;
|
|
313
|
+
console.log("Clicked:", data.name);
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
// Data validated (after render)
|
|
317
|
+
series.events.on("datavalidated", function() {
|
|
318
|
+
console.log("Hierarchy rendered");
|
|
319
|
+
});
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
## Disposal
|
|
323
|
+
|
|
324
|
+
```js
|
|
325
|
+
root.dispose();
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
---
|
|
330
|
+
|
|
331
|
+
# amCharts 5 Hierarchy Charts — Working Examples
|
|
332
|
+
|
|
333
|
+
## Example 1: Treemap
|
|
334
|
+
|
|
335
|
+
```html
|
|
336
|
+
<!DOCTYPE html>
|
|
337
|
+
<html>
|
|
338
|
+
<head>
|
|
339
|
+
<meta charset="UTF-8">
|
|
340
|
+
<title>Treemap</title>
|
|
341
|
+
<script src="https://cdn.amcharts.com/lib/5/index.js"></script>
|
|
342
|
+
<script src="https://cdn.amcharts.com/lib/5/hierarchy.js"></script>
|
|
343
|
+
<script src="https://cdn.amcharts.com/lib/5/themes/Animated.js"></script>
|
|
344
|
+
<style>#chartdiv { width: 100%; height: 500px; }</style>
|
|
345
|
+
</head>
|
|
346
|
+
<body>
|
|
347
|
+
<div id="chartdiv"></div>
|
|
348
|
+
<script>
|
|
349
|
+
var root = am5.Root.new("chartdiv");
|
|
350
|
+
root.setThemes([am5themes_Animated.new(root)]);
|
|
351
|
+
|
|
352
|
+
var container = root.container.children.push(am5.Container.new(root, {
|
|
353
|
+
width: am5.percent(100),
|
|
354
|
+
height: am5.percent(100),
|
|
355
|
+
layout: root.verticalLayout
|
|
356
|
+
}));
|
|
357
|
+
|
|
358
|
+
var series = container.children.push(am5hierarchy.Treemap.new(root, {
|
|
359
|
+
valueField: "value",
|
|
360
|
+
categoryField: "name",
|
|
361
|
+
childDataField: "children",
|
|
362
|
+
initialDepth: 2,
|
|
363
|
+
topDepth: 1,
|
|
364
|
+
layoutAlgorithm: "squarify",
|
|
365
|
+
nodePaddingOuter: 4,
|
|
366
|
+
nodePaddingInner: 2
|
|
367
|
+
}));
|
|
368
|
+
|
|
369
|
+
series.rectangles.template.setAll({
|
|
370
|
+
strokeWidth: 2,
|
|
371
|
+
stroke: am5.color(0xffffff),
|
|
372
|
+
cornerRadiusTL: 3, cornerRadiusTR: 3,
|
|
373
|
+
cornerRadiusBL: 3, cornerRadiusBR: 3
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
series.nodes.template.set("tooltipText", "{category}: {sum}");
|
|
377
|
+
series.labels.template.setAll({ text: "{category}", fontSize: 13 });
|
|
378
|
+
|
|
379
|
+
series.data.setAll([{
|
|
380
|
+
name: "Root",
|
|
381
|
+
children: [{
|
|
382
|
+
name: "Technology",
|
|
383
|
+
children: [
|
|
384
|
+
{ name: "Smartphones", value: 500 },
|
|
385
|
+
{ name: "Laptops", value: 380 },
|
|
386
|
+
{ name: "Tablets", value: 220 },
|
|
387
|
+
{ name: "Wearables", value: 150 }
|
|
388
|
+
]
|
|
389
|
+
}, {
|
|
390
|
+
name: "Media",
|
|
391
|
+
children: [
|
|
392
|
+
{ name: "Streaming", value: 350 },
|
|
393
|
+
{ name: "Gaming", value: 280 },
|
|
394
|
+
{ name: "Music", value: 180 },
|
|
395
|
+
{ name: "News", value: 90 }
|
|
396
|
+
]
|
|
397
|
+
}, {
|
|
398
|
+
name: "Finance",
|
|
399
|
+
children: [
|
|
400
|
+
{ name: "Banking", value: 300 },
|
|
401
|
+
{ name: "Insurance", value: 200 },
|
|
402
|
+
{ name: "Investing", value: 250 }
|
|
403
|
+
]
|
|
404
|
+
}]
|
|
405
|
+
}]);
|
|
406
|
+
|
|
407
|
+
series.appear(1000);
|
|
408
|
+
</script>
|
|
409
|
+
</body>
|
|
410
|
+
</html>
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
## Example 2: Force-directed tree
|
|
414
|
+
|
|
415
|
+
```html
|
|
416
|
+
<!DOCTYPE html>
|
|
417
|
+
<html>
|
|
418
|
+
<head>
|
|
419
|
+
<meta charset="UTF-8">
|
|
420
|
+
<title>Force-Directed Tree</title>
|
|
421
|
+
<script src="https://cdn.amcharts.com/lib/5/index.js"></script>
|
|
422
|
+
<script src="https://cdn.amcharts.com/lib/5/hierarchy.js"></script>
|
|
423
|
+
<script src="https://cdn.amcharts.com/lib/5/themes/Animated.js"></script>
|
|
424
|
+
<style>#chartdiv { width: 100%; height: 600px; }</style>
|
|
425
|
+
</head>
|
|
426
|
+
<body>
|
|
427
|
+
<div id="chartdiv"></div>
|
|
428
|
+
<script>
|
|
429
|
+
var root = am5.Root.new("chartdiv");
|
|
430
|
+
root.setThemes([am5themes_Animated.new(root)]);
|
|
431
|
+
|
|
432
|
+
var container = root.container.children.push(am5.Container.new(root, {
|
|
433
|
+
width: am5.percent(100),
|
|
434
|
+
height: am5.percent(100),
|
|
435
|
+
layout: root.verticalLayout
|
|
436
|
+
}));
|
|
437
|
+
|
|
438
|
+
var series = container.children.push(am5hierarchy.ForceDirected.new(root, {
|
|
439
|
+
valueField: "value",
|
|
440
|
+
categoryField: "name",
|
|
441
|
+
childDataField: "children",
|
|
442
|
+
minRadius: 15,
|
|
443
|
+
maxRadius: 60,
|
|
444
|
+
initialFrames: 200,
|
|
445
|
+
topDepth: 1,
|
|
446
|
+
centerStrength: 0.3,
|
|
447
|
+
manyBodyStrength: -10
|
|
448
|
+
}));
|
|
449
|
+
|
|
450
|
+
series.circles.template.setAll({
|
|
451
|
+
fillOpacity: 0.85,
|
|
452
|
+
strokeWidth: 2,
|
|
453
|
+
stroke: am5.color(0xffffff)
|
|
454
|
+
});
|
|
455
|
+
|
|
456
|
+
series.labels.template.setAll({
|
|
457
|
+
text: "{category}",
|
|
458
|
+
fill: am5.color(0xffffff),
|
|
459
|
+
fontSize: 11,
|
|
460
|
+
oversizedBehavior: "truncate",
|
|
461
|
+
maxWidth: 80
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
series.outerCircles.template.setAll({
|
|
465
|
+
strokeDasharray: [3, 3],
|
|
466
|
+
strokeOpacity: 0.3
|
|
467
|
+
});
|
|
468
|
+
|
|
469
|
+
series.nodes.template.set("tooltipText", "{category}: {value}");
|
|
470
|
+
|
|
471
|
+
series.data.setAll([{
|
|
472
|
+
name: "Team", value: 0,
|
|
473
|
+
children: [{
|
|
474
|
+
name: "Engineering", value: 0,
|
|
475
|
+
children: [
|
|
476
|
+
{ name: "Frontend", value: 8 },
|
|
477
|
+
{ name: "Backend", value: 12 },
|
|
478
|
+
{ name: "DevOps", value: 5 },
|
|
479
|
+
{ name: "QA", value: 4 }
|
|
480
|
+
]
|
|
481
|
+
}, {
|
|
482
|
+
name: "Product", value: 0,
|
|
483
|
+
children: [
|
|
484
|
+
{ name: "Design", value: 6 },
|
|
485
|
+
{ name: "Research", value: 3 },
|
|
486
|
+
{ name: "PM", value: 4 }
|
|
487
|
+
]
|
|
488
|
+
}, {
|
|
489
|
+
name: "Business", value: 0,
|
|
490
|
+
children: [
|
|
491
|
+
{ name: "Sales", value: 10 },
|
|
492
|
+
{ name: "Marketing", value: 7 },
|
|
493
|
+
{ name: "Support", value: 8 }
|
|
494
|
+
]
|
|
495
|
+
}]
|
|
496
|
+
}]);
|
|
497
|
+
|
|
498
|
+
series.appear(1000);
|
|
499
|
+
</script>
|
|
500
|
+
</body>
|
|
501
|
+
</html>
|
|
502
|
+
```
|
|
503
|
+
|
|
504
|
+
## Example 3: Sunburst chart
|
|
505
|
+
|
|
506
|
+
```html
|
|
507
|
+
<!DOCTYPE html>
|
|
508
|
+
<html>
|
|
509
|
+
<head>
|
|
510
|
+
<meta charset="UTF-8">
|
|
511
|
+
<title>Sunburst</title>
|
|
512
|
+
<script src="https://cdn.amcharts.com/lib/5/index.js"></script>
|
|
513
|
+
<script src="https://cdn.amcharts.com/lib/5/hierarchy.js"></script>
|
|
514
|
+
<script src="https://cdn.amcharts.com/lib/5/themes/Animated.js"></script>
|
|
515
|
+
<style>#chartdiv { width: 100%; height: 600px; }</style>
|
|
516
|
+
</head>
|
|
517
|
+
<body>
|
|
518
|
+
<div id="chartdiv"></div>
|
|
519
|
+
<script>
|
|
520
|
+
var root = am5.Root.new("chartdiv");
|
|
521
|
+
root.setThemes([am5themes_Animated.new(root)]);
|
|
522
|
+
|
|
523
|
+
var container = root.container.children.push(am5.Container.new(root, {
|
|
524
|
+
width: am5.percent(100),
|
|
525
|
+
height: am5.percent(100)
|
|
526
|
+
}));
|
|
527
|
+
|
|
528
|
+
var series = container.children.push(am5hierarchy.Sunburst.new(root, {
|
|
529
|
+
valueField: "value",
|
|
530
|
+
categoryField: "name",
|
|
531
|
+
childDataField: "children",
|
|
532
|
+
radius: am5.percent(95),
|
|
533
|
+
innerRadius: am5.percent(15)
|
|
534
|
+
}));
|
|
535
|
+
|
|
536
|
+
series.nodes.template.set("tooltipText", "{category}: {sum}");
|
|
537
|
+
series.labels.template.set("forceHidden", true);
|
|
538
|
+
|
|
539
|
+
series.data.setAll([{
|
|
540
|
+
name: "Revenue",
|
|
541
|
+
children: [{
|
|
542
|
+
name: "Products",
|
|
543
|
+
children: [
|
|
544
|
+
{ name: "SaaS", value: 450 },
|
|
545
|
+
{ name: "On-Premise", value: 120 },
|
|
546
|
+
{ name: "Mobile", value: 200 }
|
|
547
|
+
]
|
|
548
|
+
}, {
|
|
549
|
+
name: "Services",
|
|
550
|
+
children: [
|
|
551
|
+
{ name: "Consulting", value: 180 },
|
|
552
|
+
{ name: "Training", value: 80 },
|
|
553
|
+
{ name: "Support", value: 160 }
|
|
554
|
+
]
|
|
555
|
+
}, {
|
|
556
|
+
name: "Licensing",
|
|
557
|
+
children: [
|
|
558
|
+
{ name: "Enterprise", value: 300 },
|
|
559
|
+
{ name: "SMB", value: 150 }
|
|
560
|
+
]
|
|
561
|
+
}]
|
|
562
|
+
}]);
|
|
563
|
+
|
|
564
|
+
series.appear(1000);
|
|
565
|
+
</script>
|
|
566
|
+
</body>
|
|
567
|
+
</html>
|
|
568
|
+
```
|