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/starbucks-by-country/data.json
4
anychart.data.loadJsonFile(
5
'https://cdn.anychart.com/samples/tree-map-charts/starbucks-by-country/data.json',
6
function (data) {
7
// define themes settings for font
8
var customTheme = {
9
defaultFontSettings: {
10
fontFamily: '"Source Sans Pro", sans-serif',
11
fontSize: 13
12
}
13
};
14
15
anychart.theme(customTheme);
16
17
// makes tree from the data for the sample
18
var dataTree = anychart.data.tree(data, 'as-table');
19
var chart = anychart.treeMap(dataTree);
20
21
// sets scale
22
var scale = anychart.scales.ordinalColor([
23
{ less: 10 },
24
{ from: 10, to: 100 },
25
{ from: 100, to: 500 },
26
{ from: 500, to: 1000 },
27
{ greater: 1000 }
28
]);
29
30
// sets colors for scale
31
scale.colors([
32
'#d8b597',
33
'#CFA185',
34
'#C3866C',
35
'#AD5841',
36
'#9b301c'
37
]);
38
39
// sets chart settings
40
chart.selectionMode('none').colorScale(scale);
41
42
chart.hovered().fill('#fcece2').stroke('#a1887f');
43
44
// sets credits for this sample
45
chart
46
.credits()
47
.enabled(true)
48
.url(
49
'https://opendata.socrata.com/Business/All-Starbucks-Locations-in-the-World/xy4y-c4mk'
50
)
51
.text('Data source: https://opendata.socrata.com')
52
.logoSrc(
53
'https://opendata.socrata.com/stylesheets/images/common/favicon.ico'
54
);
55
56
// sets title
57
chart
58
.title()
59
.enabled(true)
60
.useHtml(true)
61
.fontSize(18)
62
.text(
63
'Starbucks Distribution by Country<br/>' +
64
'<span style="color: #212121; font-size: 14px">' +
65
'According to opendata.socrata.com</span>'
66
);
67
68
// turns legend on
69
chart.legend().enabled(true).padding([0, 0, 20, 0]);
70
71
// sets labels settings
72
chart.labels().enabled(true).fontSize(16).textOverflow('');
73
74
// sets tooltip settings and formatter
75
var tooltip = chart.tooltip();
76
tooltip
77
.title()
78
.padding({ bottom: 8 })
79
.fontSize(16)
80
.fontColor('#5d4037');
81
tooltip
82
.background()
83
.fill('#d7ccc8 0.9')
84
.stroke('3 #bcaaa4')
85
.corners(7);
86
tooltip
87
.useHtml(true)
88
.padding([10, 20])
89
.separator(false)
90
.fontColor('#3e2723')
91
.format(function () {
92
return (
93
'<span style="color: #3e2723">Number of Starbucks: </span>' +
94
parseInt(this.value).toLocaleString()
95
);
96
});
97
98
// set container id for the chart
99
chart.container('container');
100
// initiate chart drawing
101
chart.draw();
102
}
103
);
104
});