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
var data = getData();
3
4
var chart = anychart.treeMap(data);
5
chart.maxDepth(3);
6
7
// Create color scale.
8
var customColorScale = anychart.scales.ordinalColor();
9
customColorScale.ranges([
10
{less: 500000},
11
{from: 500000, to: 1500000},
12
{greater: 1500000}
13
]);
14
15
// Set color scale.
16
chart.colorScale(customColorScale);
17
18
chart.title('Set color scale using value');
19
chart.container('container');
20
chart.draw();
21
22
});
23
24
function getData() {
25
return [
26
{
27
name: 'Eurasia',
28
children: [
29
{
30
name: 'Asia', children: [
31
{
32
name: 'Eastern Asia', children: [
33
{name: 'Mongolia', value: 1464116, capital: 'Ulan-Bator'},
34
{name: 'China', value: 1364116, capital: 'Beijing'},
35
{name: 'Southern Korea', value: 1564116, capital: 'Seoul'},
36
{name: 'Northern Korea', value: 120540, capital: 'Pyongyang'},
37
{name: 'Japan', value: 1564116, capital: 'Tokio'}
38
]
39
}
40
]
41
},
42
{
43
name: 'Europe', children: [
44
{
45
name: 'Northern Europe', children: [
46
{name: 'Finland', value: 338424, capital: 'Helsinki'},
47
{name: 'Great Britain', value: 209331, capital: 'London'},
48
{name: 'Ireland', value: 84421, capital: 'Dublin'},
49
{name: 'Scandinavia', value: 928057}
50
]
51
}
52
]
53
}
54
]
55
}
56
]
57
}