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/us-population/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 chart settings
12
chart
13
.selectionMode('none')
14
// set colorScale with colors
15
.colorScale(anychart.scales.linearColor('#f1a122', '#a50b01'));
16
17
// sets chart settings
18
chart.selectionMode('none')
19
// set colorScale with colors
20
.colorScale(anychart.scales.linearColor('#f1a122', '#a50b01'));
21
22
// sets credits for this sample
23
chart
24
.credits()
25
.enabled(true)
26
.url(
27
'https://en.wikipedia.org/wiki/List_of_United_States_cities_by_population'
28
)
29
.text(
30
'Data source: https://en.wikipedia.org/wiki/List_of_United_States_cities_by_population'
31
)
32
.logoSrc('https://en.wikipedia.org/static/favicon/wikipedia.ico');
33
34
// sets title for chart and customizes it
35
chart
36
.title()
37
.enabled(true)
38
.useHtml(true)
39
.padding([0, 0, 20, 0])
40
.text(
41
'US population by Biggest Cities<br/>' +
42
'<span style="color:#212121; font-size: 13px;">According to en.wikipedia.org</span>'
43
);
44
45
// sets settings for labels
46
chart
47
.labels()
48
.useHtml(true)
49
.fontColor('#212121')
50
.fontSize(12)
51
.format(function () {
52
return (
53
this.getData('name') +
54
'<br/><span style="font-size: 10px; font-weight: bold">' +
55
parseFloat(this.value).toLocaleString() +
56
'</span> '
57
);
58
});
59
60
// sets settings for tooltips
61
chart.tooltip().format(function () {
62
return parseFloat(this.value).toLocaleString() + ' people';
63
});
64
65
// set container id for the chart
66
chart.container('container');
67
// initiate chart drawing
68
chart.draw();
69
}
70
);
71
});