Skip to content

ChartDataSourceAsset

ClassChartGuruChartGuru
[CreateAssetMenu(menuName = "ChartGuru/Chart Data Source (Asset)", fileName = "ChartDataSource")]
public class ChartDataSourceAsset : ScriptableObject, IChartGuruElementDataSource

ScriptableObject-based data source for ChartGuru.ChartGuruElement.

Created via Assets > Create > ChartGuru > Chart Data Source (Asset), populated from the Inspector, and assigned to `ChartGuru.ChartGuruElement.DataSource` — at runtime in C#, via UXML data-source="…" (Unity 2023.2+), or via a [ChartGuru.UIToolkitChartBinder](/tools/chartguru/api/chartguru-uitoolkitchartbinder/).

Carries only the data surface (labels + values per series). Visual configuration (chart type, theme, animation, …) is owned by the element's `ChartGuru.ChartAuthoringState`. The same asset can drive multiple charts of different types simultaneously.

Call `ChartGuru.ChartDataSourceAsset.MarkChanged` after mutating `ChartGuru.ChartDataSourceAsset.SeriesList` at runtime to push updates to every subscribed element.

public void MarkChanged()

Notify every subscribed element that the data set changed. Call this after runtime mutation of ChartGuru.ChartDataSourceAsset.SeriesList — Inspector edits trigger it automatically via ChartGuru.ChartDataSourceAsset.OnValidate.

public void SetData(string[] labels, float[] values)

Replace all data with labelled values in a single series.

Parameters

Name Type
labels System.String[]
values System.Single[]
public void SetData(float[] values)

Replace all data with Y-only values in a single series. Labels are auto-generated.

Parameters

Name Type
values System.Single[]
public void SetData(Dictionary<string, float> data)

Replace all data from a dictionary in a single series.

Parameters

Name Type
data System.Collections.Generic.Dictionary{System.String,System.Single}
public void AddEntry(string label, float value)

Add an entry to the first (or only) series. Creates a default series if none exist.

Parameters

Name Type
label System.String
value System.Single
public void AddEntry(string seriesName, string label, float value)

Add an entry to a named series. Creates the series if it does not exist.

Parameters

Name Type
seriesName System.String
label System.String
value System.Single
public void RemoveEntryAt(int seriesIndex, int entryIndex)

Remove the entry at the given index within the specified series.

Parameters

Name Type
seriesIndex System.Int32
entryIndex System.Int32
public void ClearData()

Clear all series and entries.

PopulateChart(Chart, ChartType, ChartAuthoringStyleOptions)

Section titled “PopulateChart(Chart, ChartType, ChartAuthoringStyleOptions)”
public void PopulateChart(Chart chart, ChartType chartType, ChartAuthoringStyleOptions style)

Push the current data set onto chart. The data source is responsible for clearing existing marks and adding new ones that match chartType. The supplied style snapshot lets the source pick mark-level properties (line width, bar corner radius, stacking method, …) consistently with the element’s authoring state.

Parameters

Name Type Description
chart ChartGuru.Chart The element’s underlying chart instance.
chartType ChartGuru.ChartType The chart type currently authored on the element.
style ChartGuru.ChartAuthoringStyleOptions Authoring style snapshot from the element. Never null.

public ChartDataSourceAsset()

public List<ChartDataSourceAsset.Series> SeriesList { get; }

All serialized series. Mutate freely at runtime, then call ChartGuru.ChartDataSourceAsset.MarkChanged.

Returns

System.Collections.Generic.List{ChartGuru.ChartDataSourceAsset.Series}

public int Count { get; }

Number of entries across all series.

Returns

System.Int32

public event Action DataChanged

Raised whenever the source’s data set changes and consumers should call ChartGuru.IChartGuruElementDataSource.PopulateChart(ChartGuru.Chart%2cChartGuru.ChartType%2cChartGuru.ChartAuthoringStyleOptions) again. May fire on any thread that mutates the source; implementations should ensure they only marshal back to the main thread before invoking it.

Returns

System.Action