HTMLcopy
1
<div id="container"></div>
CSScopy
8
1
html,
2
body,
3
#container {
4
width: 100%;
5
height: 100%;
6
margin: 0;
7
padding: 0;
8
}
JavaScriptcopy
x
1
anychart.onDocumentReady(function () {
2
// The data used in this sample can be obtained from the CDN
3
// https://cdn.anychart.com/samples/heat-map-charts/body-fat-charts/data.js
4
var dataSetMen = anychart.data.set(getMenData()); // eslint-disable-line no-undef
5
var heatMapMenData = dataSetMen.mapAs({
6
y: 0,
7
x: 1,
8
value: 2,
9
heat: 3
10
});
11
var dataSetWomen = anychart.data.set(getWomenData()); // eslint-disable-line no-undef
12
var heatMapWomenData = dataSetWomen.mapAs({
13
y: 0,
14
x: 1,
15
value: 2,
16
heat: 3
17
});
18
19
// create stage for all charts
20
var stage = acgraph.create('container');
21
22
// helper function to setup same settings for all six charts
23
var setupChartSettings = function (chart) {
24
chart
25
.container(stage)
26
.padding([5, 10, 5, 10])
27
.margin(0)
28
.xAxis(false)
29
.interactivity({ selectionMode: 'none' });
30
chart.yAxis().stroke('#fff').ticks(false);
31
chart.yAxis().title().enabled(true).text('Age').padding(0).margin(0);
32
33
// Sets title setting
34
chart
35
.title()
36
.enabled(true)
37
.padding([0, 0, 5, 75])
38
.fontColor('#212121')
39
.align('left');
40
41
// Sets labels
42
chart.labelsDisplayMode('drop');
43
chart
44
.labels()
45
.enabled(true)
46
.maxFontSize(12)
47
.format(function () {
48
return this.getData('value');
49
});
50
51
// Sets chart settings and hover chart settings
52
chart.stroke('#fff');
53
chart
54
.hovered()
55
.stroke('4 #fff')
56
.fill('#545f69')
57
.labels({ fontColor: '#fff' });
58
59
// Sets range for colorScale
60
var colorScale = chart.colorScale();
61
62
// Sets colors for all points
63
colorScale.ranges([
64
{ equal: 0, color: '#3085be 0.8', name: 'Lean' },
65
{ equal: 1, color: '#69bce8 0.8', name: 'Ideal' },
66
{ equal: 2, color: '#ffa000 0.8', name: 'Average' },
67
{ equal: 3, color: '#ff6d00 0.8', name: 'Above average' }
68
]);
69
chart.colorScale(colorScale);
70
// Sets legend
71
chart
72
.legend()
73
.enabled(true)
74
.align('left')
75
.position('center-top')
76
.itemsLayout('horizontal')
77
.padding([0, 0, 8, 75]);
78
79
// Turns tooltips off
80
chart.tooltip(false);
81
};
82
83
// Creates Heat Map for Men
84
var menChart = anychart.heatMap(heatMapMenData);
85
menChart.title('Body Fat Percentage Chart for Men');
86
menChart.bounds(0, 0, '100%', '50%');
87
setupChartSettings(menChart);
88
menChart.draw();
89
90
// Creates Heat Map for Women
91
var womenChart = anychart.heatMap(heatMapWomenData);
92
womenChart.title('Body Fat Percentage Chart for Women');
93
womenChart.bounds(0, '50%', '100%', '50%');
94
setupChartSettings(womenChart);
95
womenChart.draw();
96
97
var credits = womenChart.credits();
98
credits.enabled(true);
99
credits.url('http://www.bodyfatcharts.com/');
100
credits.text('Data source: http://www.bodyfatcharts.com/');
101
});