Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including react-donut-chart with all npm packages installed. Try it out:

var reactDonutChart = require("react-donut-chart")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

react-donut-chart v1.1.8

An extendable SVG donut chart React component.


An extendable SVG-based donut chart React component.



npm install react-donut-chart --save


import DonutChart from 'react-donut-chart';
//things I would never do:
        label: 'Give you up',
        value: 25
        label: '',
        value: 75,
        isEmpty: true
    }]} />

View the demo online, or run it locally:

npm run build npm run start

then visit localhost:3000.


  value: number.isRequired,
  label: string,
  className: string,
  isEmpty: boolean
  value: 100,
  label: '',
The chart data
classNamestringfalsedonutchartThis is the className given to the top-level svg element. All subclasses are prefixed from this name:
  • ${className}-arcs accesses the entire graph area
    • ${className}-arcs-paths accesses the individual arc paths
  • ${className}-innertext accesses all of the text within the inner donut area
    • ${className}-innertext-label accesses the label within this area
    • ${className}-innertext-value accesses the value within this area
  • ${className}-legend accesses the legend component
    • ${className}-legend-rect accesses the legend rectangle items
    • ${className}-legend-label accesses the labels of the legend items
In addition the selected class is given to selected items, the toggled class to all toggled items, and the isEmpty class to all isEmpty items. All style (and animations) can be manipulated from the CSS
heightnumberfalse500Height of the entire component
widthnumberfalse750Width of the entire component. If no legend is specified, then the chart takes up the entire width. If a legend is toggled, then the chart takes up 2/3 of the width, and the legend takes up 1/3
colorsarrayOf(string)false['#f44336', '#e91e63', '#9c27b0', '#673ab7', '#3f51b5', '#2196f3', '#03a9f4', '#00bcd4', '#009688', '#4caf50', '#8bc34a', '#cddc39', '#ffeb3b', '#ffc107', '#ff9800', '#ff5722', '#795548', '#607d8b' ]An array of colors (could be hex strings or named colors) for the data items. Defaults to an array of Google colors
emptyColorstringfalse'#e0e0e0'A color for empty data items, defaults to gray
strokeColorstringfalse'#212121'A color for the stroke around the items in the graph and legend, defaults to black
colorFunctionfuncfalse(colors, index) => colors[(index % colors.length)]The default cycles through the array of colors and loops for excess
innerRadiusnumberfalse0.70The inner donut radius
outerRadiusnumberfalse0.90The outer donut radius
selectedOffsetnumberfalse0.03The outerRadius offset when an item is selected
emptyOffsetnumberfalse0.08The innerRadius and outerRadius offset on isEmpty items
toggledOffsetnumberfalse0.04The innerRadius and outerRadius offset on toggle-clicked items
startAnglenumberfalse0The drawing start angle
formatValuesfuncfalse(values, total) => `${(values / total * 100).toFixed(2)}%`Custom format for values displayed in the donut chart's inner text area. By default formats as percentages rounded to two decimal places.
onMouseEnterfuncfalse(item) => itemCallback that fires when an item is hovered
onClickfuncfalseonClick: (item, toggled) => (toggled ? item : null)Callback that fires when an item is toggle-clicked
legendboolfalsetrueDetermines whether or not to create a legend
clickToggleboolfalsetrueDetermines whether or not to toggle-freeze the graph on the arc that has been clicked



RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free