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
function heatMap(mode){
4
// create heatMap
5
var chart = anychart.heatMap(data());
6
7
// set labels display mode
8
chart.labelsDisplayMode(mode);
9
chart.title(mode);
10
chart.xAxis(false);
11
chart.yAxis(false);
12
13
// create color scale
14
var colorScale = anychart.scales.ordinalColor();
15
// set range of heat parameters and corresponding colors
16
colorScale.ranges([
17
{equal: 0, color: "#9ACD32"},
18
{equal: 1, color: "#FFFF00"},
19
{equal: 2, color: "#FF6347"},
20
{equal: 3, color: "#FF0000"}
21
]);
22
// apply colorScale for colorizing heatMap chart
23
chart.colorScale(colorScale);
24
25
// adjust chart labels
26
var labels = chart.labels();
27
// display labels
28
labels.enabled(true);
29
// set minimum font size
30
labels.minFontSize(12);
31
// variable with list of labels
32
var namesList = ["Low", "Medium", "High", "Extreme"];
33
// format labels' content
34
labels.format(function(){
35
// get points heat
36
var value = this.heat;
37
// replace values with words
38
return namesList[value];
39
});
40
// disable tooltip
41
chart.tooltip(false);
42
// manage chart position
43
var padding = chart.padding();
44
padding.bottom(0);
45
padding.top(10);
46
47
return chart;
48
}
49
50
var table = anychart.standalones.table();
51
table.contents([
52
[
53
"Labels Display Mode"
54
],[
55
heatMap("clip")
56
],[
57
heatMap("drop")
58
],[
59
heatMap("alwaysShow")
60
]
61
]);
62
63
for (var i=1;i<4;i++){
64
var row = table.getRow(i);
65
row.minHeight(230);
66
}
67
var col = table.getCol(0);
68
col.width(245);
69
table.cellBorder(null);
70
var row0 = table.getRow(0);
71
row0.height(30);
72
row0.hAlign("center");
73
74
// set table container and initiate draw
75
table.container("container");
76
table.left((table.container().width()/2)-122);
77
table.draw();
78
});
79
function data(){
80
return anychart.data.set([
81
{x: "Rare", y: "Insignificant", heat: 0},
82
{x: "Rare", y: "Minor", heat: 0},
83
{x: "Rare", y: "Moderate", heat: 0},
84
{x: "Rare", y: "Major", heat: 0},
85
{x: "Rare", y: "Extreme", heat: 0},
86
{x: "Unlikely", y: "Insignificant", heat: 0},
87
{x: "Unlikely", y: "Minor", heat: 0},
88
{x: "Unlikely", y: "Moderate", heat: 0},
89
{x: "Unlikely", y: "Major", heat: 1},
90
{x: "Unlikely", y: "Extreme", heat: 1},
91
{x: "Possible", y: "Insignificant", heat: 0},
92
{x: "Possible", y: "Minor", heat: 0},
93
{x: "Possible", y: "Moderate", heat: 1},
94
{x: "Possible", y: "Major", heat: 1},
95
{x: "Possible", y: "Extreme", heat: 1},
96
{x: "Likely", y: "Insignificant", heat: 0},
97
{x: "Likely", y: "Minor", heat: 1},
98
{x: "Likely", y: "Moderate", heat: 1},
99
{x: "Likely", y: "Major", heat: 2},
100
{x: "Likely", y: "Extreme", heat: 2},
101
{x: "Almost\nCertain", y: "Insignificant", heat: 0},
102
{x: "Almost\nCertain", y: "Minor", heat: 1},
103
{x: "Almost\nCertain", y: "Moderate", heat: 1},
104
{x: "Almost\nCertain", y: "Major", heat: 2},
105
{x: "Almost\nCertain", y: "Extreme", heat: 3}
106
]);
107
}