Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Chart.js Doughnut Chart

Chart.js Doughnut Chart

A doughnut chart, also called a donut chart, is essentially a pie chart with the center region hollowed out.

A doughnut chart is a figure formed by stacking two or more pie charts of different sizes and removing the middle portion.

Doughnut Chart type The attribute is doughnut, and type describes the chart type.



const config = {

  type: 'doughnut',

  data: data,

};

Next, let's create a simple doughnut chart:

Example

const

ctx

=

document.

getElementById

(

'myChart'

)

;

const

data

=

{

  labels

:

[

   

'Red'

,

   

'Blue'

,

   

'Yellow'

 

]

,

  datasets

:

[

{

    label

:

'Doughnut Chart Example'

,

    data

:

[

300

,

50

,

100

]

,

    backgroundColor

:

[

     

'rgb(255, 99, 132)'

,

     

'rgb(54, 162, 235)'

,

     

'rgb(255, 205, 86)'

   

]

,

    hoverOffset

:

4

 

}

]

}

;

const

config

=

{

  type

:

'doughnut'

,

  data

:

data

,

  options

:

{

    responsive

:

true

,

// Make the chart responsive, adapting to window size changes

    maintainAspectRatio

:

false

,

// Maintain the chart's original aspect ratio

    scales

:

{

      yAxes

:

[

{

        ticks

:

{

          beginAtZero

:

true

               

}

         

}

]

   

}

 

}

}

;

const

myChart

=

new

Chart

(

ctx

,

config

)

;

Try it »

The output of the above example is: