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