Chartjs-Using data in HTML to display ChartJS Doughnut chart

0👍

Well if you have to pull data from the DOM here is the possible solution (not the prettiest one, but it works… ). Give the corresponding HTML elements ids e.g. amount and total.

var total = document.getElementById("total").innerText;
var amount = document.getElementById("amount").innerText / total * 100;
var left = 100 - amount;

if ( amount && total ) {
 data.datasets[0].data = [amount, left];
}

See this working fiddle

And do some styling…

Leave a comment