Rendering Paths
All 2D rendering paths share the same Chart model and renderer. Choose the host that matches where the chart appears.
Host | Use it when |
|---|---|
ChartGraphic | The chart belongs in a uGUI Canvas, including Screen Space Overlay, Screen Space Camera, or World Space Canvas. |
ChartComponent | You want a quick scene component for prototyping without building a full Canvas workflow. |
ChartGuruElement | The UI is built with UI Toolkit, UXML, USS, or Unity data binding. |
Chart Designer / Chart Gallery | You need an editor preview or a visual authoring surface. |
UI Toolkit
ChartGuruElement is a VisualElement with UXML attributes for chart type, title, labels, axes, legend, marks, data source, and interaction. Use UIToolkitChartBinder when a scene component should feed a named element inside a UIDocument.
<UXML xmlns="UnityEngine.UIElements" xmlns:cg="ChartGuru">
<cg:ChartGuruElement
chart-type="Line"
chart-title="Sales Trend"
legend-position="Bottom"
show-data-labels="true"
animate-on-start="true" />
</UXML>
Sharing Data and Images
Use ChartDataExporter.ToCsv(chart) or ToJson(chart) to obtain deterministic semantic data, or WriteCsv and WriteJson to save it to an application-chosen path. Exports describe the chart's marks and their meaning, including X/Y/Z values where applicable; they are separate from a rendered image.
For a Canvas ChartGraphic, use EncodeOutputPng(includeText: true) for PNG bytes or SaveOutputPng(path, includeText: true) for a file. Including text composes titles, axes, legends and data labels with the chart. Choose includeText: false when only the chart geometry is wanted. Use a writable application path such as Application.persistentDataPath on supported targets and provide truthful save feedback in the surrounding UI.