Framework:Javascript Data GridAngular Data GridReact Data GridVue Data Grid

React Charts: Pie and Doughnut Series

Pie series are useful for illustrating the numerical proportion of data values. The slices in a pie series show the contribution of individual values to the whole.

For example, a pie series could be used to visualise the market share of each competitor as a proportion of the total.

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 minimal 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:

series: [{
    ...
    label: {
        minAngle: 20
    }
}]

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

series: [{
    ...
    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 we 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 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

Properties available on the AgPieSeriesOptions interface.

angleKey *
string
The key to use to retrieve angle values from the data.
labelKey *
string
The key to use to retrieve label values from the data.
type
'pie'
'pie'
title
AgPieTitleOptions
Configuration for the series title.
title: AgPieTitleOptions;

interface AgPieTitleOptions {
  showInLegend?: boolean;
  // Whether or not the title should be shown. 
  enabled?: boolean;
  padding?: AgChartPaddingOptions;
  // The text to show in the title. 
  text?: string;
  // The font style to use for the title. 
  fontStyle?: FontStyle;
  // The font weight to use for the title. 
  fontWeight?: FontWeight;
  // The font size in pixels to use for the title. 
  fontSize?: FontSize;
  // The font family to use for the title. 
  fontFamily?: FontFamily;
  // The colour to use for the title. 
  color?: CssColor;
}

interface AgChartPaddingOptions {
  // The number of pixels of padding at the top of the chart area. 
  top?: PixelSize;
  // The number of pixels of padding at the right of the chart area. 
  right?: PixelSize;
  // The number of pixels of padding at the bottom of the chart area. 
  bottom?: PixelSize;
  // The number of pixels of padding at the left of the chart area. 
  left?: PixelSize;
}

type PixelSize = number

type FontStyle = 
      'normal' 
    | 'italic' 
    | 'oblique'


type FontWeight = 
      'normal' 
    | 'bold' 
    | 'bolder' 
    | 'lighter' 
    | '100' 
    | '200' 
    | '300' 
    | '400' 
    | '500' 
    | '600' 
    | '700' 
    | '800' 
    | '900'


type FontSize = number

type FontFamily = string

type CssColor = string
label
AgPieSeriesLabelOptions
Configuration for the labels used for the segments.
label: AgPieSeriesLabelOptions;

interface AgPieSeriesLabelOptions {
  // Distance in pixels between the callout line and the label text. 
  offset?: PixelSize;
  // Minimum angle in degrees required for a segment to show a label. 
  minAngle?: number;
  // Whether or not the labels should be shown. 
  enabled?: boolean;
  // The font style to use for the labels. 
  fontStyle?: FontStyle;
  // The font weight to use for the labels. 
  fontWeight?: FontWeight;
  // The font size in pixels to use for the labels. 
  fontSize?: FontSize;
  // The font family to use for the labels. 
  fontFamily?: FontFamily;
  // The colour to use for the labels. 
  color?: CssColor;
}

type PixelSize = number

type FontStyle = 
      'normal' 
    | 'italic' 
    | 'oblique'


type FontWeight = 
      'normal' 
    | 'bold' 
    | 'bolder' 
    | 'lighter' 
    | '100' 
    | '200' 
    | '300' 
    | '400' 
    | '500' 
    | '600' 
    | '700' 
    | '800' 
    | '900'


type FontSize = number

type FontFamily = string

type CssColor = string
callout
AgPieSeriesCalloutOptions
Configuration for the callouts used with the labels for the segments.
callout: AgPieSeriesCalloutOptions;

interface AgPieSeriesCalloutOptions {
  // The colours to cycle through for the strokes of the callouts. 
  colors?: CssColor[];
  // The length in pixels of the callout lines. 
  length?: PixelSize;
  // The width in pixels of the stroke for callout lines. 
  strokeWidth?: PixelSize;
}

type CssColor = string

type PixelSize = number
angleName
string
A human-readable description of the angle values. If supplied, this will be passed to the tooltip renderer as one of the parameters.
radiusKey
string
The key to use to retrieve radius values from the data.
radiusName
string
A human-readable description of the radius values. If supplied, this will be passed to the tooltip renderer as one of the parameters.
labelName
string
A human-readable description of the label values. If supplied, this will be passed to the tooltip renderer as one of the parameters.
fills
CssColor[]
The colours to cycle through for the fills of the segments.
Default: ['#f3622d', '#fba71b', '#57b757', '#41a9c9', '#4258c9', '#9a42c8', '#c84164', '#888888']
fills: CssColor[];

type CssColor = string
strokes
CssColor[]
The colours to cycle through for the strokes of the segments.
Default: ['#aa4520', '#b07513', '#3d803d', '#2d768d', '#2e3e8d', '#6c2e8c', '#8c2d46', '#5f5f5f']
strokes: CssColor[];

type CssColor = string
fillOpacity
Opacity
The opacity of the fill for the segments.
Default: 1
fillOpacity: Opacity;

type Opacity = number
strokeOpacity
Opacity
The opacity of the stroke for the segments.
Default: 1
strokeOpacity: Opacity;

type Opacity = number
strokeWidth
PixelSize
The width in pixels of the stroke for the segments.
Default: 1
strokeWidth: PixelSize;

type PixelSize = number
lineDash
PixelSize[]
Defines how the pie sector strokes are rendered. Every number in the array specifies the length in pixels of alternating dashes and gaps. For example, [6, 3] means dashes with a length of 6 pixels with gaps between of 3 pixels.
lineDash: PixelSize[];

type PixelSize = number
lineDashOffset
PixelSize
The initial offset of the dashed line in pixels.
Default: 0
lineDashOffset: PixelSize;

type PixelSize = number
rotation
number
The rotation of the pie series in degrees.
Default: 0
outerRadiusOffset
PixelSize
The offset in pixels of the outer radius of the series. Used to construct doughnut charts.
Default: 0
outerRadiusOffset: PixelSize;

type PixelSize = number
innerRadiusOffset
PixelSize
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
innerRadiusOffset: PixelSize;

type PixelSize = number
shadow
AgDropShadowOptions
Configuration for the shadow used behind the chart series.
shadow: AgDropShadowOptions;

interface AgDropShadowOptions {
  // Whether or not the shadow is visible. 
  enabled?: boolean;
  // The colour of the shadow. 
  color?: CssColor;
  // The horizontal offset in pixels for the shadow. 
  xOffset?: PixelSize;
  // The vertical offset in pixels for the shadow. 
  yOffset?: PixelSize;
  // The radius of the shadow's blur, given in pixels. 
  blur?: PixelSize;
}

type CssColor = string

type PixelSize = number
tooltip
AgPieSeriesTooltip
Series-specific tooltip configuration.
tooltip: AgPieSeriesTooltip;

interface AgPieSeriesTooltip {
  // Function used to create the content for tooltips. 
  renderer?: (params: AgPieSeriesTooltipRendererParams) => string | AgTooltipRendererResult;
  // Whether or not to show tooltips when the series are hovered over. 
  enabled?: boolean;
}

interface AgPieSeriesTooltipRendererParams {
  labelKey?: string;
  labelName?: string;
  angleKey: string;
  angleValue?: any;
  angleName?: string;
  radiusKey?: string;
  radiusValue?: any;
  radiusName?: string;
  datum: any;
  title?: string;
  color?: CssColor;
}

type CssColor = string

interface AgTooltipRendererResult {
  title?: string;
  content?: string;
}
formatter
Function
(params: AgPieSeriesFormatterParams) => AgPieSeriesFormat
formatter = (
    params: AgPieSeriesFormatterParams
) => AgPieSeriesFormat;

interface AgPieSeriesFormatterParams {
  datum: any;
  fill?: CssColor;
  stroke?: CssColor;
  strokeWidth: PixelSize;
  highlighted: boolean;
  angleKey: string;
  radiusKey?: string;
}

type CssColor = string

type PixelSize = number

interface AgPieSeriesFormat {
  fill?: CssColor;
  stroke?: CssColor;
  strokeWidth?: PixelSize;
}
data
any[]
The data to use when rendering the series. If this is not supplied, data must be set on the chart instead.
visible
boolean
Whether or not to display the series.
showInLegend
boolean
Whether or not to include the series in the legend.
cursor
string
The cursor to use for hovered area markers. This config is identical to the CSS cursor property.
listeners
AgBaseSeriesListeners | {[key: string]: Function}
A map of event names to event listeners.
listeners: AgBaseSeriesListeners | {[key: string]: Function};

interface AgBaseSeriesListeners {
  // The listener to call when a node (marker, column, bar, tile or a pie slice) in the series is clicked. 
  nodeClick: (params: { type: 'nodeClick'; series: any; datum: any; xKey: string; yKey: string; }) => any;
}
highlightStyle
AgSeriesHighlightStyle
Configuration for series markers and series line highlighting when a marker / data point or a legend item is hovered over.
highlightStyle: AgSeriesHighlightStyle;

interface AgSeriesHighlightStyle {
  // Highlight style used for an individual marker when tapped or hovered over. 
  item?: AgSeriesHighlightMarkerStyle;
  // Highlight style used for whole series when one of its markers is tapped or hovered over. 
  series?: AgSeriesHighlightSeriesStyle;
}

interface AgSeriesHighlightMarkerStyle {
  // The fill colour of a marker when tapped or hovered over. Use `undefined` for no highlight. 
  fill?: CssColor;
  // The stroke colour of a marker when tapped or hovered over. Use `undefined` for no highlight. 
  stroke?: CssColor;
  // The stroke width of a marker when tapped or hovered over. Use `undefined` for no highlight. 
  strokeWidth?: PixelSize;
}

type CssColor = string

type PixelSize = number

interface AgSeriesHighlightSeriesStyle {
  enabled?: boolean;
  // The opacity of the whole series (area line, area fill, labels and markers, if any) when another chart series or another stack level in the same area series is highlighted by hovering a data point or a legend item. Use `undefined` or `1` for no dimming. 
  dimOpacity?: Opacity;
  // The stroke width of the area line when one of the markers is tapped or hovered over, or when a tooltip is shown for a data point, even when series markers are disabled. Use `undefined` for no highlight. 
  strokeWidth?: PixelSize;
}

type Opacity = number

Next Up

Continue to the next section to learn about treemap.