Logo
UI Elements

Pie Chart

Show proportions as a pie or donut with labels and a legend

Overview

Pie Chart divides a circle according to the relative values of its data points. A nonzero inner-radius ratio creates a donut chart.

Preview

Usage

Create a Pie Chart and add labeled values with colors.

Choose pie or donut appearance with Inner Radius Ratio.

Enable labels, percentages, and the legend as needed.

Assign a legend container when displaying a separate legend.


Tips

  • Minimum Label Percentage hides labels for very small slices, while Legend Values chooses percentage, value, both, or label-only display.
  • Inner Radius Ratio sets the hole as a fraction of the outer radius: 0 makes a full pie and 0.6 leaves a ring around a hole that is 60% of the radius.
  • Spacing under Style > Slices adds a gap between slices, in UI units. The gap keeps the same width from the center to the edge, so slices narrower than the gap disappear into it.

Public API

Use PieChart in the Evo.UI namespace.

Properties

Setting a property refreshes the chart. After editing dataPoints or a shape settings field directly, call DrawChart().

NameTypeDescription
InnerRadiusRatiofloatHole radius as a fraction of the outer radius, from 0 to 0.95. Zero draws a solid pie.
StartAnglefloatAngle of the first slice in degrees counterclockwise from the right. Wraps at 360.
SegmentsintMinimum tessellation detail, from 3 to 512.
PercentageDecimalsintDecimal places in slice and legend percentages, from 0 to 4.
SliceSpacingfloatGap between adjacent slices in local UI units. The gap keeps the same width from the center outward.
EdgeSmoothingfloatSmoothing width in screen pixels for the silhouette, outline and slice edges, from 0 to 3.
DrawBorderboolDraws an outline along the inner and outer circumference.
BorderWidthfloatOutline width in local UI units. Clamped to the available thickness.
BorderAlignmentBorderPlacementPlaces the outline inside, centered on, or outside the radii.
ShowLabelsboolShows labels.
ShowPercentagesboolShows percentages on slices. Disable to show formatted values.
MinimumLabelPercentagefloatHides labels below this percentage, from 0 to 100.
LabelFontSizefloatSlice label font size.
DrawLabelBackgroundboolDraws a procedural background behind each label.
LabelPaddingVector2Horizontal and vertical inset on each side of a label background, in local UI units.
LabelCornerRadiusfloatUniform label background corner radius.
ShowLegendboolShows the legend in the assigned container.
LegendContainerRectTransformContainer for this chart's generated legend.
LegendValuesLegendValueModeShows percentages, values, both, or category names only in the legend.
HideZeroValueLegendItemsboolOmits legend rows whose rendered value is zero.
LegendFontSizefloatFont size used by legend labels.
LegendItemHeightfloatHeight of each legend row in local UI units.
LegendColorBoxSizefloatSide length of each legend color swatch in local UI units.
LegendCornerRadiusfloatUniform swatch corner radius, in pixels or percent according to Legend Shape radius mode.
DisplayFormatNumberDisplayFormatNumeric format used by value and scale labels.

Fields

NameTypeDescription
dataPointsList<DataPoint>Labeled slice values and colors.
labelShapeShapeSettingsLabel background corner, softness and outline settings.
legendShapeShapeSettingsLegend swatch corner, softness and outline settings.

Methods

NameParametersDescription
SetInnerRadiusRatio()float ratioSets the donut ratio.
UpdateData()List<DataPoint> newDataReplaces all slice data.
AddDataPoint()string label, float value, Color colorAdds a label, value, and color.
SetDataPoint()int index, string label, float value, Color? color = nullUpdates a slice, optionally changing its color.
SetDataPoint()DataPoint data, string label, float value, Color? color = nullUpdates a slice, optionally changing its color.
RemoveDataPoint()int indexRemoves a slice by index.
ClearData()NoneClears all slices.
DrawChart()NoneRefreshes the chart.

Example

PieChartExample.cs
using UnityEngine;
using Evo.UI;

public class PieChartExample : MonoBehaviour
{
    [SerializeField] private PieChart target;

    private void Start()
    {
        target.ClearData();
        target.InnerRadiusRatio = 0.6f;
        target.SliceSpacing = 4f;
        target.AddDataPoint("Used", 65f, Color.cyan);
        target.AddDataPoint("Free", 35f, Color.gray);

        // Call this when modifying the data entries directly
        target.DrawChart();
    }
}

On this page