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/top-1000-companies/data.json
4
anychart.data.loadJsonFile(
5
'https://cdn.anychart.com/samples/tree-map-charts/top-1000-companies/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
// setting the number of levels shown
12
chart
13
.hintDepth(1)
14
// hintOpacity setting
15
.hintOpacity(0.8)
16
// disables selection opportunity
17
.selectionMode('none');
18
19
// sets credits for this sample
20
chart
21
.credits()
22
.enabled(true)
23
.url(
24
'https://opendata.socrata.com/Government/Airplane-Crashes-and-Fatalities-Since-1908/q2te-8cvq'
25
)
26
.text('Data source: https://opendata.socrata.com')
27
.logoSrc(
28
'https://opendata.socrata.com/stylesheets/images/common/favicon.ico'
29
);
30
31
// sets title
32
chart
33
.title()
34
.enabled(true)
35
.useHtml(true)
36
.text(
37
'Top 1000 Companies by Revenue from INC.com<br/>' +
38
'<span style="color: #212121; font-size: 12px">According to opendata.socrata.com</span>'
39
);
40
41
// sets labels settings
42
chart
43
.labels()
44
.enabled(true)
45
.fontSize(14)
46
.textOverflow('')
47
.textShadow({
48
color: 'lightgray',
49
offsetX: '2px',
50
offsetY: '2px',
51
blurRadius: '2px'
52
});
53
54
// sets tooltip settings and formatter
55
var tooltip = chart.tooltip();
56
tooltip.useHtml(true).format(function () {
57
if (this.getData('city')) {
58
return (
59
'<span style="color: #bfbfbf">Revenue: </span>$' +
60
parseInt(this.value).toLocaleString() +
61
'<br/>' +
62
'<span style="color: #bfbfbf">City: </span>' +
63
this.getData('city')
64
);
65
}
66
return (
67
'<span style="color: #bfbfbf">Revenue: </span>$' +
68
parseInt(this.value).toLocaleString()
69
);
70
});
71
72
// set container id for the chart
73
chart.container('container');
74
// initiate chart drawing
75
chart.draw();
76
}
77
);
78
});