JSFiddle - React, Tailwind, and code Playground
by theboyler
HTML
<body>
<canvas id="chartJSContainer" width="32" height="32"></canvas>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.3.0/chart.js"></script>
</body>
JavaScript
makepie(5,0,0,0)
function makepie(a,b,c,d){
if (b <= 0) {n = 'n'} else {n = 'y'}
if (c <= 0) {o = 'n'} else {o = 'y'}
if (d <= 0) {p = 'n'} else {p = 'y'}
q = n + o + p
if (q == 'nnn') {s = [a];r = ['Indianred'];u = ['Emails']}
if (q == 'yyy') {s = [a, b, c, d];r = ['Indianred', 'salmon', 'pink', 'mistyrose'];u = ['Emails','Calls','Meetings','Working']}
if (q == 'ynn') {s = [a, b];r = ['Indianred', 'salmon'];u = ['Emails','Calls']}
if (q == 'nyn') {s = [a, c];r = ['Indianred', 'pink', ];u = ['Emails','Working']}
if (q == 'nny') {s = [a, d];r = ['Indianred', 'mistyrose'];u = ['Emails','Working']}
if (q == 'yyn') {s = [a, b, c];r = ['Indianred', 'salmon', 'pink'];u = ['Emails','Calls','Meetings']}
if (q == 'yny') {s = [a, b, d];r = ['Indianred', 'salmon', 'mistyrose'];u = ['Emails','Calls','Working']}
if (q == 'nyy') {s = [a, c, d];r = ['Indianred', 'pink', 'mistyrose'];u = ['Emails','Meetings','Working']}
var options = {
type: 'pie',
data: {
labels: u,
datasets: [{
data: s,
borderColor: '#6f6f6f',
borderWidth: (ctx) => (ctx.chart.data.datasets[0].data.length === 1 ? 0 : 3),
backgroundColor: r
}]
},
options: {
hover: {mode: null},
animation: {duration: (Math.floor(Math.random() * 30) + 20) * 100},
legend: {display: false,labels: {display: false}},
rotation: (Math.floor(Math.random() * 5)+1),
tooltips: {enabled: false},
plugins: {
legend: {display: false},
circleAroundPieDoughnut: {
width: 3,
color: '#6f6f6f'
}
}
},
plugins: [{
id: 'circleAroundPieDoughnut',
beforeDatasetsDraw: (chart, args, options) => {
if (chart.data.datasets[0].data.length > 1) return;
var {
ctx,
canvas
} = chart;
var {
top,
left,
width,
height
} = chart.chartArea;
var x = left + width / 2;
var...