Skip to content

ChartGuruElement

ClassChartGuruChartGuru
public class ChartGuruElement : VisualElement, IChartHost

UI Toolkit chart host. Like ChartGraphic it shows a ChartDefinition or a ChartAsset with data from a ChartDataAsset, a ChartDataSource or code, and draws through the shared ChartRenderer. In UXML, chart and data reference assets and chart-type sets the type of the element's own definition.

The chart lays out in panel points and renders into a UnityEngine.RenderTexture sized to the content rect in pixels, emitted as one textured quad through UITKMeshDrawSink. Axis, data and legend labels, titles and tooltips are pooled UI Toolkit elements on an overlay, placed from the same layout ChartGraphic uses.

public ChartGuruElement()

Creates an element that shows a bar chart definition of its own.

public void Rebuild()

Recompiles the chart from the definition and its data now.

public void SetDirty()

Recompiles the chart on the next scheduler tick, merging repeated requests.

public void Dispose()

Releases renderer, tooltip, chart, schedule, and texture resources owned by this element.

public void SetChart(Chart chart)

Shows a chart built in code. The chart is runtime state: it is not saved and replaces the definition until ChartGuruElement.ClearChart() is called.

Parameters

Name Type
chart ChartGuru.Chart
public void ClearChart()

Returns from a chart set in code to the definition.

public void SetData(ChartDataFrame data, bool shapeChanged = true)

Shows data instead of the bound data, mapped by the definition's layers. The data is runtime state and is not saved; pass null to return to the bound data. Pass shapeChanged false when the data keeps the columns, row count and categories shown, so the chart's values update in place.

Parameters

Name Type
data ChartGuru.ChartDataFrame
shapeChanged System.Boolean
public void ClearData()

Returns from data set in code to the bound data.

public void MorphTo(ChartType type, ChartMorphStyle? style = null)

Changes the chart type and morphs the live chart into it, bars into pies included; types without a 2D morph recipe, such as 3D types, rebuild instead. A chart set from code changes its own type.

Parameters

Name Type
type ChartGuru.ChartType
style System.Nullable{ChartGuru.ChartMorphStyle}
public void ReplayEntryAnimation(Animation? animation = null)

Replays the entry animation, using the chart's animation when none is given.

Parameters

Name Type
animation System.Nullable{ChartGuru.Animation}
public void ClearSelection()

Clears the selection on the runtime chart.

public void ResetViewport()

Restores both axes to their configured visible domains.

public ChartHostContent Content { get; }

What this element shows: its own definition or a chart asset, plus bound data.

Returns

ChartGuru.ChartHostContent

public ChartDefinition Definition { get; }

The definition to read or edit: the asset's when one is assigned, otherwise the element's own. In Play Mode an element that uses a chart asset returns its own copy, like Renderer.material, so runtime edits never change the asset. Call ChartGuruElement.Rebuild() after editing it.

Returns

ChartGuru.ChartDefinition

public ChartDefinition InlineDefinition { get; set; }

The element's own definition, used when no chart asset is assigned. UXML saves only its chart type.

Returns

ChartGuru.ChartDefinition

public ChartAsset DefinitionAsset { get; set; }

Shared chart asset. When set, it replaces the element's own definition. UXML: chart.

Returns

ChartGuru.ChartAsset

public ChartDataAsset DataAsset { get; set; }

Shared data table bound to the chart. UXML: data.

Returns

ChartGuru.ChartDataAsset

public ChartDataSource DataSource { get; set; }

Live data source bound to the chart, such as a CSV file, a web endpoint or mock data. UXML cannot reference scene objects, so assign it from code or with a UIToolkitChartBinder.

Returns

ChartGuru.ChartDataSource

public ChartType InlineChartType { get; set; }

Chart type of the element's own definition, used when no chart asset is assigned. UXML: chart-type.

Returns

ChartGuru.ChartType

public ChartDataFrame Data { get; set; }

Data shown instead of the bound data, for code and Unity 6 runtime data binding. Null returns to the bound data. Not saved.

Returns

ChartGuru.ChartDataFrame

public ChartType ChartType { get; set; }

The displayed chart type. Setting it morphs the live chart when a 2D morph recipe exists.

Returns

ChartGuru.ChartType

public Chart Chart { get; }

The runtime chart being drawn.

Returns

ChartGuru.Chart

public ChartProxy Proxy { get; }

Hit testing and coordinate conversion for the runtime chart.

Returns

ChartGuru.ChartProxy

public bool HasRuntimeChart { get; }

True while a chart set from code replaces the definition.

Returns

System.Boolean

public bool IsShowingPreviewData { get; }

True while generated preview data is shown because nothing is bound and the definition has no rows.

Returns

System.Boolean

public ChartTooltipState TooltipState { get; }

A snapshot of tooltip visibility, pin state, hit, pointer position, retained content, and version, refreshed as interactions or presentation change.

Returns

ChartGuru.ChartTooltipState

public int SelectedIndex { get; }

Index of the selected mark, or -1.

Returns

System.Int32

public int HoveredIndex { get; }

Index of the hovered mark, or -1.

Returns

System.Int32

public event Action<int, DataPoint> DataPointClicked

Raised when a data point is clicked or tapped.

Returns

System.Action{System.Int32,ChartGuru.DataPoint}

public event Action<int, DataPoint> DataPointSelected

Raised when a data point becomes selected.

Returns

System.Action{System.Int32,ChartGuru.DataPoint}

public event Action<int, DataPoint> DataPointHovered

Raised when the pointer moves onto a data point.

Returns

System.Action{System.Int32,ChartGuru.DataPoint}

public event Action SelectionCleared

Raised when the selection is cleared.

Returns

System.Action

public event Action<ChartTooltipState> TooltipChanged

Raised when the tooltip content or visibility changes.

Returns

System.Action{ChartGuru.ChartTooltipState}

public event Action<ChartTooltipState> TooltipPresentationChanged

Raised when the tooltip moves, including content changes.

Returns

System.Action{ChartGuru.ChartTooltipState}

public event Action<int> OnSelectionChanged

Raised with the selected mark index after pointer or programmatic selection changes.

Returns

System.Action{System.Int32}

public event Action<int> OnHoverChanged

Raised with the hovered mark index, or -1 after the pointer leaves all marks.

Returns

System.Action{System.Int32}

public event Action<ChartType> OnMorphComplete

Raised with the new chart type after an animated morph reaches its target.

Returns

System.Action{ChartGuru.ChartType}