Chartjs-How to make a prefilled doughnut in chart.js?

1👍

It can be done this way:

var canvas = document.getElementById('myChart');
var data = {
  labels: ["1", "2"],
  datasets: [{
    data: [105, 20],
    backgroundColor: ['da5d78', 'gray'],
  }]
};

var options = {
  rotation: 0,
  cutoutPercentage: 85,
  legend: {
    display: false
  },
  tooltips: {
    enabled: false
  }
}

Chart.Doughnut(canvas, {
  data: data,
  options: options
});

HTML

<canvas id="myChart" width="400" height="200"></canvas>

See how it looks on working jsfiddle

See docs for explanations of options (cutoutPercentage, rotation etc).

Leave a comment