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(products_data, "as-table");
4
var chart = anychart.treeMap(data);
5
6
// sets title for chart and customizes it
7
chart.title().enabled(false);
8
9
// sets scale
10
var scale = anychart.scales.ordinalColor([
11
{less: 25000},
12
{from: 25000, to: 30000},
13
{from: 30000, to: 40000},
14
{from: 40000, to: 50000},
15
{from: 50000, to: 100000},
16
{greater: 100000}
17
]);
18
19
// setting the number of levels shown
20
chart.maxDepth(2);
21
22
// sets chart settings
23
chart.padding([10, 10, 10, 20]);
24
chart.hovered().fill('#bdbdbd');
25
chart.selectionMode('none');
26
27
// sets padding for legend
28
chart.legend().enabled(true).padding([0, 0, 0, 20]).position('right').align('top').itemsLayout('vertical');
29
30
// sets settings for labels
31
chart.labels().fontColor('#212121').fontSize(12).useHtml(true).format(function () {
32
return this.getData('product');
33
});
34
35
// sets settings for headers
36
chart.headers().format(function () {
37
return this.getData('product');
38
});
39
40
// sets settings for tooltip
41
chart.tooltip().titleFormat(function () {
42
return this.getData('product');
43
});
44
45
chart.tooltip().useHtml(true).format(function () {
46
return '<span style="color: #bfbfbf">Revenue: </span>$' + parseInt(this.value).toLocaleString();
47
});
48
49
// sets colors for scale
50
scale.colors(['#ffee58', '#fbc02d', '#f57f17', '#c0ca33', '#689f38', '#2e7d32']);
51
chart.colorScale(scale);
52
53
// set container id for the chart
54
chart.container('container');
55
56
// initiate chart drawing
57
chart.draw();
58
});
59
60
var products_data = [
61
{id: "00", product: 'Products by Revenue', parent: null},
62
{parent: "00", id: "01", product: 'Fruits', value: 692000},
63
{parent: "00", id: "02", product: 'Vegetables', value: 597000},
64
{parent: "00", id: "03", product: 'Dairy', value: 1359000},
65
{parent: "00", id: "04", product: 'Meat', value: 596000},
66
67
{parent: "01", id: "11", product: "Apples", value: 138000},
68
{parent: "01", id: "12", product: "Oranges", value: 22000},
69
{parent: "01", id: "13", product: "Bananas", value: 88000},
70
{parent: "01", id: "14", product: "Melons", value: 77000},
71
{parent: "01", id: "15", product: "Apricots", value: 48000},
72
{parent: "01", id: "16", product: "Plums", value: 48000},
73
{parent: "01", id: "17", product: "Pineapples", value: 41000},
74
{parent: "01", id: "18", product: "Cherries", value: 39000},
75
{parent: "01", id: "19", product: "Tangerines", value: 32000},
76
77
{parent: "02", id: "21", product: "Potato", value: 189000},
78
{parent: "02", id: "22", product: "Eggplants", value: 94000},
79
{parent: "02", id: "23", product: "Tomatoes", value: 63000},
80
{parent: "02", id: "24", product: "Cucumbers", value: 43000},
81
{parent: "02", id: "25", product: "Cabbage", value: 30000},
82
{parent: "02", id: "26", product: "Carrot", value: 29000},
83
{parent: "02", id: "27", product: "Squash", value: 26000},
84
{parent: "02", id: "28", product: "Capsicums", value: 23000},
85
86
{parent: "03", id: "31", product: "Milk", value: 154000},
87
{parent: "03", id: "32", product: "Curd", value: 142000},
88
{parent: "03", id: "33", product: "Cheese", value: 43000},
89
{parent: "03", id: "34", product: "Yogurt", value: 38000},
90
{parent: "03", id: "35", product: "Kefir", value: 32000},
91
92
{parent: "04", id: "41", product: "Mutton", value: 154000},
93
{parent: "04", id: "42", product: "Beef", value: 142000},
94
{parent: "04", id: "43", product: "Pork", value: 43000},
95
{parent: "04", id: "44", product: "Veal", value: 38000}
96
]