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:
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:
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:
The label's callout can be configured to have a different length,
color and strokeWidth, for example:
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:
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.
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.
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
angleKeyRequired | The key to use to retrieve angle values from the data. |
angleName | A human-readable description of the angle values. |
labelKeyRequired | The key to use to retrieve label values from the data. |
labelName | A human-readable description of the label values. |
radiusKey | The key to use to retrieve radius values from the data. |
radiusName | A human-readable description of the radius values. |
dataRequired | The data to use when rendering the series. If this is not supplied, data must be set on the chart instead. |
visible | Whether or not to display the series. Default: true |
showInLegend | Whether or not to include the series in the legend. Default: true |
tooltipEnabled | Whether or not to show tooltips when the series are hovered over. Default: true |
tooltipRenderer | Function used to create the content for tooltips. |
rotation | The rotation of the pie series in degrees. Default: 0 |
innerRadiusOffset | The 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 |
outerRadiusOffset | The offset in pixels of the outer radius of the series. Used to construct doughnut charts. Default: 0 |
title | Configuration for the series title. See title for more details about this configuration object. |
fills | The colours to cycle through for the fills of the segments. Default: ['#f3622d',
'#fba71b',
'#57b757',
'#41a9c9',
'#4258c9',
'#9a42c8',
'#c84164',
'#888888'] |
fillOpacity | The opacity of the fill for the segments. Default: 1 |
strokes | The colours to cycle through for the strokes of the segments. Default: ['#aa4520',
'#b07513',
'#3d803d',
'#2d768d',
'#2e3e8d',
'#6c2e8c',
'#8c2d46',
'#5f5f5f'] |
strokeOpacity | The opacity of the stroke for the segments. Default: 1 |
strokeWidth | The width in pixels of the stroke for the segments. Default: 1 |
highlightStyle | Configuration for the highlighting used when the segments are hovered over. See highlightStyle for more details about this configuration object. |
label | Configuration for the labels used for the segments. See label for more details about this configuration object. |
callout | Configuration for the callouts used with the labels for the segments. See callout for more details about this configuration object. |
shadow | Configuration for the shadow used behind the chart series. See shadow for more details about this configuration object. |
title
Configuration for the series title.
enabled | Whether or not the title should be shown. Default: true |
text | The text to show in the title. |
color | The colour to use for the title. Default: '#000000' |
fontStyle | The font style to use for the title. Default: 'normal'Options: 'normal' | 'italic' | 'oblique' |
fontWeight | The font weight to use for the title. Default: 'normal'Options: 'normal' | 'bold' | 'bolder' | 'lighter' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900' |
fontSize | The font size in pixels to use for the title. Default: 10 |
fontFamily | The font family to use for the title. Default: 'Verdana, sans-serif' |
highlightStyle
Configuration for the highlighting used when the segments are hovered over.
fill | The fill colour of the segments when hovered over. Default: 'yellow' |
stroke | The colour of the stroke around the segments when hovered over. |
label
Configuration for the labels used for the segments.
enabled | Whether or not the labels should be shown. Default: true |
color | The colour to use for the labels. Default: '#000000' |
fontStyle | The font style to use for the labels. Default: 'normal'Options: 'normal' | 'italic' | 'oblique' |
fontWeight | The font weight to use for the labels. Default: 'normal'Options: 'normal' | 'bold' | 'bolder' | 'lighter' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900' |
fontSize | The font size in pixels to use for the labels. Default: 12 |
fontFamily | The font family to use for the labels. Default: 'Verdana, sans-serif' |
offset | Distance in pixels between the callout line and the label text. Default: 3 |
minAngle | Minimum 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.
colors | The colours to cycle through for the strokes of the callouts. Default: ['#aa4520',
'#b07513',
'#3d803d',
'#2d768d',
'#2e3e8d',
'#6c2e8c',
'#8c2d46',
'#5f5f5f'] |
strokeWidth | The width in pixels of the stroke for callout lines. Default: 1 |
length | The length in pixels of the callout lines. Default: 10 |
shadow
Configuration for the shadow used behind the chart series.
enabled | Whether or not the shadow is visible. Default: true |
color | The colour of the shadow. Default: 'rgba(0, 0, 0, 0.5)' |
xOffset | The horizontal offset in pixels for the shadow. Default: 0 |
yOffset | The vertical offset in pixels for the shadow. Default: 0 |
blur | The radius of the shadow's blur, given in pixels. Default: 5 |
Next Up
Continue to the next section to learn about layout.