- Qt 6.10
- Qt Graphs
- QML Types
- QtGraphs
- PieSeries
- Qt Graphs | Commercial or GPLv3

# PieSeries QML Type

Presents data in pie graphs. More...

Import Statement: | `import QtGraphs`
Inherits: | AbstractSeries

- List of all members, including inherited members
- PieSeries is part of Qt Graphs QML Types for 2D.

## Properties

- angleSpanLabelVisibility : enumeration `(since 6.10)`
- angleSpanVisibleLimit : real `(since 6.10)`
- count : int
- endAngle : real
- holeSize : real
- horizontalPosition : real
- pieSize : real
- startAngle : real
- sum : real
- verticalPosition : real

## Signals

- added(list<PieSlice> slices)
- angleSpanLabelVisibilityChanged(LabelVisibility visibility) `(since 6.10)`
- angleSpanVisibleLimitChanged(real limit) `(since 6.10)`
- clicked(PieSlice slice)
- countChanged()
- doubleClicked(PieSlice slice)
- endAngleChanged()
- holeSizeChanged()
- horizontalPositionChanged()
- pieSizeChanged()
- pressed(PieSlice slice)
- released(PieSlice slice)
- removed(list<PieSlice> slices)
- startAngleChanged()
- sumChanged()
- verticalPositionChanged()

## Methods

- PieSlice append(string label, real value)
- PieSlice at(int index)
- clear()
- PieSlice find(string label)
- bool remove(PieSlice slice)
- bool remove(int index)
- void removeMultiple(int index, int count)
- bool replace(list<PieSlice> slices)
- bool replace(PieSlice oldSlice, PieSlice newSlice)
- bool replace(int index, PieSlice slice)
- bool take(PieSlice slice)

## Detailed Description

A pie series consists of slices that are defined using the PieSlice type. The slices can have any values as the PieSeries type calculates the percentage of a slice compared with the sum of all slices in the series to determine the actual size of the slice in the graph.

Pie size and position on the graph are controlled by using relative values that range from 0.0 to 1.0. These relate to the actual graph rectangle.

By default, the pie is defined as a full pie. A partial pie can be created by setting a starting angle and angle span for the series. A full pie is 360 degrees, where 0 is at 12 o'clock.

The following QML example shows how to create a simple pie graph.

     import QtQuick
     import QtGraphs

     Item {
         id: mainView
         width: 1280
         height: 720

         GraphsView {
             anchors.fill: parent
             theme: GraphsTheme {
                  colorScheme: GraphsTheme.ColorScheme.Dark
                  theme: GraphsTheme.Theme.QtGreen
             }
             PieSeries {
                 id: pieSeries
                 PieSlice {
                     value: 1
                 }
                 PieSlice {
                     value: 2
                 }
             }
         }
     }

See also PieSlice and GraphsView.

## Property Documentation

angleSpanLabelVisibility : enumeration `[since 6.10]`

The mode for label visibility.

The mode which determines which labels will be hidden if they are under the angle span limit set with angleSpanVisibleLimit. Has no effect if angleSpanVisibleLimit has not been set.

Constant | Description
--- | ---
`PieSeries.LabelVisibility.None` | All of the labels of slices with smaller angle span than the angleSpanVisibleLimit will be hidden.
`PieSeries.LabelVisibility.First` | All except the first label of consecutive slices with smaller angle span than the angleSpanVisibleLimit will be hidden. This is the default value.
`PieSeries.LabelVisibility.Even` | Every other label of consecutive slices with smaller angle span than the angleSpanVisibleLimit will be hidden, starting from the second one.
`PieSeries.LabelVisibility.Odd` | Every other label of consecutive slices with smaller angle span than the angleSpanVisibleLimit will be hidden, starting from the first one.

This property was introduced in Qt 6.10.

See also angleSpanVisibleLimit.

angleSpanVisibleLimit : real `[since 6.10]`

The angle span limit for label visibility.

The angle span that will be used as the visibility limit for a slice label. A slice with angle span under this value will change its visibility based on the angleSpanLabelVisibility set to the series. The default value is `0`, which means no slices will be hidden regardless of the angleSpanLabelVisibility.

This property was introduced in Qt 6.10.

See also angleSpanLabelVisibility.

count : int

The number of slices in the series.

endAngle : real

The ending angle of the pie.

A full pie is 360 degrees, where 0 degrees is at 12 o'clock.

The default value is 360.

holeSize : real

The donut hole size.

When setting the pieSize property, this property is adjusted if necessary, to ensure that the hole size is not greater than the pie size.

The default value is 0.0.

horizontalPosition : real

The horizontal position of the pie.

The value is relative to the graph rectangle, so that:

- 0.0 is the absolute left.
- 1.0 is the absolute right.

The default value is 0.5 (center).

See also verticalPosition.

pieSize : real

The pie size.

The value is relative to the graph rectangle, so that:

- 0.0 is the minimum pieSize (pie not drawn).
- 1.0 is the maximum pieSize that can fit the graph.

When setting this property, the holeSize property is adjusted if necessary, to ensure that the hole size is not greater than the pie size.

The default value is 0.7.

startAngle : real

The starting angle of the pie.

A full pie is 360 degrees, where 0 degrees is at 12 o'clock.

The default value is 0.

sum : real

The sum of all slices.

The series keeps track of the sum of all the slices it holds.

verticalPosition : real

The vertical position of the pie.

The value is relative to the graph rectangle, so that:

- 0.0 is the absolute top.
- 1.0 is the absolute bottom.

The default value is 0.5 (center).

See also horizontalPosition.

## Signal Documentation

added(list<PieSlice> slices)

This signal is emitted when the slices specified by slices are added to the series.

Note: The corresponding handler is `onAdded`.

`[since 6.10]` angleSpanLabelVisibilityChanged(LabelVisibility visibility)

This signal is emitted when the angle span limit visible mode has been changed. The visibility parameter holds the new visible mode.

Note: The corresponding handler is `onAngleSpanLabelVisibilityChanged`.

This signal was introduced in Qt 6.10.

`[since 6.10]` angleSpanVisibleLimitChanged(real limit)

This signal is emitted when the angle span limit has been changed. The limit parameter holds the new limit.

Note: The corresponding handler is `onAngleSpanVisibleLimitChanged`.

This signal was introduced in Qt 6.10.

clicked(PieSlice slice)

This signal is emitted when the slice is clicked or tapped.

Note: The corresponding handler is `onClicked`.

countChanged()

This signal is emitted when the slice count changes.

Note: The corresponding handler is `onCountChanged`.

See also count.

doubleClicked(PieSlice slice)

This signal is emitted when the slice is double-clicked or double-tapped. This signal always occurs after clicked.

Note: The corresponding handler is `onDoubleClicked`.

endAngleChanged()

This signal is emitted when the pie end angle changes.

Note: The corresponding handler is `onEndAngleChanged`.

See also endAngle.

holeSizeChanged()

This signal is emitted when the donut hole size changes.

Note: The corresponding handler is `onHoleSizeChanged`.

See also holeSize.

horizontalPositionChanged()

This signal is emitted when the horizontal position changes.

Note: The corresponding handler is `onHorizontalPositionChanged`.

See also horizontalPosition.

pieSizeChanged()

This signal is emitted when the pie size changes.

Note: The corresponding handler is `onPieSizeChanged`.

See also pieSize.

pressed(PieSlice slice)

This signal is emitted when the user clicks or taps the slice and holds down the mouse button or gesture.

Note: The corresponding handler is `onPressed`.

released(PieSlice slice)

This signal is emitted when the user releases a previously pressed mouse button or gesture on the slice.

Note: The corresponding handler is `onReleased`.

removed(list<PieSlice> slices)

This signal is emitted when the slices specified by slices are removed from the series.

Note: The corresponding handler is `onRemoved`.

startAngleChanged()

This signal is emitted when the pie start angle changes.

Note: The corresponding handler is `onStartAngleChanged`.

See also startAngle.

sumChanged()

This signal is emitted when the sum of all slices changes.

Note: The corresponding handler is `onSumChanged`.

See also sum.

verticalPositionChanged()

This signal is emitted when the vertical position changes.

Note: The corresponding handler is `onVerticalPositionChanged`.

See also verticalPosition.

## Method Documentation

PieSlice append(string label, real value)

Adds a new slice with the label label and the value value to the pie.

PieSlice at(int index)

Returns the slice at the position specified by index. Returns null if the index is not valid.

clear()

Removes all slices from the pie.

PieSlice find(string label)

Returns the first slice that has the label label. Returns null if the label is not found.

bool remove(PieSlice slice)

Removes the slice specified by slice from the pie. Returns `true` if the removal was successful, `false` otherwise.

bool remove(int index)

Removes the slice specified by index from the pie. Returns `true` if the removal was successful, `false` otherwise.

void removeMultiple(int index, int count)

Removes a range of slices as specified by the index and count. The call traverses over all slices even if removal of one fails.

bool replace(list<PieSlice> slices)

Completely replaces all current slices with slices. The size does not need to match. Returns false if any of the PieSlice in slices is invalid.

bool replace(PieSlice oldSlice, PieSlice newSlice)

Replaces the slice specified by oldSlice with newSlice. Returns `true` if the removal was successful, `false` otherwise. oldSlice is destroyed if this is successful.

bool replace(int index, PieSlice slice)

Replaces the slice specified by slice from the pie at index. Returns `true` if the replace was successful, `false` otherwise.

bool take(PieSlice slice)

Takes a single slice, specified by slice, from the series. Does not delete the slice object. Returns `true` if successful.