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 the data
4
var data = [
5
{ x: "2010", y: "Arab States", heat: 0.676 },
6
{ x: "2010", y: "East Asia and the Pacific", heat: 0.691 },
7
{ x: "2010", y: "Europe and Central Asia", heat: 0.735 },
8
{ x: "2010", y: "Latin America and the Caribbean", heat: 0.731 },
9
{ x: "2010", y: "South Asia", heat: 0.585 },
10
{ x: "2010", y: "Sub-Saharan Africa", heat: 0.498 },
11
{ x: "2011", y: "Arab States", heat: 0.681 },
12
{ x: "2011", y: "East Asia and the Pacific", heat: 0.700 },
13
{ x: "2011", y: "Europe and Central Asia", heat: 0.744 },
14
{ x: "2011", y: "Latin America and the Caribbean", heat: 0.737 },
15
{ x: "2011", y: "South Asia", heat: 0.593 },
16
{ x: "2011", y: "Sub-Saharan Africa", heat: 0.505 },
17
{ x: "2012", y: "Arab States", heat: 0.687 },
18
{ x: "2012", y: "East Asia and the Pacific", heat: 0.707 },
19
{ x: "2012", y: "Europe and Central Asia", heat: 0.750 },
20
{ x: "2012", y: "Latin America and the Caribbean", heat: 0.740 },
21
{ x: "2012", y: "South Asia", heat: 0.601 },
22
{ x: "2012", y: "Sub-Saharan Africa", heat: 0.512 },
23
{ x: "2013", y: "Arab States", heat: 0.688 },
24
{ x: "2013", y: "East Asia and the Pacific", heat: 0.714 },
25
{ x: "2013", y: "Europe and Central Asia", heat: 0.759 },
26
{ x: "2013", y: "Latin America and the Caribbean", heat: 0.748 },
27
{ x: "2013", y: "South Asia", heat: 0.607 },
28
{ x: "2013", y: "Sub-Saharan Africa", heat: 0.521 },
29
{ x: "2014", y: "Arab States", heat: 0.691 },
30
{ x: "2014", y: "East Asia and the Pacific", heat: 0.721 },
31
{ x: "2014", y: "Europe and Central Asia", heat: 0.766 },
32
{ x: "2014", y: "Latin America and the Caribbean", heat: 0.752 },
33
{ x: "2014", y: "South Asia", heat: 0.617 },
34
{ x: "2014", y: "Sub-Saharan Africa", heat: 0.527 },
35
{ x: "2015", y: "Arab States", heat: 0.695 },
36
{ x: "2015", y: "East Asia and the Pacific", heat: 0.727 },
37
{ x: "2015", y: "Europe and Central Asia", heat: 0.770 },
38
{ x: "2015", y: "Latin America and the Caribbean", heat: 0.754 },
39
{ x: "2015", y: "South Asia", heat: 0.624 },
40
{ x: "2015", y: "Sub-Saharan Africa", heat: 0.532 },
41
{ x: "2016", y: "Arab States", heat: 0.699 },
42
{ x: "2016", y: "East Asia and the Pacific", heat: 0.733 },
43
{ x: "2016", y: "Europe and Central Asia", heat: 0.772 },
44
{ x: "2016", y: "Latin America and the Caribbean", heat: 0.756 },
45
{ x: "2016", y: "South Asia", heat: 0.634 },
46
{ x: "2016", y: "Sub-Saharan Africa", heat: 0.535 },
47
{ x: "2017", y: "Arab States", heat: 0.699 },
48
{ x: "2017", y: "East Asia and the Pacific", heat: 0.733 },
49
{ x: "2017", y: "Europe and Central Asia", heat: 0.771 },
50
{ x: "2017", y: "Latin America and the Caribbean", heat: 0.758 },
51
{ x: "2017", y: "South Asia", heat: 0.638 },
52
{ x: "2017", y: "Sub-Saharan Africa", heat: 0.537 },
53
{ x: "2018", y: "Arab States", heat: 0.703 },
54
{ x: "2018", y: "East Asia and the Pacific", heat: 0.741 },
55
{ x: "2018", y: "Europe and Central Asia", heat: 0.779 },
56
{ x: "2018", y: "Latin America and the Caribbean", heat: 0.759 },
57
{ x: "2018", y: "South Asia", heat: 0.642 },
58
{ x: "2018", y: "Sub-Saharan Africa", heat: 0.541 },
59
];
60
61
// create the chart and set the data
62
chart = anychart.heatMap(data);
63
64
// set the chart title
65
chart.title("Human Development Index by region (2010-2018)");
66
67
// create and configure the color scale
68
var customColorScale = anychart.scales.ordinalColor();
69
customColorScale.ranges([
70
{ less: 0.549, name: 'Low: <= 0.549', color: '#CF7A78' },
71
{ from: 0.550, to: 0.699, name: 'Medium: 0.55 - 0.699', color: '#E69645' },
72
{ from: 0.700, to: 0.799, name: 'High: 0.7 - 0.799', color: '#69A231' },
73
{ greater: 0.800, name: 'Very High: >=0.8', color: '#4D7623' }
74
]);
75
76
// set the colors for each range, from smaller to bigger
77
customColorScale.colors(["#CF7A78", "#E69645", "#69A231", "#4D7623"]);
78
79
// set the color scale as the color scale of the chart
80
chart.colorScale(customColorScale);
81
82
// enable the legend
83
chart.legend(true);
84
85
// hide cell labels
86
chart.labels().enabled(false)
87
88
// create categories
89
var categoryNames = ["Low", "Medium", "High", "Very High"]
90
91
// configure the tooltip
92
var tooltip = chart.tooltip();
93
tooltip.fontWeight(600);
94
tooltip.positionMode("point");
95
tooltip.format(function () {
96
if (this.heat <= 0.549) {
97
return ("Value: " + this.heat + "\n Category: " + categoryNames[0]);
98
}
99
if (this.heat >= 0.55 && this.heat <= 0.699) {
100
return ("Value: " + this.heat + "\n Category: " + categoryNames[1]);
101
}
102
if (this.heat >= 0.7 && this.heat <= 0.799) {
103
return ("Value: " + this.heat + "\n Category: " + categoryNames[2]);
104
}
105
});
106
107
// set the container id
108
chart.container("container");
109
110
// initiate drawing the chart
111
chart.draw();
112
113
});