UGTK / Toolkit / Gameplay Systems / Line Chart (3D) Completed
Line Chart
Summary
Builds a uGUI line chart at edit-time or runtime: axis grid, dashed gridlines, axis labels (TextMeshPro) and coloured data lines with points, all generated as Image/TextMeshProUGUI children of a RectTransform.
Note: a separate, larger
Mn_LineChartalso exists underUIModule/LineChart(925 lines, namespaced). This GameplaySystems version is a distinct, simpler implementation (~547 lines, no namespace) — not the same file.
Content
Modules Dependencies
This module has no hard UGTK dependencies. It relies on Unity uGUI (UnityEngine.UI.Image) and TextMeshPro (TMPro) for axis labels.
Setup
Add Mn_LineChart to a UI RectTransform (under a Canvas), fill the vertical/horizontal axis lists and the line data, then press Generate Chart in the Inspector (custom editor) or call GenerateChart().
How To Use
- Add
Mn_LineChartto a UI object; it requires aRectTransformand runs with[ExecuteAlways]. - Populate
verticalAxis(numeric labels; the first and last define the value range) andhorizontalAxis(string labels), then addS_Lineentries (name,color, list of string point values). - Call
GenerateChart()— or click the Generate Chart button added byMn_LineChart_Editor— to rebuild all children (grid, axes, labels, segments, points). Non-numeric or empty points are skipped. - Configure appearance via the Inspector: spacing, thickness, colours, dash length/gap, margins, label offsets, font size and an optional
TMP_FontAsset(falls back to the TMP default font). - Runtime setters
SetVerticalAxis,SetHorizontalAxis,SetLinesvalidate and replace the data (vertical values are parsed and sorted ascending) before you regenerate. Mn_LineChartDebugis a sample helper exposingSetVertical/SetHorizontal/SetLineswith hard-coded demo data.
Testing Scene
Open LineChart in the module's Debug/ folder and select Canvas > LineChart Scroll >
Content. Everything happens with the editor stopped: change a value, press Generate Chart,
and the Game view redraws.
What to do, in order:
- Press Generate Chart with the sample data, then change Line Thickness and Point Size and press it again: the whole plot is rebuilt from the serialized lists, so nothing is cached between one press and the next.
- Feed it a single point, then two points with the same X.
- Feed it values that are all identical.
- Feed it a few hundred points.
Steps 2 and 3 are the degenerate cases every chart gets wrong at least once: a single point has no line to draw, and a flat series has zero range, which is a division by zero waiting to happen when the axis is scaled.
Technical Info
- Mn_LineChart:
[ExecuteAlways]MonoBehaviourthat generates the chart; holds axis lists, theS_Linestruct list and layout settings; exposesGenerateChart()and theSet*data setters. Parses values with invariant/current culture and maps them onto the plane withInverseLerp/Lerp. - Mn_LineChart_Editor (Editor): custom inspector adding the Generate Chart button with full-hierarchy Undo.
- Mn_LineChartDebug (Debug): sample component that feeds demo axis/line data to a referenced chart.
© 2026 Marcello De Bonis. All rights reserved
UGTKengine within an engine


