API Reference

Stacked Bar Chart API

Complete API reference for the Stacked Bar Chart. Uses the bar-chart headless engine with stacked bar-specific configuration.

Data Format

Stacked Bar Chart reuses the BarChartData format. Each dataset represents a stacked series with values accumulated on top of previous series.

type BarChartData = {
  labels: string[];
  datasets: { legend: string; values: number[] }[];
};
AG Style Config

Bar

PropertyTypeDefaultDescription
bar.gapnumber0Gap between stacked bars (typically 0 for stacked layout).
Toast Style Config

Bar

PropertyTypeDefaultDescription
bar.gapnumber0Gap between stacked bars (typically 0 for stacked layout).

Custom Parts

Override any visual element by providing a custom builder function: (args, context) => Widget

PartArgsDescription
barGroup{ bars: { bar: Widget; value: number; datasetIndex: number }[]; index: number; label: string }Container for a group of stacked bars at a single label position.
barBox{ bar: Widget; value: number; ratio: number; alignment: Alignment; index: number; label: string; legend: string; isHovered: boolean }Wrapper around each individual stacked bar segment.
bar{ value: number; label: string; legend: string; index: number; isHovered: boolean }The visual bar element itself.
xAxis{ line: Widget; labels: Widget[]; tick: Widget }The complete x-axis assembly.
yAxis{ line: Widget; labels: Widget[]; tick: Widget }The complete y-axis assembly.
xAxisLabel{ name: string; index: number }Individual x-axis label.
yAxisLabel{ name: string; index: number }Individual y-axis label.
xAxisTickundefinedX-axis tick mark.
yAxisTickundefinedY-axis tick mark.
xAxisLineundefinedX-axis line.
yAxisLineundefinedY-axis line.
axisCornerundefinedCorner element where x and y axes meet.
dataView{ barGroups: Widget[] }Container for all bar groups in the data area.
layout{ title: Widget; legends: Widget[]; plot: Widget }Top-level layout composing title, legends, and the plot area.
plot{ xAxis: Widget; yAxis: Widget; dataView: Widget; grid: Widget; axisCorner: Widget; tooltipArea: Widget }The plot area composing axes, data view, grid, and tooltip.
legend{ name: string; index: number; isVisible: boolean }Individual legend item.
titleundefinedChart title element.
dataLabel{ value: number; label: string; legend: string }Data label displayed on or near a bar.
grid{ xLine: Widget; yLine: Widget }Grid container for horizontal and vertical grid lines.
gridXLineundefinedIndividual vertical grid line.
gridYLineundefinedIndividual horizontal grid line.
tooltip{ label: string; items: { legend: string; color: string; value: number }[] }Tooltip content widget.
tooltipArea{ tooltip: Widget | null; hoveredBar: { index: number; legend: string; value: number; label: string; x: number; y: number; width: number; height: number } | null }Tooltip positioning area that manages tooltip display.

Context: BarChartContext

Available in every custom builder via the second argument.

NameTypeKindDescription
dataBarChartDatapropertyCurrent chart data (filtered by hidden series).
legendsstring[]propertyAll legend names from the raw data.
direction"vertical" | "horizontal"propertyCurrent bar direction.
widthnumberpropertyCurrent chart width in pixels.
heightnumberpropertyCurrent chart height in pixels.
scaleBarChartScale | nullpropertyComputed scale with min, max, and step.
hiddenSeriesReadonlySet<string>propertySet of currently hidden series legend names.
hoveredBar{ index: number; legend: string } | nullpropertyCurrently hovered bar info.
configTConfigpropertyThe resolved chart configuration object.
isSeriesVisible(legend)(legend: string) => booleanmethodCheck if a series is currently visible.
toggleSeries(legend)(legend: string) => voidmethodToggle visibility of a series.
showSeries(legend)(legend: string) => voidmethodShow a hidden series.
hideSeries(legend)(legend: string) => voidmethodHide a visible series.
showAllSeries()() => voidmethodShow all hidden series.
hoverBar(index, legend, anchorKey)(index: number, legend: string, anchorKey: GlobalKey) => voidmethodSet hover state on a specific bar.
unhoverBar(index, legend)(index: number, legend: string) => voidmethodClear hover if the specified bar is currently hovered.
unhoverAllBars()() => voidmethodClear all bar hover state.
isBarHovered(index, legend)(index: number, legend: string) => booleanmethodCheck if a specific bar is hovered.
setSize(width, height)(width: number, height: number) => voidmethodUpdate chart dimensions.

Custom Part Example

import { ToastStackedBarChart } from "@/components/flitter/charts/toast-stacked-bar-chart";

<ToastStackedBarChart
  data={data}
  config={{
    bar: { gap: 2 },
  }}
/>