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
3
// create data
4
var data = [
5
{name: "European Union", children: [
6
{name: "Belgium", value: 11443830},
7
{name: "France", value: 64938716},
8
{name: "Germany", value: 80636124},
9
{name: "Greece", value: 10892931},
10
{name: "Italy", value: 59797978},
11
{name: "Netherlands", value: 17032845},
12
{name: "Poland", value: 38563573},
13
{name: "Romania", value: 19237513},
14
{name: "Spain", value: 46070146},
15
{name: "United Kingdom", value: 65511098}
16
]}
17
];
18
19
// create a chart and set the data
20
var chart = anychart.treeMap(data, "as-tree");
21
22
// create and configure a color scale.
23
var customColorScale = anychart.scales.ordinalColor();
24
customColorScale.ranges([
25
{less: 20000000},
26
{from: 20000000, to: 50000000},
27
{from: 50000000, to: 70000000},
28
{greater: 70000000}
29
]);
30
customColorScale.colors(["lightgray", "#9ed1de", "#00ccff", "#ffcc00"]);
31
32
// set the color scale as the color scale of the chart
33
chart.colorScale(customColorScale);
34
35
// add a color range
36
chart.colorRange().enabled(true);
37
chart.colorRange().length("90%");
38
39
// set the chart title
40
chart.title().useHtml(true);
41
chart.title("Treemap: Color Scale (Ordinal)<br><br>" +
42
"<span style='font-size:12; font-style:italic'>" +
43
"Top 10 European Union Countries by Population</span>");
44
45
// set the container id
46
chart.container("container");
47
48
// initiate drawing the chart
49
chart.draw();
50
});