JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://rawgit.com/vpassapera/jqPlot/master/jquery.jqplot.min.js"></script>
<link rel="stylesheet" href="https://rawgit.com/vpassapera/jqPlot/master/jquery.jqplot.min.css">
<script src="https://rawgit.com/vpassapera/jqPlot/master/plugins/jqplot.pieRenderer.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqPlot/1.0.8/plugins/jqplot.highlighter.min.js"></script>
<div id="donut-chart"></div>
CSS
#donut-chart {
height: 500px;
width: 450px;
border: 1px solid black;
}
JavaScript
//This is your data-set..
var data = [12, 9, 14, 16, 7, 9];
//Total/Sum of values in data-set..
var total = 0;
for(var val in data) {
total += data[val];
}
//Setting the dummy data as total, which will be half of the pie chart, that we are gonna plot..
var dummyData = total;
//We add this dummyData to the data-set.. In this case, it becomes our 7th value..
data.push(dummyData);
//Hack to draw half piechart.. We set the color for last/extra part(7th value) as transparent..
//rgba(255,255,255,1) => transparent (the last value '1' sets the opacity)
var seriesColorsArray = ['#DF7401', '#2E9AFE', '#3ADF00', '#FE2E64', '#D7DF01', '#8A0808', 'rgba(255,255,255,1)'];
//Preparing data-labels array to display on the pie-slices.
//NOTE: We are not labelling the dummyData.. So we add only six values..
var dataLabelsArray = ['One', 'Two', 'Three', 'Four', 'Five', 'Six'];
var plot1 = jQuery.jqplot ('donut-chart', [data],
{
seriesDefaults: {
// Make this a pie chart.
renderer: jQuery.jqplot.PieRenderer,
rendererOptions: {
highlightMouseOver: false,
highlightMouseDown: false,
highlightColor: null,
startAngle: 180,
//Remove shadow from the pie(shadow along the circumference, turn the below value to '1' and see the difference)
shadowDepth : 0,
//By default, jqplot displays percentages on the pie-slices, which in our case would be wrong values..
//Since we added an extra dummy-value.. And hence percentages will be half of what you expect to see..
dataLabelThreshold: 0,
showDataLabels: true,
// Setting the dataLabelsArray - defined above..
dataLabels: dataLabelsArray,
dataLabelFormatString: "%s"
}
},
//Setting the series colors - defined above..
seriesColors: seriesColorsArray,
highlighter: {
show: false
},
...