Logo
UI Elements

Horizontal Chart

A bar chart component for comparing numeric values horizontally

Overview

Horizontal Chart renders a set of labeled data points as horizontal bars. It supports custom styling through the Styler system.

At runtime or in the editor, the chart rebuilds itself whenever data changes or when the RectTransform size updates. All visible elements are generated dynamically.


Properties

Data

NameTypeDescription
dataPointsList<DataPoint>List of entries containing label and numeric value

DataPoint

FieldTypeDescription
labelstringDisplay name for the bar
valuefloatHeight or length of the bar

Layout Settings

NameTypeDescription
paddingRectOffsetInner padding around chart content
gridToBarsOffsetfloatDistance between grid and bars
barSpacingfloatVertical spacing between bars
barCornerRadiusfloatRadius used for rounded bar corners
barSpriteSpriteCustom sprite used for bars (optional)
labelWidthfloatWidth of left side label area
valueWidthfloatWidth of right side value area

Grid Settings

NameTypeDescription
showGridbool显示 vertical grid lines
verticalGridLinesintNumber of divisions in the grid
gridLineThicknessfloatThickness of grid lines

Axis Settings

NameTypeDescription
showAxisboolShows X and Y axes
axisThicknessfloatThickness of axis lines

Value Settings

NameTypeDescription
showValuesboolShows value text next to each bar
valueFontSizefloatFont size for value text

Styling

NameTypeDescription
stylingSourceStylingSourceSource used for styler color lookup
stylerPresetStylerPresetPreset used when stylingSource is StylerPreset
gridColorColorMappingGrid coloring
axisColorColorMappingAxis coloring
barColorColorMappingBar fill coloring
labelColorColorMappingLabel coloring
valueFontFontMappingFont for value text
labelFontFontMappingFont for label text
labelFontSizefloatSize of label text

Public Methods

NameParametersDescription
DrawChart()NoneClears and rebuilds the entire chart
UpdateData(newData)List<DataPoint>Replaces all data points and redraws
AddDataPoint(label, value)string, floatAdds a new entry
RemoveDataPoint(index)intRemoves an entry
ClearData()NoneClears all points
SetDataPoint(index, label, value)int, string, floatUpdates a single entry
SetDataPoint(point, label, value)DataPoint, string, floatUpdates an existing item reference
ShowValuespropertyEnables or disables value labels

Code Example

HorizontalChartExample.cs
using UnityEngine;
using Evo.UI;

public class HorizontalChartExample : MonoBehaviour
{
    public HorizontalChart chart;

    void Start()
    {
        // Add some data
        chart.AddDataPoint("Apples", 50);
        chart.AddDataPoint("Oranges", 75);
        chart.AddDataPoint("Bananas", 30);

        // Modify data
        chart.SetDataPoint(1, "Oranges", 90);

        // Hide value labels
        chart.ShowValues = false;

        // Replace all data
        chart.UpdateData(new()
        {
            new HorizontalChart.DataPoint("Product A", 120),
            new HorizontalChart.DataPoint("Product B", 80)
        });

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

On this page