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
// makes tree from the data for the sample
3
var data = anychart.data.tree(export_data, anychart.enums.TreeFillingMethod.AS_TABLE);
4
var chart = anychart.treeMap(data);
5
6
// sets credits data
7
var credits = chart.credits();
8
credits.enabled(true);
9
credits.url('http://www.worldsrichestcountries.com/top_china_exports.html');
10
credits.text('Data source: http://www.worldsrichestcountries.com/top_china_exports.html');
11
12
// sets title for chart and customizes it
13
chart.title().enabled(true).padding([0, 0, 20, 0]).useHtml(true).text('Top 10 Chinese Export Directions to the World<br/>' +
14
'<span style="color:#212121; font-size: 13px;">According to www.worldsrichestcountries.com</span>');
15
// sets scale
16
var scale = anychart.scales.ordinalColor([
17
{less: 1},
18
{from: 1, to: 2},
19
{from: 2, to: 3},
20
{from: 3, to: 5},
21
{from: 5, to: 15},
22
{from: 15, to: 25},
23
{from: 25, to: 50},
24
{from: 50, to: 100},
25
{greater: 100}
26
]);
27
28
// setting the number of levels shown
29
chart.hintDepth(1);
30
31
// hintOpacity setting
32
chart.hintOpacity(0.5);
33
34
// sets chart settings
35
chart.hoverFill('#bdbdbd');
36
chart.hoverStroke('#212121');
37
chart.selectionMode('none');
38
39
// sets padding for legend
40
chart.legend().padding([0, 0, 20, 0]);
41
42
// sets settings for labels
43
chart.labels().fontColor('#212121').fontSize(16).useHtml(true).textFormatter(function () {
44
return this.getDataValue('direction') + '<br/><span style="color: #455a64">$' + this.value.toFixed(2) + ' billions</span>';
45
});
46
47
// sets settings for headers
48
chart.headers().textFormatter(function () {
49
return this.getDataValue('direction');
50
});
51
52
// sets settings for tooltip
53
chart.tooltip().title().useHtml(true);
54
chart.tooltip().useHtml(true).textFormatter(function () {
55
var value = this.value.toFixed(2);
56
if (this.getDataValue('percent'))
57
return '<span style="color: #bfbfbf">Revenue: </span>$' + value + ' billions<br/>' +
58
'<span style="color: #bfbfbf">Percent: ' + '</span>' + this.getDataValue('percent') + '%';
59
return '<span style="color: #bfbfbf">Revenue: </span>$' + value + ' billions';
60
});
61
62
// turns on legend on drill down (for all children nodes)
63
chart.listen(anychart.enums.EventType.DRILL_CHANGE, function (e) {
64
if (e.path.length != 1) chart.labels().fontSize(12);
65
else chart.labels().fontSize(16);
66
chart.legend(e.path.length != 1);
67
});
68
69
// sets colors for scale
70
scale.colors(['#e1f5fe', '#b3e5fc', '#81d4fa', '#4fc3f7', '#29b6f6', '#039be5', '#26c6da', '#00b8d4', '#00acc1']);
71
chart.colorScale(scale);
72
73
// set container id for the chart
74
chart.container('container');
75
76
// initiate chart drawing
77
chart.draw();
78
});