Skip to content

Chart

Data visualization chart widget supporting bar and line visualizations, axes, and interactive hover tooltips.

Overview

Chart extends Sparkline into a full-featured data chart component. Supports switching between LINE and BAR rendering modes, coordinate axes, value labels, and hover bar highlighting.

Bar Chart

Chart latencyChart = new Chart()
        .type(Chart.Type.BAR)
        .values(List.of(12, 18, 15, 25, 14))
        .barColor(Color.CYAN);

API

API

Method Description
axisColor() Returns mutable color of chart coordinate axes.
barColor() Returns mutable color of bars in bar chart mode.
type(Type) Configures visualization mode (LINE or BAR).
Chart() Creates a chart with its default size and line mode.

Chart::axisColor()

Axis Color

Returns mutable color of chart coordinate axes.

Returns MutableColor: The mutable RGBA axis color; changing it overrides the style value..

Chart::barColor()

Bar Color

Returns mutable color of bars in bar chart mode.

Returns MutableColor: The mutable RGBA bar color; changing it overrides the style value..

Chart::type(Type)

Chart Type

Configures visualization mode (LINE or BAR).

Parameter Type Description
type Type Rendering mode; null selects LINE.

Returns Chart: This chart for fluent configuration..

Chart()

Create a chart

Creates a chart with its default size and line mode.

Data

Method Description
values(List) Replaces the plotted values from a Number list.
values(float[]) Replaces the plotted values without boxing numeric inputs.
categories(List) Sets optional labels aligned by index with the plotted values.
categories() Returns the current immutable category-label list.

Chart::values(List)

Set chart values

Replaces the plotted values from a Number list.

Parameter Type Description
values List Values in data order; null clears the series and null entries are treated as zero.

Returns Chart: This chart for fluent configuration..

Chart::values(float[])

Set chart values from floats

Replaces the plotted values without boxing numeric inputs.

Parameter Type Description
data float[] Values in data order; null clears the series and non-finite values create gaps.

Returns Chart: This chart for fluent configuration..

Chart::categories(List)

Set category labels

Sets optional labels aligned by index with the plotted values.

Parameter Type Description
categories List Category labels in value order; null or an empty list hides labels.

Returns Chart: This chart for fluent configuration..

Chart::categories()

Get category labels

Returns the current immutable category-label list.

Returns List: An immutable list of category labels, empty when labels are not configured..

Appearance

Method Description
type() Returns the active line or bar rendering mode.
hoveredBarColor() Returns the mutable color used for the hovered bar.
barValuesVisible(boolean) Enables or hides numeric labels rendered on bars.
barValuePlacement(BarValuePlacement) Selects where numeric labels appear relative to each bar.

Chart::type()

Get chart type

Returns the active line or bar rendering mode.

Returns Type: The current rendering mode; defaults to LINE..

Chart::hoveredBarColor()

Get hovered bar color

Returns the mutable color used for the hovered bar.

Returns MutableColor: The mutable RGBA hovered-bar color..

Chart::barValuesVisible(boolean)

Show bar values

Enables or hides numeric labels rendered on bars.

Parameter Type Description
barValuesVisible boolean True to render bar value labels.

Returns Chart: This chart for fluent configuration..

Chart::barValuePlacement(BarValuePlacement)

Place bar value labels

Selects where numeric labels appear relative to each bar.

Parameter Type Description
barValuePlacement BarValuePlacement Placement mode; null resets to HEAD.

Returns Chart: This chart for fluent configuration..

Custom Rendering

Method Description
barRenderer(BarRenderer) Installs or clears a custom bar renderer.
barValueRenderer(BarValueRenderer) Installs or clears a custom bar-value label renderer.
barTooltipRenderer(BarTooltipRenderer) Installs or clears a custom tooltip renderer for hovered bars.
renderer(WidgetRender) Sets the widget-level renderer used for chart rendering hooks.

Chart::barRenderer(BarRenderer)

Customize bar rendering

Installs or clears a custom bar renderer.

Parameter Type Description
barRenderer BarRenderer Custom renderer callback, or null to use the built-in bar rendering.

Returns Chart: This chart for fluent configuration..

Chart::barValueRenderer(BarValueRenderer)

Customize bar value labels

Installs or clears a custom bar-value label renderer.

Parameter Type Description
barValueRenderer BarValueRenderer Custom renderer callback, or null to use built-in value labels.

Returns Chart: This chart for fluent configuration..

Chart::barTooltipRenderer(BarTooltipRenderer)

Customize bar tooltips

Installs or clears a custom tooltip renderer for hovered bars.

Parameter Type Description
barTooltipRenderer BarTooltipRenderer Custom renderer callback, or null to use the built-in tooltip.

Returns Chart: This chart for fluent configuration..

Chart::renderer(WidgetRender)

Set chart renderer

Sets the widget-level renderer used for chart rendering hooks.

Parameter Type Description
renderer WidgetRender Widget renderer callback.

Returns Chart: This chart for fluent configuration..

Layout

Method Description
preferredWidth(float) Sets the preferred chart width in UI pixels.
preferredHeight(float) Sets the preferred chart height in UI pixels.
preferredSize(float, float) Sets preferred width and height in UI pixels.

Chart::preferredWidth(float)

Set preferred chart width

Sets the preferred chart width in UI pixels.

Parameter Type Description
preferredWidth float Preferred width in UI pixels; non-positive or non-finite values use the default.

Returns Chart: This chart for fluent configuration..

Chart::preferredHeight(float)

Set preferred chart height

Sets the preferred chart height in UI pixels.

Parameter Type Description
preferredHeight float Preferred height in UI pixels; non-positive or non-finite values use the default.

Returns Chart: This chart for fluent configuration..

Chart::preferredSize(float, float)

Set preferred chart size

Sets preferred width and height in UI pixels.

Parameter Type Description
width float Preferred width in UI pixels.
height float Preferred height in UI pixels.

Returns Chart: This chart for fluent configuration..

Interaction

Method Description
onBarClick(EventListener) Registers a listener for clicks on chart bars.

Chart::onBarClick(EventListener)

Listen for bar clicks

Registers a listener for clicks on chart bars.

Parameter Type Description
listener EventListener Listener receiving the clicked bar event.

Returns EventSubscription: A subscription handle that can be cancelled..