Pie and Doughnut Series

This section shows how to create pie charts.

Pie series are used for showing how parts relate to the whole, for example if you want to show the market share of each competitor.

Basic Configuration

To plot a basic pie all we need is an array of values that will determine the angle of each pie slice. The total of all values will correspond to the full pie.

A basic pie series configuration is shown below:

series: [{ type: 'pie', angleKey: 'value' }]

This results in the chart shown below. Note that tooltips show the absolute value of each pie slice.

Slice Labels

In the example above there's no legend or labels next to pie slices. To show those, the label information must be in the data. Additionally, we'll have to provide the labelKey:

series: [{ type: 'pie', angleKey: 'value', + labelKey: 'label' }]

Now we get labels, a legend, and the tooltips will also show labels along with the values:

Each individual slice can be toggled on and off via the legend.

You might notice that not all of the slices in the chart above have a label. The reason for this is that certain slices can be small, and if there's a cluster of small slices their labels will overlap, resulting in a messy chart. To prevent this from happening the series will only show labels for slices with an angle greater than a certain value, which by default is set to be 20 degrees. This value is adjustable via the label.minAngle config:

label: { minAngle: 20 }

The label's callout can be configured to have a different length, color and strokeWidth, for example:

callout: { colors: 'red', length: 20, strokeWidth: 3 }

Please check the API reference below to learn more about label and callout, as well as other series configuration.

Variable Slice Radius

Let's say you have the data for both the market share of mobile operating systems and the level of user satisfaction with each OS. We could represent the satisfaction level as the radius of a slice using the radiusKey config like so:

series: [{ type: 'pie', labelKey: 'os', angleKey: 'share', radiusKey: 'satisfaction' }]

A pie chart where slices can have different radii is also known as a rose chart.

Doughnuts

Pie series can be used to create a doughnut chart by using the innerRadiusOffset config.

series: [{ type: 'pie', labelKey: 'os', angleKey: 'share', innerRadiusOffset: -70 }]

The config specifies the offset value from the maximum pie radius which all pie slices use by default (the maximum pie series radius is determined automatically by the chart depending on the chart's dimensions). -70 in the snippet above means the inner radius of the series should be 70 pixels smaller than the maximum radius.

Multiple Doughnuts

As well as the innerRadiusOffset we can also configure the outerRadiusOffset. This gives us the ability to render multiple pie series in a single chart without overlapping.

series: [ { type: 'pie', outerRadiusOffset: 0, // default innerRadiusOffset: -40, ... }, { type: 'pie', outerRadiusOffset: -100, innerRadiusOffset: -140, ... } ]

In the snippet above we configure the outerRadiusOffset of the second (inner) series to be smaller than the innerRadiusOffset of the first (outer) series. The difference of 60 between these offsets will determine the size of the gap between the outer and inner series. The difference between outerRadiusOffset and innerRadiusOffset for each series will determine the thickness of the rings, which will be 40 for both series in this case.

The example below uses one pie series to plot the market share of each operating system and another pie series to plot user satisfaction level with each OS:

API Reference

angleKey
Required
The key to use to retrieve angle values from the data.
angleNameA human-readable description of the angle values.
labelKey
Required
The key to use to retrieve label values from the data.
labelNameA human-readable description of the label values.
radiusKeyThe key to use to retrieve radius values from the data.
radiusNameA human-readable description of the radius values.
data
Required
The data to use when rendering the series. If this is not supplied, data must be set on the chart instead.
visibleWhether or not to display the series.
Default: true
showInLegendWhether or not to include the series in the legend.
Default: true
tooltipEnabledWhether or not to show tooltips when the series are hovered over.
Default: true
tooltipRendererFunction used to create the content for tooltips.function (params: IParams): string; interface IParams { datum: any; title?: string; color?: string; angleKey: string; angleName?: string; radiusKey?: string; radiusName?: string; labelKey?: string; labelName?: string; }
rotationThe rotation of the pie series in degrees.
Default: 0
innerRadiusOffsetThe offset in pixels of the inner radius of the series. Used to construct doughnut charts. If this is not given, or a value of zero is given, a pie chart will be rendered.
Default: 0
outerRadiusOffsetThe offset in pixels of the outer radius of the series. Used to construct doughnut charts.
Default: 0
titleConfiguration for the series title. See title for more details about this configuration object.
fillsThe colours to cycle through for the fills of the segments.
Default: ['#f3622d', '#fba71b', '#57b757', '#41a9c9', '#4258c9', '#9a42c8', '#c84164', '#888888']
fillOpacityThe opacity of the fill for the segments.
Default: 1
strokesThe colours to cycle through for the strokes of the segments.
Default: ['#aa4520', '#b07513', '#3d803d', '#2d768d', '#2e3e8d', '#6c2e8c', '#8c2d46', '#5f5f5f']
strokeOpacityThe opacity of the stroke for the segments.
Default: 1
strokeWidthThe width in pixels of the stroke for the segments.
Default: 1
highlightStyleConfiguration for the highlighting used when the segments are hovered over. See highlightStyle for more details about this configuration object.
labelConfiguration for the labels used for the segments. See label for more details about this configuration object.
calloutConfiguration for the callouts used with the labels for the segments. See callout for more details about this configuration object.
shadowConfiguration for the shadow used behind the chart series. See shadow for more details about this configuration object.
listenersA map of event names to event listeners. See listeners for more details about this configuration object.

title

Configuration for the series title.

enabledWhether or not the title should be shown.
Default: true
textThe text to show in the title.
colorThe colour to use for the title.
Default: '#000000'
fontStyleThe font style to use for the title.
Default: 'normal'
Options: 'normal', 'italic', 'oblique'
fontWeightThe font weight to use for the title.
Default: 'normal'
Options: 'normal', 'bold', 'bolder', 'lighter', '100', '200', '300', '400', '500', '600', '700', '800', '900'
fontSizeThe font size in pixels to use for the title.
Default: 10
fontFamilyThe font family to use for the title.
Default: 'Verdana, sans-serif'

highlightStyle

Configuration for the highlighting used when the segments are hovered over.

fillThe fill colour of the segments when hovered over.
Default: 'yellow'
strokeThe colour of the stroke around the segments when hovered over.

label

Configuration for the labels used for the segments.

enabledWhether or not the labels should be shown.
Default: true
colorThe colour to use for the labels.
Default: '#000000'
fontStyleThe font style to use for the labels.
Default: 'normal'
Options: 'normal', 'italic', 'oblique'
fontWeightThe font weight to use for the labels.
Default: 'normal'
Options: 'normal', 'bold', 'bolder', 'lighter', '100', '200', '300', '400', '500', '600', '700', '800', '900'
fontSizeThe font size in pixels to use for the labels.
Default: 12
fontFamilyThe font family to use for the labels.
Default: 'Verdana, sans-serif'
offsetDistance in pixels between the callout line and the label text.
Default: 3
minAngleMinimum angle in degrees required for a segment to show a label.
Default: 20

callout

Configuration for the callouts used with the labels for the segments.

colorsThe colours to cycle through for the strokes of the callouts.
Default: ['#aa4520', '#b07513', '#3d803d', '#2d768d', '#2e3e8d', '#6c2e8c', '#8c2d46', '#5f5f5f']
strokeWidthThe width in pixels of the stroke for callout lines.
Default: 1
lengthThe length in pixels of the callout lines.
Default: 10

shadow

Configuration for the shadow used behind the chart series.

enabledWhether or not the shadow is visible.
Default: true
colorThe colour of the shadow.
Default: 'rgba(0, 0, 0, 0.5)'
xOffsetThe horizontal offset in pixels for the shadow.
Default: 0
yOffsetThe vertical offset in pixels for the shadow.
Default: 0
blurThe radius of the shadow's blur, given in pixels.
Default: 5

listeners

A map of event names to event listeners.

nodeClickThe listener to call when a pie slice is clicked.function (params: IParams): any; interface IParams { type: 'nodeClick'; series: PieSeries; datum: any; angleKey: string; radiusKey?: string; }

Next Up

Continue to the next section to learn about histogram series.