Evo uiUi elements
Pie Chart
A dynamic pie and donut chart
This page documents Evo UI v1. For the current version, see Evo UI v2. Upgrading? Read the migration guide.
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
| Name | Type | Description |
|---|---|---|
dataPoints | List<DataPoint> | Label, value, and color entries |
DataPoint
| Field | Type | Description |
|---|---|---|
label | string | Category label |
value | float | Value used to calculate slice percentage |
color | Color | Color for slice rendering |
tableKey (optional) | string | Localization key |
Chart Settings
| Name | Type | Description |
|---|---|---|
innerRadius | float | Turns chart into donut shape when greater than zero |
startAngle | float | Starting angle for first slice |
segments | int | Resolution used to build slices |
enableAntiAliasing | bool | Enables edge smoothing |
antiAliasingWidth | float | Width of AA gradient |
Border Settings
| Name | Type | Description |
|---|---|---|
drawBorder | bool | Draws outer (and inner if donut) border |
borderWidth | float | Thickness of border rings |
Label Settings
| Name | Type | Description |
|---|---|---|
showLabels | bool | Displays labels inside slices |
showPercentages | bool | Shows percentage instead of value |
labelFontSize | float | Font size for labels |
drawLabelBackground | bool | Draws a background behind label |
labelBackgroundSprite | Sprite | Sprite for label background |
labelBackgroundPPU | float | PPU multiplier for background |
labelPadding | Vector2 | Padding around label text |
Legend Settings
| Name | Type | Description |
|---|---|---|
showLegend | bool | Toggles legend |
legendContainer | RectTransform | Parent for generated legend items |
legendItemHeight | float | Height for each legend row |
legendColorBoxSize | float | Size of color square |
legendColorBoxSprite | Sprite | Optional sprite for color boxes |
legendFontSize | float | Font size of legend text |
Styling
| Name | Type | Description |
|---|---|---|
stylingSource | StylingSource | Custom or StylerPreset |
stylerPreset | StylerPreset | Used for Styler based styling |
borderColor | ColorMapping | Color for chart border |
labelColor | ColorMapping | Color for label text |
labelBackgroundColor | ColorMapping | Color for label background |
legendTextColor | ColorMapping | Color for legend text |
labelFont | FontMapping | Font for label text |
legendFont | FontMapping | Font for legend entries |
Public Methods
| Name | Parameters | Description |
|---|---|---|
DrawChart() | None | Rebuilds the entire chart |
UpdateData(newData) | List<DataPoint> | Replaces all data and redraws |
AddDataPoint(label, value, color) | string, float, Color | Adds new slice |
RemoveDataPoint(index) | int | Removes slice |
ClearData() | None | Clears 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) | float | Updates donut radius and redraws |
ShowLabels | bool | Enables or disables labels |
ShowLegend | bool | Enables or disables legend |
Code Example
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();
}
}