HTMLcopy
1
<script src="https://cdn.anychart.com/releases/8.9.0/js/anychart-base.min.js"></script>
2
<script src="https://cdn.anychart.com/releases/8.9.0/js/anychart-mekko.min.js"></script>
3
<div id="container">
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
// load data
4
var data = {
5
title: 'Global Smartphone Shipments (In Millions) in 2019',
6
header: ['Name', 'Quarter 1', 'Quarter 2', 'Quarter 3', 'Quarter 4'],
7
rows: [
8
['Huawei', 59.1,56.6,66.8,56.2],
9
['Vivo', 23.9,27,31.3,31.5],
10
['Apple', 42,36.5,44.8,72.3],
11
['Samsung', 72,76.3,78.2,70.4],
12
['Xiaomi', 27.8,32.3,31.7,32.9],
13
['Oppo', 25.7,30.6,32.3,31.4],
14
['Others', 90.5,97.7,94.9,106.4],
15
]
16
};
17
18
// create mekko chart
19
var chart = anychart.mekko();
20
21
// set chart data
22
chart.data(data);
23
24
// enabled legend
25
chart.legend(true);
26
27
// Anychart uses palette for coloring
28
chart.palette(anychart.palettes.wines);
29
30
// set format tooltip
31
chart.tooltip().format('{%seriesName}: ${%Value}M');
32
// set display mode for the tooltip
33
chart.tooltip().displayMode("union");
34
35
// Customize + tooltip title
36
var title = chart.tooltip().title();
37
title.fontFamily("Calibri");
38
title.fontDecoration("underline");
39
title.fontWeight(700);
40
title.fontSize(18);
41
42
// set titles for x-axis
43
chart.xAxis().title('Smartphone Shipments by Brands');
44
// set titles for y-axis
45
chart.yAxis().title('Smartphone Shipments by Quarters %');
46
47
// set container id for the chart
48
chart.container('container');
49
50
// initiate chart drawing
51
chart.draw();
52
53
});