HTMLcopy
1
<script src="https://cdn.anychart.com/releases/8.9.0/js/anychart-core.min.js" type="text/javascript"></script>
2
<script src="https://cdn.anychart.com/releases/8.9.0/js/anychart-circular-gauge.min.js"></script>
3
<script src="https://cdn.anychart.com/releases/8.9.0/js/anychart-data-adapter.min.js"></script>
4
5
<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
anychart.data.loadJsonFile('https://gist.githubusercontent.com/shacheeswadia/9e4598a73bb86180f1726daf9de8062f/raw/b258e93e1f9db37da6847eb05a230afcb64446d5/circularGaugeData.json', function (data) {
4
5
// Get the names of the records
6
var recordNames = data.map(function(d){
7
return d.Record;
8
});
9
10
// Get the percent values
11
var recordPercentValue = data.map(function(d){
12
return d.percent;
13
});
14
15
// Add the 100% value to signify the max value for each of the radial ring
16
recordPercentValue.push(100);
17
18
// Set the data to indicate the percent values
19
var dataSet = anychart.data.set(recordPercentValue);
20
21
// Create the angular gauge
22
var gauge = anychart.gauges.circular();
23
24
// Set the data for the angular gauge
25
gauge.data(dataSet);
26
27
// Set the colors based on the designated palette
28
var palette = anychart.palettes
29
.distinctColors()
30
.items([
31
'#593d04', '#6c4304', '#966905', '#a77b0a', '#cf9f20', '#ddb22e', '#f1c84d', '#ffdc73'
32
]);
33
34
// Specify the attributes of the angular gauge chart
35
gauge
36
.fill('#fff')
37
.stroke(null)
38
.padding(25, 100, 25, 100)
39
.margin(0)
40
.startAngle(0)
41
.sweepAngle(270);
42
43
// Create the angular gauge axis
44
var axis = gauge.axis().radius(100).width(1).fill(null);
45
46
// Set the minimum and maximum values for the axis
47
axis
48
.scale()
49
.minimum(0)
50
.maximum(100);
51
52
// Hide the axis labels and ticks
53
axis.labels().enabled(false);
54
axis.ticks().enabled(false);
55
axis.minorTicks().enabled(false);
56
57
// Create a function to make radial bars for each data point
58
var makeBarWithBar = function (gauge, radius, i, width) {
59
60
// Create the radial bars based on the data
61
gauge
62
.bar(i)
63
.dataIndex(i)
64
.radius(radius)
65
.width(width)
66
.fill(palette.itemAt(i))
67
.stroke(null)
68
.zIndex(5);
69
70
// Create the background radial bars indicating the total value
71
gauge
72
.bar(i + 100)
73
.dataIndex(8)
74
.radius(radius)
75
.width(width)
76
.fill('#F5F4F4')
77
.stroke(null)
78
.zIndex(4);
79
80
// Set the labels based on each data point
81
gauge
82
.label(i)
83
.text(recordNames[i]);
84
85
// Align the labels
86
gauge
87
.label(i)
88
.hAlign('center')
89
.vAlign('middle')
90
.anchor('right-center')
91
.padding(0, 10)
92
.height(width / 2 + '%')
93
.offsetY(radius + '%')
94
.offsetX(0);
95
96
return gauge.bar(i);
97
98
};
99
100
// Get the time of each song
101
var recordLength = data.map(function(d){
102
return d['Time'];
103
});
104
105
// Call the function to create the radial bars with specifications
106
for(var i=0, j=100; i<data.length, j>=12.5; i++, j-=12.5){
107
makeBarWithBar(gauge, j, i, (recordLength[i]* 2.75));
108
}
109
110
// Add the angular gauge chart title
111
gauge.title('Popularity of 2021 GRAMMYs Record of the Year Nominations on Spotify');
112
113
gauge
114
.title()
115
.enabled(true)
116
.hAlign('center')
117
.padding(0)
118
.margin([0, 0, 10, 0]);
119
120
// Drawing the resulting angular gauge
121
gauge.container('container');
122
gauge.draw();
123
124
});
125
126
});