35
loading...
This website collects cookies to deliver better user experience
<div>
later in the code, we give it an id attribute. Let it be just “container” this time.width
and height
parameters inside the <style>
block as “100%” so the donut chart fills the whole page.<html>
<head>
<title>JavaScript Donut Chart</title>
<style type="text/css">
html, body, #container {
width: 100%; height: 100%; margin: 0; padding: 0;
}
</style>
</head>
<body>
<div id="container"></div>
</body>
</html>
<head>
section of the HTML page.<html>
<head>
<title>JavaScript Donut Chart</title>
<script src="https://cdn.anychart.com/releases/8.10.0/js/anychart-core.min.js"></script>
<script src="https://cdn.anychart.com/releases/8.10.0/js/anychart-pie.min.js"></script>
<style type="text/css">
html, body, #container {
width: 100%; height: 100%; margin: 0; padding: 0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
// All the code for the JS donut chart will come here
</script>
</body>
</html>
var data = anychart.data.set([
['Spotify', 34],
['Apple Music', 21],
['Amazon Music', 15],
['Tencent apps', 11],
['YouTube Music', 6],
['Others', 13]
]);
// create a pie chart with the data
var chart = anychart.pie(data)
// set the chart radius making a donut chart
chart.innerRadius('55%');
chart.title('Music Streaming Apps Global Market Share')
chart.container('container');
chart.draw();