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
// The data used in this sample can be obtained from the CDN
3
// https://cdn.anychart.com/samples/tree-map-charts/acme-products-by-revenue/data.json
4
anychart.data.loadJsonFile(
5
'https://cdn.anychart.com/samples/tree-map-charts/acme-products-by-revenue/data.json',
6
function (data) {
7
// makes tree from the data for the sample
8
var dataTree = anychart.data.tree(data, 'as-table');
9
var chart = anychart.treeMap(dataTree);
10
11
// sets title for chart and customizes it
12
chart
13
.title()
14
.enabled(true)
15
.useHtml(true)
16
.padding([0, 0, 20, 0])
17
.text(
18
'Top ACME Products by Revenue<br/>' +
19
'<span style="color:#212121; font-size: 13px;">(average sales during the year, in $)</span>'
20
);
21
22
// sets scale
23
var scale = anychart.scales.ordinalColor([
24
{ less: 25000 },
25
{ from: 25000, to: 30000 },
26
{ from: 30000, to: 40000 },
27
{ from: 40000, to: 50000 },
28
{ from: 50000, to: 100000 },
29
{ greater: 100000 }
30
]);
31
32
// sets colors for scale
33
scale.colors([
34
'#ffee58',
35
'#fbc02d',
36
'#f57f17',
37
'#c0ca33',
38
'#689f38',
39
'#2e7d32'
40
]);
41
42
// sets chart settings
43
chart
44
.padding([10, 10, 10, 20])
45
// setting the number of levels shown
46
.maxDepth(2)
47
.selectionMode('none')
48
.colorScale(scale)
49
.hovered({ fill: '#bdbdbd' });
50
51
// sets padding for legend
52
chart
53
.legend()
54
.enabled(true)
55
.padding([0, 0, 0, 20])
56
.position('right')
57
.align('top')
58
.itemsLayout('vertical');
59
60
// sets settings for labels
61
chart
62
.labels()
63
.useHtml(true)
64
.fontColor('#212121')
65
.fontSize(12)
66
.format(function () {
67
return this.getData('product');
68
});
69
70
// sets settings for headers
71
chart.headers().format(function () {
72
return this.getData('product');
73
});
74
75
// sets settings for tooltip
76
chart
77
.tooltip()
78
.useHtml(true)
79
.titleFormat(function () {
80
return this.getData('product');
81
})
82
.format(function () {
83
return (
84
'<span style="color: #bfbfbf">Revenue: </span>$' +
85
anychart.format.number(this.value, { groupsSeparator: ' ' })
86
);
87
});
88
89
// set container id for the chart
90
chart.container('container');
91
// initiate chart drawing
92
chart.draw();
93
}
94
);
95
});