Skip to main content

Starwind UI v3.7 is now available with new chart component and full rtl support!

Chart Primitive

Use Chart to draw bar, line, area, pie, radar and radial charts from your data and series config. Add parts such as Bar, XAxis and Grid to describe the chart. For a chart that the parts cannot draw, pass a TanStack Charts chart module. People can read values in a tooltip with the pointer or the keyboard, and the legend can hide a series.

Use arrow keys to inspect values. Enter pins details. Escape dismisses. Exact values follow in a table.

Anatomy

Use the Astro primitive adapter to render Chart anatomy with the Runtime wiring included.

---
import { Chart } from "@starwind-ui/astro/chart";
import type { ChartConfig } from "@starwind-ui/astro/chart";
type VisitorRow = { month: string; desktop: number; mobile: number };
const data: VisitorRow[] = [
{ month: "January", desktop: 186, mobile: 80 },
{ month: "February", desktop: 305, mobile: 200 },
{ month: "March", desktop: 237, mobile: 120 },
];
const config = {
desktop: { label: "Desktop", color: "var(--chart-1)" },
mobile: { label: "Mobile", color: "var(--chart-2)" },
} satisfies ChartConfig;
---
<Chart.Root data={data} config={config}>
<Chart.Style />
<Chart.Surface />
<Chart.Grid vertical={false} />
<Chart.XAxis dataKey="month" tickFormatter={{ maxLength: 3 }} />
<Chart.Bar dataKey="desktop" radius={4} />
<Chart.Bar dataKey="mobile" radius={4} />
</Chart.Root>

Astro, React, Vue, and Svelte components use the same underlying interactions. Each framework has its own way to read and update state. See the examples and your installed packageโ€™s types for the available props and events. Plain HTML uses DOM events and Runtime methods.

API Reference

Root

The main element that owns the Chart Runtime instance.

Default element
div
Discovery hook
data-sw-chart
Role
-

Props

Prop Type Default Toggle
id string -
Description
Names the chart. Leave it out to get a generated id that matches on server and client.
Kind
attribute
Targets
root
Full type
string
chart ChartSource<T, D, X, Y> -
Description
The chart module or factory that draws the chart from the data and the visible keys.
Kind
option
Targets
root
Full type
ChartSource<T, D, X, Y>
definition DomChartDefinition<D, X, Y> -
Description
A static native TanStack definition. It owns its visibility, so the legend is passive.
Kind
option
Targets
root
Full type
DomChartDefinition<D, X, Y>
data readonly T[] -
Description
The data rows that the chart module reads.
Kind
option
Targets
root
Full type
readonly T[]
config ChartConfig -
Description
The series labels, colors and icons, keyed by series.
Kind
option
Targets
root
Full type
ChartConfig
params Record<string, unknown> -
Description
Extra values that the chart module reads.
Kind
option
Targets
root
Full type
Record<string, unknown>
theme ChartInput["theme"] -
Description
Overrides the native TanStack chart theme.
Kind
option
Targets
root
Full type
ChartInput["theme"]
host NativeHostOptions<D, X, Y> -
Description
Native TanStack host options, such as the focus and select callbacks.
Kind
option
Targets
root
Full type
NativeHostOptions<D, X, Y>
disableTooltip boolean false
Description
Turns the tooltip off.
Kind
option
Targets
root
Full type
boolean
stackOffset "none" | "expand" "none"
Description
How the stacked bars and areas of a parts chart stack. `"expand"` stacks each category to 100%, and the tooltip keeps the raw values.
Kind
option
Targets
root
Full type
"none" | "expand"
visible readonly string[] -
Description
Controls the visible state for Chart.
Kind
control
Targets
root
Full type
readonly string[]
React

Use visible for controlled state and defaultVisible for default state, and onVisibleChange for change proposals.

  • visible
  • defaultVisible
  • onVisibleChange
Astro

Use visible or defaultVisible for initial state, listen for starwind-chart:visible-change, and call setVisible(next, { emit: false }) for silent updates, because a legend toggle commits on its own.

  • visible
  • defaultVisible
  • starwind-chart:visible-change
  • setVisible
Runtime / HTML

listen for starwind-chart:visible-change and call setVisible(next, { emit: false }) for silent updates, because a legend toggle commits on its own.

  • starwind-chart:visible-change
  • setVisible
defaultVisible readonly string[] -
Description
Controls the default visible state for Chart.
Kind
control
Targets
root
Full type
readonly string[]
React

Use visible for controlled state and defaultVisible for default state, and onVisibleChange for change proposals.

  • visible
  • defaultVisible
  • onVisibleChange
Astro

Use visible or defaultVisible for initial state, listen for starwind-chart:visible-change, and call setVisible(next, { emit: false }) for silent updates, because a legend toggle commits on its own.

  • visible
  • defaultVisible
  • starwind-chart:visible-change
  • setVisible
Runtime / HTML

listen for starwind-chart:visible-change and call setVisible(next, { emit: false }) for silent updates, because a legend toggle commits on its own.

  • starwind-chart:visible-change
  • setVisible
onVisibleChange (visible: string[], details: ChartVisibleChangeDetails) => void -
Description
Receives proposed visible keys before the cancelable starwind-chart:visible-change event. Call details.cancel() to keep the current keys.
Kind
callback
Targets
root
Full type
(visible: string[], details: ChartVisibleChangeDetails) => void
React

Use visible for controlled state and defaultVisible for default state, and onVisibleChange for change proposals.

  • visible
  • defaultVisible
  • onVisibleChange
Astro

Use visible or defaultVisible for initial state, listen for starwind-chart:visible-change, and call setVisible(next, { emit: false }) for silent updates, because a legend toggle commits on its own.

  • visible
  • defaultVisible
  • starwind-chart:visible-change
  • setVisible
Runtime / HTML

listen for starwind-chart:visible-change and call setVisible(next, { emit: false }) for silent updates, because a legend toggle commits on its own.

  • starwind-chart:visible-change
  • setVisible
interactive Astro only boolean true
Description
Renders the wire payload, the tooltip and legend templates and, for a chart module or chart parts, the lifecycle script. `false` renders a static chart that loads no script.
Kind
option
Targets
root
Frameworks
Astro
Full type
boolean
labels Astro only Record<string, string> -
Description
Rich label HTML per config key, for a wrapper that renders its own `label-<key>` slots. A `label-<key>` slot on the Root wins.
Kind
option
Targets
root
Frameworks
Astro
Full type
Record<string, string>
icons Astro only Record<string, string> -
Description
Icon HTML per config key, for a wrapper that renders its own `icon-<key>` slots.
Kind
option
Targets
root
Frameworks
Astro
Full type
Record<string, string>

Events

Event Callback Value Toggle
visibleChange onVisibleChange visible: string[]
Description
Fires when the visible changes for Chart.
DOM event
starwind-chart:visible-change
Details type
ChartVisibleChangeDetails
Timing
before-state-commit
Cancelable
Yes
Cancellation sequence
  1. Check internal eligibility and intent.
  2. Create one details object for the proposal.
  3. Call the Runtime callback with the details object when the controller exposes one.
  4. Dispatch the cancelable DOM event with the same details object, including when the callback canceled it.
  5. Read details.isCanceled, including cancellation caused by preventDefault().
  6. Apply the accepted state.
  7. Notify Runtime subscribers and other accepted-only observers.

State

State Type Props Toggle
visible string[] visible / defaultVisible
Description
Tracks the visible state for Chart.
Initial attribute
-
Runtime getter
getVisible
Runtime setter
setVisible
React

Use visible for controlled state and defaultVisible for default state, and onVisibleChange for change proposals.

  • visible
  • defaultVisible
  • onVisibleChange
Astro

Use visible or defaultVisible for initial state, listen for starwind-chart:visible-change, and call setVisible(next, { emit: false }) for silent updates, because a legend toggle commits on its own.

  • visible
  • defaultVisible
  • starwind-chart:visible-change
  • setVisible
Runtime / HTML

listen for starwind-chart:visible-change and call setVisible(next, { emit: false }) for silent updates, because a legend toggle commits on its own.

  • starwind-chart:visible-change
  • setVisible

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-chart - Marks the Root part so Starwind Runtime can find it.
Metadata
Attribute Value Description
data-slot chart Identifies Root metadata for styling and selectors.
data-chart - Reflects the chart prop on the Root part.

Style

Writes the config color rules for light and dark themes.

Default element
style
Discovery hook
data-sw-chart-style
Role
-

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-chart-style - Marks the Style part so Starwind Runtime can find it.
Metadata
Attribute Value Description
data-slot chart-style Identifies Style metadata for styling and selectors.

Surface

Provides the Surface part for Chart.

Default element
div
Discovery hook
data-sw-chart-surface
Role
-

Props

Prop Type Default Toggle
tooltip framework content -
Description
Tooltip body content. It wins over a registered Tooltip.
Kind
rendering
Targets
surface
Full type
framework content
fallbackTooltip framework content -
Description
Tooltip body content when no Tooltip is registered.
Kind
rendering
Targets
surface
Full type
framework content
nativeTooltip boolean false
Description
Uses the native TanStack tooltip body.
Kind
option
Targets
surface
Full type
boolean

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-chart-surface - Marks the Surface part so Starwind Runtime can find it.
Metadata
Attribute Value Description
data-slot chart-surface Identifies Surface metadata for styling and selectors.

Tooltip

Inside a chart root, the first Tooltip supplies the tooltip body, unless a Surface `tooltip` replaces it. Inside a tooltip body it renders its content in place. Elsewhere it renders nothing.

Default element
template
Discovery hook
data-sw-chart-tooltip
Role
-

Props

Prop Type Default Toggle
children framework content -
Description
Tooltip body content.
Kind
children
Targets
tooltip
Full type
framework content
cursor boolean true
Description
Draws the hover band of a bar chart. `false` removes it. Line and area charts draw no hover rule. In a parts chart, the first Tooltip at chart level sets it, because that Tooltip supplies the tooltip body. When it leaves `cursor` unset, the band shows. A Tooltip inside a tooltip body sets nothing.
Kind
option
Targets
tooltip
Full type
boolean

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-chart-tooltip - Marks the Tooltip part so Starwind Runtime can find it.

Tooltip Content

The tooltip body content. It renders inside a tooltip body only.

Default element
div
Discovery hook
data-sw-chart-tooltip-content
Role
-

Props

Prop Type Default Toggle
indicator "dot" | "line" | "dashed" -
Description
Configures the indicator option for the Tooltip Content part.
Kind
option
Targets
tooltipContent
Full type
"dot" | "line" | "dashed"
hideLabel boolean -
Description
Configures the hide label option for the Tooltip Content part.
Kind
option
Targets
tooltipContent
Full type
boolean
hideIndicator boolean -
Description
Configures the hide indicator option for the Tooltip Content part.
Kind
option
Targets
tooltipContent
Full type
boolean
label string | framework content -
Description
Replaces the heading before labelFormatter runs.
Kind
rendering
Targets
tooltipContent
Full type
string | framework content
labelKey string -
Description
Configures the label key option for the Tooltip Content part.
Kind
option
Targets
tooltipContent
Full type
string
nameKey string -
Description
Configures the name key option for the Tooltip Content part.
Kind
option
Targets
tooltipContent
Full type
string
valueKey string -
Description
Configures the value key option for the Tooltip Content part.
Kind
option
Targets
tooltipContent
Full type
string
color string -
Description
Overrides each row's indicator color.
Kind
option
Targets
tooltipContent
Full type
string
formatter ((value: unknown, name: string, item: TooltipItem<T>, index: number, payload: T) => string | framework content) | ChartFormat -
Description
A function returns the complete row view, with shadcn's argument order. `payload` is the native datum. A ChartFormat object formats only the row value.
Kind
callback
Targets
tooltipContent
Full type
((value: unknown, name: string, item: TooltipItem<T>, index: number, payload: T) => string | framework content) | ChartFormat
labelFormatter ((label: unknown, payload: readonly TooltipItem<T>[]) => string | framework content) | ChartFormat -
Description
A function returns the complete heading view. A ChartFormat object formats the heading.
Kind
callback
Targets
tooltipContent
Full type
((label: unknown, payload: readonly TooltipItem<T>[]) => string | framework content) | ChartFormat

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-chart-tooltip-content - Marks the Tooltip Content part so Starwind Runtime can find it.
State
Attribute Value Description
data-chart - Reflects the chart state on the Tooltip Content part.
data-indicator - Reflects the indicator state on the Tooltip Content part.
data-nested - Reflects the nested state on the Tooltip Content part.
Metadata
Attribute Value Description
data-slot chart-tooltip-content Identifies Tooltip Content metadata for styling and selectors.

Tooltip Label

The tooltip heading. It renders nothing when the heading is hidden, empty or nested in a row.

Default element
div
Discovery hook
data-sw-chart-tooltip-label
Role
-

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-chart-tooltip-label - Marks the Tooltip Label part so Starwind Runtime can find it.
Metadata
Attribute Value Description
data-slot chart-tooltip-label Identifies Tooltip Label metadata for styling and selectors.

Tooltip Items

Renders its content once per tooltip row, with that row in context.

Default element
template
Discovery hook
data-sw-chart-tooltip-row
Role
-

Props

Prop Type Default Toggle
children framework content -
Description
Rendered once per tooltip row, with that row in context.
Kind
children
Targets
tooltipItems
Full type
framework content

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-chart-tooltip-row - Marks the Tooltip Items part so Starwind Runtime can find it.

Tooltip Item

One tooltip row. Rows stay hidden from assistive technology, because the Runtime keeps the native status label in sync with the visible text. A formatter row renders the formatter view.

Default element
div
Discovery hook
data-sw-chart-tooltip-item
Role
-

Props

Prop Type Default Toggle
customClass string -
Description
The class for a row that a tooltip formatter replaced. React names it `customClassName`.
Kind
attribute
Targets
tooltipItem
Full type
string

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-chart-tooltip-item - Marks the Tooltip Item part so Starwind Runtime can find it.
State
Attribute Value Description
data-active - Reflects the active state on the Tooltip Item part.
data-key - Reflects the key state on the Tooltip Item part.
Metadata
Attribute Value Description
data-slot chart-tooltip-item Identifies Tooltip Item metadata for styling and selectors.

Tooltip Indicator

The row color marker. A row with an icon or a hidden indicator renders nothing.

Default element
span
Discovery hook
data-sw-chart-tooltip-indicator
Role
-

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-chart-tooltip-indicator - Marks the Tooltip Indicator part so Starwind Runtime can find it.
Metadata
Attribute Value Description
data-slot chart-tooltip-indicator Identifies Tooltip Indicator metadata for styling and selectors.

Tooltip Icon

The config icon of a row. Keep TooltipIndicator in the row too: a row with an icon shows the icon in place of the indicator, and a row without one shows the indicator.

Default element
span
Discovery hook
data-sw-chart-tooltip-icon
Role
-

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-chart-tooltip-icon - Marks the Tooltip Icon part so Starwind Runtime can find it.
Metadata
Attribute Value Description
data-slot chart-tooltip-icon Identifies Tooltip Icon metadata for styling and selectors.

Tooltip Name

The row name. One line or dashed row nests the heading inside it.

Default element
span
Discovery hook
data-sw-chart-tooltip-name
Role
-

Props

Prop Type Default Toggle
labelClass string -
Description
The class of the heading that one line or dashed row nests inside its name. React names it `labelClassName`.
Kind
attribute
Targets
tooltipName
Full type
string

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-chart-tooltip-name - Marks the Tooltip Name part so Starwind Runtime can find it.
Metadata
Attribute Value Description
data-slot chart-tooltip-name Identifies Tooltip Name metadata for styling and selectors.

Tooltip Value

The formatted row value.

Default element
span
Discovery hook
data-sw-chart-tooltip-value
Role
-

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-chart-tooltip-value - Marks the Tooltip Value part so Starwind Runtime can find it.
Metadata
Attribute Value Description
data-slot chart-tooltip-value Identifies Tooltip Value metadata for styling and selectors.

Legend

A group of legend items.

Default element
div
Discovery hook
data-sw-chart-legend
Role
group

Props

Prop Type Default Toggle
hideIcon boolean false
Description
Uses the swatch even when config supplies an icon.
Kind
option
Targets
legend
Full type
boolean
config Astro only ChartConfig -
Description
Renders the legend from this config. Leave it out inside a chart Root, which fills the legend with its own config, visibility and rich label slots.
Kind
option
Targets
legend
Frameworks
Astro
Full type
ChartConfig
visible Astro only readonly string[] -
Description
Visible keys for a legend that takes `config`.
Kind
option
Targets
legend
Frameworks
Astro
Full type
readonly string[]

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-chart-legend - Marks the Legend part so Starwind Runtime can find it.
Metadata
Attribute Value Description
data-slot chart-legend Identifies Legend metadata for styling and selectors.

Legend Items

Renders its content once per config key, with that key in context. A parts chart lists only the keys that it draws.

Default element
template
Discovery hook
data-sw-chart-legend-template
Role
-

Props

Prop Type Default Toggle
children framework content -
Description
Rendered once per config key, with that key in context. A parts chart lists only the keys that it draws.
Kind
children
Targets
legendItems
Full type
framework content

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-chart-legend-template - Marks the Legend Items part so Starwind Runtime can find it.

Legend Item

A legend toggle for one config key. A click handler that calls `preventDefault()` cancels the toggle.

Default element
button
Discovery hook
data-sw-chart-legend-item
Role
-

Props

Prop Type Default Toggle
value string -
Description
The config key this item shows or hides. Defaults to the key from LegendItems.
Kind
option
Targets
legendItem
Full type
string
interactive boolean -
Description
Defaults to false for a static native definition. A passive item renders a span.
Kind
option
Targets
legendItem
Full type
boolean

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-chart-legend-item - Marks the Legend Item part so Starwind Runtime can find it.
State
Attribute Value Description
data-state - Reflects the current state on the Legend Item part.
Metadata
Attribute Value Description
data-slot chart-legend-item Identifies Legend Item metadata for styling and selectors.
data-key - Reflects the key prop on the Legend Item part.

Legend Swatch

The series color swatch. It renders nothing when the legend shows the config icon.

Default element
span
Discovery hook
data-sw-chart-legend-swatch
Role
-

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-chart-legend-swatch - Marks the Legend Swatch part so Starwind Runtime can find it.
Metadata
Attribute Value Description
data-slot chart-legend-swatch Identifies Legend Swatch metadata for styling and selectors.

Legend Icon

The config icon of a legend item. It renders nothing without an icon or with `hideIcon`.

Default element
span
Discovery hook
data-sw-chart-legend-icon
Role
-

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-chart-legend-icon - Marks the Legend Icon part so Starwind Runtime can find it.
Metadata
Attribute Value Description
data-slot chart-legend-icon Identifies Legend Icon metadata for styling and selectors.

Legend Label

The config label of a legend item: a rich label, or its plain text.

Default element
span
Discovery hook
data-sw-chart-legend-label
Role
-

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-chart-legend-label - Marks the Legend Label part so Starwind Runtime can find it.
Metadata
Attribute Value Description
data-slot chart-legend-label Identifies Legend Label metadata for styling and selectors.

Bar

Adds bars for one data key. Bars with the same `stackId` stack. Other bars group.

Default element
template
Discovery hook
data-sw-chart-part-bar
Role
-

Props

Prop Type Default Toggle
dataKey string -
Description
The data key of the values this part draws.
Kind
option
Targets
bar, line, area, pie, radar, radialBar
Full type
string
stackId string | number -
Description
Bars with the same stackId stack. Other bars group.
Kind
option
Targets
bar
Full type
string | number
radius number | readonly [number, number, number, number] 0
Description
The corner radius in pixels. A number rounds the bar end. Four numbers set the top left, top right, bottom right and bottom left corners, as in Recharts.
Kind
option
Targets
bar
Full type
number | readonly [number, number, number, number]
fill string -
Description
The fill color, or `"url(#id)"` for the ChartLinearGradient with that id. Defaults to the config color.
Kind
option
Targets
bar, area
Full type
string
label boolean | { dataKey?: string; position?: "top" | "inside" | "insideLeft" | "insideStart" | "right" | "outside"; offset?: number; fill?: string; fontSize?: number; formatter?: ChartTickFormatter } false
Description
Draws a label on each bar or value, as a Recharts `label` or `LabelList`. An object sets the row field, position, offset, color, font size and formatter. Labels sit in the middle of the mark, 5px from it, unless `position` says otherwise.
Kind
option
Targets
bar, line, area
Full type
boolean | { dataKey?: string; position?: "top" | "inside" | "insideLeft" | "insideStart" | "right" | "outside"; offset?: number; fill?: string; fontSize?: number; formatter?: ChartTickFormatter }

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-chart-part-bar - Marks the Bar part so Starwind Runtime can find it.

Line

Adds a line for one data key.

Default element
template
Discovery hook
data-sw-chart-part-line
Role
-

Props

Prop Type Default Toggle
dataKey string -
Description
The data key of the values this part draws.
Kind
option
Targets
bar, line, area, pie, radar, radialBar
Full type
string
type "natural" | "monotone" | "linear" | "step" "natural"
Description
The curve of the line.
Kind
option
Targets
line
Full type
"natural" | "monotone" | "linear" | "step"
stroke string -
Description
The stroke color. Defaults to the config color.
Kind
option
Targets
line, area
Full type
string
strokeWidth number 2
Description
The stroke width in pixels.
Kind
option
Targets
line, area, radar
Full type
number
dot boolean | { r?: number; fill?: string; fillOpacity?: number; stroke?: string; strokeWidth?: number } false
Description
Draws a dot at every value. An object sets the dot radius, fill and stroke.
Kind
option
Targets
line, radar
Full type
boolean | { r?: number; fill?: string; fillOpacity?: number; stroke?: string; strokeWidth?: number }
activeDot boolean | { r?: number; fill?: string; fillOpacity?: number; stroke?: string; strokeWidth?: number } true
Description
Draws a dot at the focused value. An object sets the dot radius, fill and stroke.
Kind
option
Targets
line, radar
Full type
boolean | { r?: number; fill?: string; fillOpacity?: number; stroke?: string; strokeWidth?: number }
label boolean | { dataKey?: string; position?: "top" | "inside" | "insideLeft" | "insideStart" | "right" | "outside"; offset?: number; fill?: string; fontSize?: number; formatter?: ChartTickFormatter } false
Description
Draws a label on each bar or value, as a Recharts `label` or `LabelList`. An object sets the row field, position, offset, color, font size and formatter. Labels sit in the middle of the mark, 5px from it, unless `position` says otherwise.
Kind
option
Targets
bar, line, area
Full type
boolean | { dataKey?: string; position?: "top" | "inside" | "insideLeft" | "insideStart" | "right" | "outside"; offset?: number; fill?: string; fontSize?: number; formatter?: ChartTickFormatter }

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-chart-part-line - Marks the Line part so Starwind Runtime can find it.

Area

Adds an area for one data key. Areas with the same `stackId` stack. Other areas overlap.

Default element
template
Discovery hook
data-sw-chart-part-area
Role
-

Props

Prop Type Default Toggle
dataKey string -
Description
The data key of the values this part draws.
Kind
option
Targets
bar, line, area, pie, radar, radialBar
Full type
string
stackId string | number -
Description
Areas with the same stackId stack. Other areas overlap.
Kind
option
Targets
area
Full type
string | number
type "natural" | "monotone" | "linear" | "step" "monotone"
Description
The curve of the area edge.
Kind
option
Targets
area
Full type
"natural" | "monotone" | "linear" | "step"
fill string -
Description
The fill color, or `"url(#id)"` for the ChartLinearGradient with that id. Defaults to the config color.
Kind
option
Targets
bar, area
Full type
string
stroke string -
Description
The stroke color. Defaults to the config color.
Kind
option
Targets
line, area
Full type
string
strokeWidth number 2
Description
The stroke width in pixels.
Kind
option
Targets
line, area, radar
Full type
number
fillOpacity number 0.22
Description
The fill opacity. A gradient fill without it takes 0.6, the Recharts default, so the stops look as in shadcn.
Kind
option
Targets
area
Full type
number
activeDot boolean true
Description
Draws a dot at the focused value.
Kind
option
Targets
area
Full type
boolean
label boolean | { dataKey?: string; position?: "top" | "inside" | "insideLeft" | "insideStart" | "right" | "outside"; offset?: number; fill?: string; fontSize?: number; formatter?: ChartTickFormatter } false
Description
Draws a label on each bar or value, as a Recharts `label` or `LabelList`. An object sets the row field, position, offset, color, font size and formatter. Labels sit in the middle of the mark, 5px from it, unless `position` says otherwise.
Kind
option
Targets
bar, line, area
Full type
boolean | { dataKey?: string; position?: "top" | "inside" | "insideLeft" | "insideStart" | "right" | "outside"; offset?: number; fill?: string; fontSize?: number; formatter?: ChartTickFormatter }

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-chart-part-area - Marks the Area part so Starwind Runtime can find it.

Pie

Adds a pie or donut. Slice colors come from config by `nameKey` value.

Default element
template
Discovery hook
data-sw-chart-part-pie
Role
-

Props

Prop Type Default Toggle
dataKey string -
Description
The data key of the values this part draws.
Kind
option
Targets
bar, line, area, pie, radar, radialBar
Full type
string
nameKey string -
Description
The data key whose values name the slices or bars. Their colors come from config by this value.
Kind
option
Targets
pie, radialBar
Full type
string
stroke string "var(--card)"
Description
The color of the line between slices. `"none"` removes the line.
Kind
option
Targets
pie
Full type
string
strokeWidth number 2
Description
The width of the line between slices in pixels.
Kind
option
Targets
pie
Full type
number
label boolean | { dataKey?: string; position?: "top" | "inside" | "insideLeft" | "insideStart" | "right" | "outside"; offset?: number; fill?: string; fontSize?: number; formatter?: ChartTickFormatter } false
Description
Draws a label on each slice, as a Recharts pie `label`. Labels sit 20px outside the slices, and the pie shrinks to make room. `position: "inside"` puts them in the middle of the slices.
Kind
option
Targets
pie
Full type
boolean | { dataKey?: string; position?: "top" | "inside" | "insideLeft" | "insideStart" | "right" | "outside"; offset?: number; fill?: string; fontSize?: number; formatter?: ChartTickFormatter }
labelLine boolean true
Description
Draws a line from each slice to its outside label.
Kind
option
Targets
pie
Full type
boolean
innerRadius number | `${number}%` 0
Description
The inner radius: plain pixels at any chart size, or a percent of half the smaller side.
Kind
option
Targets
pie
Full type
number | `${number}%`
outerRadius number | `${number}%` "90%"
Description
The outer radius: plain pixels at any chart size, or a percent of half the smaller side.
Kind
option
Targets
pie
Full type
number | `${number}%`
paddingAngle number -
Description
The gap between slices in degrees. Without it, slices keep a gap of about 1.4 degrees.
Kind
option
Targets
pie
Full type
number

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-chart-part-pie - Marks the Pie part so Starwind Runtime can find it.

Radar

Adds a radar area for one data key. The angle key comes from the polar angle axis.

Default element
template
Discovery hook
data-sw-chart-part-radar
Role
-

Props

Prop Type Default Toggle
dataKey string -
Description
The data key of the values this part draws.
Kind
option
Targets
bar, line, area, pie, radar, radialBar
Full type
string
strokeWidth number 2
Description
The stroke width in pixels.
Kind
option
Targets
line, area, radar
Full type
number
fillOpacity number 0.18
Description
The fill opacity.
Kind
option
Targets
radar
Full type
number
dot boolean | { r?: number; fill?: string; fillOpacity?: number; stroke?: string; strokeWidth?: number } false
Description
Draws a dot at every value. An object sets the dot radius, fill and stroke.
Kind
option
Targets
line, radar
Full type
boolean | { r?: number; fill?: string; fillOpacity?: number; stroke?: string; strokeWidth?: number }
activeDot boolean | { r?: number; fill?: string; fillOpacity?: number; stroke?: string; strokeWidth?: number } true
Description
Draws a dot at the focused value. An object sets the dot radius, fill and stroke.
Kind
option
Targets
line, radar
Full type
boolean | { r?: number; fill?: string; fillOpacity?: number; stroke?: string; strokeWidth?: number }

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-chart-part-radar - Marks the Radar part so Starwind Runtime can find it.

Radial Bar

Adds radial bars. `background` draws the muted track. Bar colors come from config by `nameKey` value.

Default element
template
Discovery hook
data-sw-chart-part-radial-bar
Role
-

Props

Prop Type Default Toggle
dataKey string -
Description
The data key of the values this part draws.
Kind
option
Targets
bar, line, area, pie, radar, radialBar
Full type
string
nameKey string -
Description
The data key whose values name the slices or bars. Their colors come from config by this value.
Kind
option
Targets
pie, radialBar
Full type
string
innerRadius number | `${number}%` "24%"
Description
The inner radius: plain pixels at any chart size, or a percent of half the smaller side.
Kind
option
Targets
radialBar
Full type
number | `${number}%`
outerRadius number | `${number}%` "88%"
Description
The outer radius: plain pixels at any chart size, or a percent of half the smaller side.
Kind
option
Targets
radialBar
Full type
number | `${number}%`
background boolean false
Description
Draws the muted track behind each bar.
Kind
option
Targets
radialBar
Full type
boolean

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-chart-part-radial-bar - Marks the Radial Bar part so Starwind Runtime can find it.

X Axis

Adds the category axis of a cartesian chart.

Default element
template
Discovery hook
data-sw-chart-part-x-axis
Role
-

Props

Prop Type Default Toggle
dataKey string -
Description
The data key of the categories.
Kind
option
Targets
xAxis, polarAngleAxis
Full type
string
tickFormatter ChartTickFormatter -
Description
Formats the tick labels: a function or a ChartFormat object. Astro accepts only a ChartFormat object.
Kind
option
Targets
xAxis, yAxis, polarAngleAxis
Full type
ChartTickFormatter
tickLine boolean false
Description
Draws tick lines.
Kind
option
Targets
xAxis, yAxis
Full type
boolean
axisLine boolean false
Description
Draws the axis line.
Kind
option
Targets
xAxis, yAxis
Full type
boolean
tickMargin number -
Description
The gap between a tick and its label in pixels.
Kind
option
Targets
xAxis, yAxis
Full type
number
hide boolean false
Description
Keeps the scale and hides the axis.
Kind
option
Targets
xAxis, yAxis
Full type
boolean

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-chart-part-x-axis - Marks the X Axis part so Starwind Runtime can find it.

Y Axis

Adds the value axis of a cartesian chart. Without it, the chart draws no value labels.

Default element
template
Discovery hook
data-sw-chart-part-y-axis
Role
-

Props

Prop Type Default Toggle
tickFormatter ChartTickFormatter -
Description
Formats the tick labels: a function or a ChartFormat object. Astro accepts only a ChartFormat object.
Kind
option
Targets
xAxis, yAxis, polarAngleAxis
Full type
ChartTickFormatter
tickLine boolean false
Description
Draws tick lines.
Kind
option
Targets
xAxis, yAxis
Full type
boolean
axisLine boolean false
Description
Draws the axis line.
Kind
option
Targets
xAxis, yAxis
Full type
boolean
tickMargin number -
Description
The gap between a tick and its label in pixels.
Kind
option
Targets
xAxis, yAxis
Full type
number
hide boolean false
Description
Keeps the scale and hides the axis.
Kind
option
Targets
xAxis, yAxis
Full type
boolean
tickCount number 5
Description
The preferred number of ticks.
Kind
option
Targets
yAxis
Full type
number

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-chart-part-y-axis - Marks the Y Axis part so Starwind Runtime can find it.

Grid

Adds cartesian grid lines.

Default element
template
Discovery hook
data-sw-chart-part-grid
Role
-

Props

Prop Type Default Toggle
vertical boolean true
Description
Draws vertical grid lines.
Kind
option
Targets
grid
Full type
boolean
horizontal boolean true
Description
Draws horizontal grid lines.
Kind
option
Targets
grid
Full type
boolean

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-chart-part-grid - Marks the Grid part so Starwind Runtime can find it.

Polar Grid

Adds the radar grid: rings and the lines from the center to each category.

Default element
template
Discovery hook
data-sw-chart-part-polar-grid
Role
-

Props

Prop Type Default Toggle
gridType "polygon" | "circle" "polygon"
Description
The shape of the radar grid.
Kind
option
Targets
polarGrid
Full type
"polygon" | "circle"
radialLines boolean true
Description
Draws the lines from the center to each category.
Kind
option
Targets
polarGrid
Full type
boolean
fill string -
Description
The fill color of the rings. Without it, the rings have no fill.
Kind
option
Targets
polarGrid
Full type
string
fillOpacity number -
Description
The fill opacity of the rings. Each ring fills its whole disc.
Kind
option
Targets
polarGrid
Full type
number
stroke string "var(--border)"
Description
The color of the rings and the lines.
Kind
option
Targets
polarGrid
Full type
string
strokeWidth number 1
Description
The width of the rings and the lines in pixels.
Kind
option
Targets
polarGrid
Full type
number
polarRadius readonly number[] -
Description
The ring radii in pixels, as in Recharts. Without it, the rings sit at the value ticks.
Kind
option
Targets
polarGrid
Full type
readonly number[]

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-chart-part-polar-grid - Marks the Polar Grid part so Starwind Runtime can find it.

Polar Angle Axis

Adds the radar categories and their labels.

Default element
template
Discovery hook
data-sw-chart-part-polar-angle-axis
Role
-

Props

Prop Type Default Toggle
dataKey string -
Description
The data key of the categories.
Kind
option
Targets
xAxis, polarAngleAxis
Full type
string
tickFormatter ChartTickFormatter -
Description
Formats the tick labels: a function or a ChartFormat object. Astro accepts only a ChartFormat object.
Kind
option
Targets
xAxis, yAxis, polarAngleAxis
Full type
ChartTickFormatter

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-chart-part-polar-angle-axis - Marks the Polar Angle Axis part so Starwind Runtime can find it.

Label

Adds a center line of text to a pie. Without `value`, it shows the total of the visible slices. Each label adds one line, so a second label with `dy` adds a line below the total.

Default element
template
Discovery hook
data-sw-chart-part-label
Role
-

Props

Prop Type Default Toggle
position "center" -
Description
Where the label sits.
Kind
option
Targets
label
Full type
"center"
value string | number -
Description
The label text. Without it, a pie shows the total of its visible slices.
Kind
option
Targets
label
Full type
string | number
dy number 0
Description
Moves the text down by this many pixels. A negative value moves it up.
Kind
option
Targets
label
Full type
number
fontSize number 28
Description
The font size in pixels.
Kind
option
Targets
label
Full type
number
fontWeight number 400
Description
The font weight, such as 700 for the bold total of a shadcn donut chart. At the default, the text keeps the weight of the page.
Kind
option
Targets
label
Full type
number
fill string "var(--foreground)"
Description
The text color.
Kind
option
Targets
label
Full type
string

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-chart-part-label - Marks the Label part so Starwind Runtime can find it.

Linear Gradient

Adds a linear gradient that a bar or an area fills from with `fill="url(#id)"`. The chart scopes the id, so two charts can use the same id.

Default element
template
Discovery hook
data-sw-chart-part-linear-gradient
Role
-

Props

Prop Type Default Toggle
id string -
Description
The gradient id that a fill such as `"url(#fillDesktop)"` names.
Kind
option
Targets
linearGradient
Full type
string
x1 number | `${number}` | `${number}%` 0
Description
The start x: 0 is the left edge and 1 the right edge, or a percent string. With the defaults, the gradient runs from left to right, as in SVG.
Kind
option
Targets
linearGradient
Full type
number | `${number}` | `${number}%`
y1 number | `${number}` | `${number}%` 0
Description
The start y: 0 is the top edge and 1 the bottom edge, or a percent string.
Kind
option
Targets
linearGradient
Full type
number | `${number}` | `${number}%`
x2 number | `${number}` | `${number}%` 1
Description
The end x, as `x1`.
Kind
option
Targets
linearGradient
Full type
number | `${number}` | `${number}%`
y2 number | `${number}` | `${number}%` 0
Description
The end y, as `y1`. For a gradient from top to bottom, shadcn sets `x2` to 0 and `y2` to 1.
Kind
option
Targets
linearGradient
Full type
number | `${number}` | `${number}%`
stops readonly { offset: number | `${number}` | `${number}%`; stopColor: string; stopOpacity?: number }[] -
Description
The color stops, as SVG `<stop>` elements. An offset is a number from 0 to 1 or a percent string such as `"5%"`.
Kind
option
Targets
linearGradient
Full type
readonly { offset: number | `${number}` | `${number}%`; stopColor: string; stopOpacity?: number }[]

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-chart-part-linear-gradient - Marks the Linear Gradient part so Starwind Runtime can find it.

Runtime API

Factory
createChart
Import
@starwind-ui/runtime/chart
Root hook
root data-sw-chart
Option props
chart, definition, host, onVisibleChange

Option Lifecycles

OptionLifecycle
chartsetter-backed
definitionsetter-backed
hostsetter-backed
onVisibleChangesetter-backed
Component Relationship
Chart Direct primitive

Changelog

View version history v1.0.0 1 release

v1.0.0

  • First release. Chart draws bar, line, area, pie, radar and radial charts from your data and series config. Put `Bar`, `Line`, `Area`, `Pie`, `Radar` or `RadialBar` parts inside `Chart.Root`, and add `XAxis`, `YAxis`, `Grid`, `PolarGrid`, `PolarAngleAxis` and `Label` for axes, grid lines and center text. Add `LinearGradient` for gradient fills. Runtime adds the Starwind tooltip, legend toggles and series colors from your theme tokens. The parts are the same in Astro, React, Vue and Svelte.
  • The parts take the props of common shadcn/ui examples: `label` draws values on bars, lines, areas and pie slices in place of a nested `LabelList`, `Bar` takes four corner radii, `stackOffset="expand"` on `Chart.Root` stacks to 100%, and `cursor={false}` on `Chart.Tooltip` removes the hover band. The legend lists only the series that the chart draws.
  • `tickFormatter`, `formatter` and `labelFormatter` take a `ChartFormat` object in every framework. React, Vue and Svelte also take functions. `{ configLabel: true }` shows the config label of a value. For a chart that the parts cannot draw, pass a TanStack Charts chart module to the `chart` prop. Install `@tanstack/charts` in your app to write chart modules. `starwind primitives add chart` installs it for you.