HTMLcopy
1
<script src="https://cdn.anychart.com/releases/8.10.0/js/anychart-core.min.js"></script>
2
<script src="https://cdn.anychart.com/releases/8.10.0/js/anychart-pie.min.js"></script>
3
<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
3
// add data
4
var data = anychart.data.set([
5
['Spotify', 34],
6
['Apple Music', 21],
7
['Amazon Music', 15],
8
['Tencent apps', 11],
9
['YouTube Music', 6],
10
['Others', 13]
11
]);
12
13
// create a pie chart with the data
14
var chart = anychart.pie(data);
15
16
// set the chart radius making a donut chart
17
chart.innerRadius('55%')
18
19
// create a color palette
20
var palette = anychart.palettes.distinctColors();
21
22
// set the colors according to the brands
23
palette.items([
24
{ color: '#1dd05d' },
25
{ color: '#000000' },
26
{ color: '#00a3da' },
27
{ color: '#156ef2' },
28
{ color: '#f60000' },
29
{ color: '#96a6a6' }
30
]);
31
32
// apply the donut chart color palette
33
chart.palette(palette);
34
35
// set the position of labels
36
chart.labels().format('{%x} - {%y}%').fontSize(16);
37
38
// disable the legend
39
chart.legend(false);
40
41
// format the donut chart tooltip
42
chart.tooltip().format('Market share: {%PercentValue}%');
43
44
// create a standalone label
45
var label = anychart.standalones.label();
46
47
// configure the label settings
48
label
49
.useHtml(true)
50
.text(
51
'<span style = "color: #313136; font-size:20px;">Global Market Share of <br/> Music Streaming Apps</span>' +
52
'<br/><br/></br><span style="color:#444857; font-size: 14px;"><i>Spotify and Apple Music have more <br/>than 50% of the total market share</i></span>'
53
)
54
.position('center')
55
.anchor('center')
56
.hAlign('center')
57
.vAlign('middle');
58
59
// set the label as the center content
60
chart.center().content(label);
61
62
// set container id for the chart
63
chart.container('container');
64
65
// initiate chart drawing
66
chart.draw();
67
68
});