Pie Chart

Slices of a whole, as a pie or a donut with a value in the middle.

The first series' values as slices, clockwise from twelve o'clock, named by Labels and coloured from the chart colours in order. The tooltip shows a slice's value and its share of the total. DonutChart, in the same file, is a pie with a hole. See Charts for how data, colours and updates work in every chart.

Installation

bash
shellui-native add pie-chart

Platforms: MAUI · Avalonia. Also installs chart, the core every chart shares. The chart colours are theme tokens added with the charts, so in a project whose shell came from an older CLI, run shellui-native update shell first.

Usage

Pie

Rendered with ShellUI for Blazor
<ui:PieChart Labels="ShellUI.CLI, ShellUI.Components, ShellUI.Native.CLI, ShellDocs.CLI, ShellIcons" Description="Downloads by package" HeightRequest="260">
    <ui:ChartSeries Values="275, 200, 187, 173, 90" />
</ui:PieChart>
Avalonia, running in your browser

Donut

DonutChart starts with InnerRadius at 0.6. CenterValue and CenterLabel go in the hole; the ShellUI preview has no centre text. Any PieChart with an InnerRadius above 0 is a donut too.

Rendered with ShellUI for Blazor
<ui:DonutChart Labels="Components, CLI, Docs, Theme" CenterValue="96" CenterLabel="Pull requests" HeightRequest="260">
    <ui:ChartSeries Values="42, 18, 27, 9" />
</ui:DonutChart>
Avalonia, running in your browser

Past the fifth slice the colours repeat, fainter. Gap sets the space between slices in degrees, and ShowLabels writes each value outside its slice.

MAUI and Avalonia

  • MAUI draws the chart in a GraphicsView; give it a HeightRequest. On touch screens a tap or a drag shows the tooltip.
  • Avalonia draws it in Render, in the control's own font; give it a Height. ChartSeries.Color is an Avalonia Color (Color.Parse("#E76E50")).

API

PieChart

XAML children go to Series.

Property Type Default Description
InnerRadius double 0 The hole, as a share of the radius: 0 is a pie, 0.6 a donut.
Gap double 1 Degrees of space between slices.
ShowLabels bool false Writes each slice's value outside it.
CenterValue string — Large text in the hole of a donut.
CenterLabel string — Small muted text under CenterValue.
Labels ChartLabels (MAUI) · ChartLabels? (Avalonia) null The category names along the axis, or the slice names of a pie.
ShowLegend bool true Shows the series (or slice) names with their colours under the chart.
ShowTooltip bool true Shows the values under the pointer (or the finger).
IsAnimated bool true Grows the chart in when it first appears.
ValueFormat string "#,0.##" A .NET number format for axis and tooltip values.
EmptyText string "No data" Shown when there are no values.
Description string — What the chart shows, for screen readers.
Method Description
Refresh() Redraws the chart. Call it after changing the numbers inside a series' Values.
PlayAnimation() Grows the chart in again.

ChartSeries

Property Type Default Description
Name string — Shown in the legend and the tooltip.
Values ChartValues Empty The numbers, one per category. In XAML, a comma-separated list.
Color Color? null Replaces the theme's chart color for this series.

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please retry or reload the page.