Abdullah Al Mamun
Abdullah Al Mamun

Reputation: 392

How to make a prefilled doughnut in chart.js?

I want to create a prefilled doughnut using chart.js like the picture below.enter image description here

This doughnut is made of using SVG.
But chart.JS cannot support SVG's

So Is there any way to create a doughnut-like the Image above.

Upvotes: 0

Views: 89

Answers (1)

Łukasz
Łukasz

Reputation: 2171

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).

Upvotes: 1

Related Questions