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
{x: "2010", y: "A", heat: 15, custom_field: "info 1"},
6
{x: "2011", y: "A", heat: 17, custom_field: "info 2"},
7
{x: "2012", y: "A", heat: 21, custom_field: "info 3"},
8
{x: "2013", y: "A", heat: 23, custom_field: "info 4"},
9
{x: "2010", y: "B", heat: 34, custom_field: "info 5"},
10
{x: "2011", y: "B", heat: 33, custom_field: "info 6"},
11
{x: "2012", y: "B", heat: 32, custom_field: "info 7"},
12
{x: "2013", y: "B", heat: 30, custom_field: "info 8"},
13
{x: "2010", y: "C", heat: 43, custom_field: "info 9"},
14
{x: "2011", y: "C", heat: 42, custom_field: "info 10"},
15
{x: "2012", y: "C", heat: 40, custom_field: "info 11"},
16
{x: "2013", y: "C", heat: 38, custom_field: "info 12"},
17
{x: "2010", y: "D", heat: 8, custom_field: "info 13"},
18
{x: "2011", y: "D", heat: 8, custom_field: "info 14"},
19
{x: "2012", y: "D", heat: 7, custom_field: "info 15"},
20
{x: "2013", y: "D", heat: 8, custom_field: "info 16"}
21
];
22
23
// create a chart and set the data
24
var chart = anychart.heatMap(data);
25
26
// enable HTML for labels
27
chart.labels().useHtml(true);
28
29
// configure labels
30
chart.labels().format(function() {
31
var heat = (this.heat);
32
if (heat < 20)
33
return "Low<br/>" + heat + "%";
34
if (heat < 40)
35
return "Medium<br/>" + heat + "%";
36
if (heat >= 40)
37
return "<span style='font-weight:bold'>High</span><br/>" +
38
heat + "%";
39
});
40
41
// configure tooltips
42
chart.tooltip().format(function() {
43
var heat = (this.heat);
44
if (heat < 20)
45
return this.y + ": Low (" + heat + "%)\n\n" +
46
this.getData("custom_field");
47
if (heat < 40)
48
return this.y + ": Medium (" + heat + "%)\n\n" +
49
this.getData("custom_field");
50
if (heat >= 40)
51
return this.y + ": High (" + heat + "%)\n\n" +
52
this.getData("custom_field");
53
});
54
55
// set the chart title
56
chart.title("Heat Map: Labels and Tooltips (Formatting Functions)");
57
58
// set the container id
59
chart.container("container");
60
61
// initiate drawing the chart
62
chart.draw();
63
});