PieChart is a VisualElement that renders a multi-segment circular chart from parallel Values and Colors lists. Values are normalized to total 100% — pass raw counts, not percentages. Each segment exposes a center point you can use for label placement.

Pie Chart

Setup

UXML:

html
<luna:PieChart background-color="#222222" outline-color="#FFFFFF" outline-width="4" gap-width="2" />

Populate from C# (Values and Colors are List<float> / List<Color>):

csharp
var pie = root.Q<PieChart>(); pie.Values = new List<float> { 35f, 25f, 40f }; pie.Colors = new List<Color> { Color.red, Color.green, Color.blue };

Inspector (UxmlAttributes)

AttributeTypeDescription
ValuesList<float>Raw segment sizes. Auto-normalized; mismatched lengths just paint missing segments black.
ColorsList<Color>Per-segment fill colors.
BackgroundColorColorDisc background, drawn beneath segments (default white). The separators between segments use it too.
OutlineColorColorOuter-ring stroke color (default white).
OutlineWidthfloatOuter-ring stroke width in pixels (default 10).
GapWidthfloatWidth of the radial separator drawn between segments (default 0.1). Set to 0 to disable.

In UXML the attributes are written in kebab case: background-color, outline-color, outline-width, gap-width.

Theming (USS)

Each look attribute has a USS custom property. A sheet that sets one wins over the attribute; where no sheet sets it, the attribute (or its default) draws, so a chart nobody themes looks as before. Widths are plain numbers in pixels: write 4, not 4px (Unity warns about a value with a unit and the attribute draws instead).

Custom propertyOverrides
--pie-chart-background-colorBackgroundColor
--pie-chart-outline-colorOutlineColor
--pie-chart-outline-widthOutlineWidth
--pie-chart-gap-widthGapWidth

The chart carries the pie-chart class. Set the properties in a rule that matches the chart itself. UI Toolkit reads a component's custom properties only from the rules that match that element, so a value set on a parent does not reach the chart; scope with a descendant selector instead (.my-screen .pie-chart):

css
.pie-chart { --pie-chart-background-color: #E2DCF6; --pie-chart-outline-color: #7B5FD6; --pie-chart-outline-width: 4; --pie-chart-gap-width: 2; }

The segment colors stay in Colors: they are data, not theme.

API

Properties

PropertyTypeDescription
SegmentCentersList<Vector2>Read-only element-space (local) centers of each rendered segment (positioned at 2/3 of the radius along the segment's mid-angle).
ResolvedBackgroundColor / ResolvedOutlineColorColorWhat the chart draws with: the sheet's value when one is set, else the attribute.
ResolvedOutlineWidth / ResolvedGapWidthfloatSame, for the widths.

Events

EventDescription
OnSegmentCentersChangedFires after each repaint. Subscribe to update overlay labels positioned at SegmentCenters[i].

See also

  • ProgressBar — single-value variant with brand-themed presets

Settings

Theme

Light

Contrast

Material

Dark

Dim

Material Dark

System

Sidebar(Light & Contrast only)

Light
Dark

Font Family

DM Sans

Wix

Inclusive Sans

AR One Sans

Direction

LTR
RTL