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
// create 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 a mekko (marimekko) chart
19
var chart = anychart.mekko();
20
21
// set the chart data
22
chart.data(data);
23
24
// enable the chart legend
25
chart.legend(true);
26
27
// apply a palette for coloring
28
chart.palette(anychart.palettes.wines);
29
30
// customize the tooltip format
31
chart.tooltip().format('{%seriesName}: ${%Value}M');
32
// set the tooltip display mode
33
chart.tooltip().displayMode("union");
34
35
// customize the 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 the chart labels settings
43
chart.labels().format('${%Value}M');
44
45
// set the x-axis title
46
chart.xAxis().title('Smartphone Shipments by Brands');
47
// set the y-axis title
48
chart.yAxis().title('Smartphone Shipments by Quarters %');
49
50
// set the chart container id
51
chart.container('container');
52
53
// draw the resulting marimekko chart
54
chart.draw();
55
56
});