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
{name: "World", children: [
6
{name: "Asia", children: [
7
{name: "East", value: 1000},
8
{name: "Southern", value: 803},
9
{name: "Southeast", value: 415},
10
{name: "Western", value: 182},
11
{name: "Central", value: 36}
12
]},
13
{name: "America", children: [
14
{name: "North", value: 346},
15
{name: "South", value: 316},
16
{name: "Central", value: 114},
17
{name: "Caribbean", value: 23}
18
]},
19
{name: "Europe", children: [
20
{name: "Eastern", value: 233},
21
{name: "Western", value: 183},
22
{name: "Southern", value: 135},
23
{name: "Northern", value: 100}
24
]},
25
{name: "Africa", children: [
26
{name: "Western", value: 158},
27
{name: "Eastern", value: 140},
28
{name: "Northern", value: 121},
29
{name: "Southern", value: 34},
30
{name: "Middle", value: 20}
31
]},
32
{name: "Oceania", children: [
33
{name: "Oceania", value: 29}
34
]}
35
]}
36
];
37
38
// create a data tree
39
var treeData = anychart.data.tree(data, "as-tree");
40
41
// create a treemap chart visualizing the data tree
42
var chart = anychart.treeMap(treeData);
43
44
// set the depth of hints
45
chart.hintDepth(1);
46
// set the opacity of hints
47
chart.hintOpacity(0.7);
48
49
// configure the visual settings of the chart
50
chart.hovered().fill("silver", 0.2);
51
chart.selected().fill("silver", 0.6);
52
chart.selected().hatchFill("backward-diagonal", "silver", 2, 20);
53
chart.normal().stroke("silver");
54
chart.hovered().stroke("gray", 2);
55
chart.selected().stroke("gray", 2);
56
57
// create and configure a custom color scale
58
var customColorScale = anychart.scales.linearColor();
59
customColorScale.colors(["Yellow", "MediumPurple"]);
60
// apply the custom color scale to the treemap chart
61
chart.colorScale(customColorScale);
62
// add the color range
63
chart.colorRange().enabled(true);
64
chart.colorRange().length("100%");
65
66
// enable HTML in the chart title
67
chart.title().useHtml(true);
68
// configure the chart title
69
chart.title(
70
"<span style='font-size:18; font-style:bold'>Internet Audience Worldwide</span><br><i><span style='font-size:14; font-style:italic'>In million users</i>"
71
);
72
73
// enable HTML in the chart tooltips
74
chart.tooltip().useHtml(true);
75
// configure the chart tooltips
76
chart.tooltip().format(
77
"Internet audience: {%value} million users<br><i>(As of January 2019.)</i>"
78
);
79
80
// enable HTML in the chart labels
81
chart.labels().useHtml(true);
82
// configure the chart labels
83
chart.labels().format(
84
"<span style='font-weight:bold'>{%name}</span><br>{%value}"
85
);
86
87
// set the container id
88
chart.container("container");
89
90
// draw the chart
91
chart.draw();
92
93
});