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/periodic-table/data.json
4
anychart.data.loadJsonFile(
5
'https://cdn.anychart.com/samples/heat-map-charts/periodic-table/data.json',
6
function (data) {
7
// Sets data for Periodic Table
8
var dataSet = anychart.data.set(data);
9
var heatMapData = dataSet.mapAs({
10
x: 'column',
11
y: 'row',
12
heat: 'ElementCategory'
13
});
14
15
// Creates Heat Map
16
var chart = anychart.heatMap(heatMapData);
17
18
// Sets selection mode for single selection.
19
chart.interactivity().selectionMode('none');
20
21
// Sets colorScale
22
var colorScale = anychart.scales.ordinalColor();
23
// Sets colors for all points
24
colorScale.ranges([
25
{ equal: 'Alkali metals', color: '#ef6c00 0.8' },
26
{ equal: 'Alkaline earth metals', color: '#ffa000 0.8' },
27
{ equal: 'Transition elements', color: '#ffd54f 0.8' },
28
{ equal: 'Other metals', color: '#00bfa5 0.8' },
29
{ equal: 'Metalloids', color: '#00838f 0.8' },
30
{ equal: 'Other nonmetals', color: '#64b5f6 0.8' },
31
{ equal: 'Halogens', color: '#1976d2 0.8' },
32
{ equal: 'Noble gases', color: '#01579b 0.8' },
33
{ equal: 'Unknown', color: '#96a6a6 0.8' }
34
]);
35
chart.colorScale(colorScale);
36
37
// Sets chart settings and hover chart settings
38
chart.stroke('#fff');
39
chart
40
.hovered()
41
.stroke('6 #fff')
42
.fill('#545f69')
43
.labels({ fontColor: '#fff' });
44
45
// Sets chart title
46
chart.padding([10, 10, 10, 10]);
47
chart
48
.title()
49
.enabled(true)
50
.text('Periodic Table of Elements')
51
.padding([0, 0, 10, 2])
52
.align('left');
53
54
// Sets tooltip formatter and tooltip title formatter
55
chart
56
.tooltip()
57
.title({ useHtml: true })
58
.useHtml(true)
59
.titleFormat(function () {
60
return (
61
'<span style="color: #CECECE">' +
62
this.getData('Symbol') +
63
': </span>' +
64
'<span style="font-size: 16px">' +
65
this.getData('name') +
66
'</span>'
67
);
68
})
69
.format(function () {
70
return (
71
'<span style="color: #CECECE">Category: </span>' +
72
this.getData('ElementCategory') +
73
'<br/>' +
74
'<span style="color: #CECECE">Atomic number: </span>' +
75
this.getData('Number') +
76
'<br/>' +
77
'<span style="color: #CECECE">Group: </span>' +
78
this.x +
79
'<br/>' +
80
'<span style="color: #CECECE">Period: </span>' +
81
this.y
82
);
83
});
84
85
// Sets labels for chart
86
chart.labels().enabled(true).fontSize(16).format('{%Symbol}');
87
88
// Sets legend
89
chart
90
.legend()
91
.align('top')
92
.position('right')
93
.itemsLayout('vertical')
94
.padding([2, 10, 0, 20])
95
.enabled(true)
96
.tooltip(false);
97
98
// Turns off axes
99
chart.yAxis(false);
100
chart.xAxis(false);
101
102
// set container id for the chart
103
chart.container('container');
104
// initiate chart drawing
105
chart.draw();
106
}
107
);
108
});