Logo
UI Elements

Pie Chart

A dynamic pie and donut chart

Overview

Pie Chart renders a circular graph divided into colored slices based on numeric values. It supports donut mode (inner radius), percentage or value labels, background labels, and a fully dynamic legend.

The chart is generated from scratch each time the data or layout changes. All slices, labels, backgrounds, borders, and legend items are built at runtime and updated when the RectTransform size changes.


Properties

Data

NameTypeDescription
dataPointsList<DataPoint>Label, value, and color entries

DataPoint

FieldTypeDescription
labelstringCategory label
valuefloatValue used to calculate slice percentage
colorColorColor for slice rendering
tableKey (optional)stringLocalization key

Chart Settings

NameTypeDescription
innerRadiusfloatTurns chart into donut shape when greater than zero
startAnglefloatStarting angle for first slice
segmentsintResolution used to build slices
enableAntiAliasingboolEnables edge smoothing
antiAliasingWidthfloatWidth of AA gradient

Border Settings

NameTypeDescription
drawBorderboolDraws outer (and inner if donut) border
borderWidthfloatThickness of border rings

Label Settings

NameTypeDescription
showLabelsboolDisplays labels inside slices
showPercentagesboolShows percentage instead of value
labelFontSizefloatFont size for labels
drawLabelBackgroundboolDraws a background behind label
labelBackgroundSpriteSpriteSprite for label background
labelBackgroundPPUfloatPPU multiplier for background
labelPaddingVector2Padding around label text

Legend Settings

NameTypeDescription
showLegendboolToggles legend
legendContainerRectTransformParent for generated legend items
legendItemHeightfloatHeight for each legend row
legendColorBoxSizefloatSize of color square
legendColorBoxSpriteSpriteOptional sprite for color boxes
legendFontSizefloatFont size of legend text

Styling

NameTypeDescription
stylingSourceStylingSourceCustom or StylerPreset
stylerPresetStylerPresetUsed for Styler based styling
borderColorColorMappingColor for chart border
labelColorColorMappingColor for label text
labelBackgroundColorColorMappingColor for label background
legendTextColorColorMappingColor for legend text
labelFontFontMappingFont for label text
legendFontFontMappingFont for legend entries

Public Methods

NameParametersDescription
DrawChart()NoneRebuilds the entire chart
UpdateData(newData)List<DataPoint>Replaces all data and redraws
AddDataPoint(label, value, color)string, float, ColorAdds new slice
RemoveDataPoint(index)intRemoves slice
ClearData()NoneClears all slices
SetDataPoint(index, label, value, color?)int, string, float, Color?Updates a specific slice
SetDataPoint(data, label, value, color?)DataPoint, string, float, Color?Updates by reference
SetInnerRadius(newRadius)floatUpdates donut radius and redraws
ShowLabelsboolEnables or disables labels
ShowLegendboolEnables or disables legend

Code Example

PieChartExample.cs
using UnityEngine;
using Evo.UI;

public class PieChartExample : MonoBehaviour
{
    public PieChart chart;

    void Start()
    {
        // Modify data
        chart.AddDataPoint("Apples", 40, new Color(1f, 0.3f, 0.3f));
        chart.AddDataPoint("Bananas", 25, new Color(1f, 0.9f, 0.2f));
        chart.SetDataPoint(1, "Bananas", 30);

        // Turn into a donut chart
        chart.SetInnerRadius(60f);

        // Toggle legend
        chart.ShowLegend = true;

        // Redraw chart
        chart.DrawChart();
    }
}

On this page