Skip to main content

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

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

Installation

Starwind charts are built on @tanstack/charts, which is installed as a dependency automatically in your project. It also adds the chart color tokens --chart-1 to --chart-5 to your CSS file when they are missing.

Usage

Put chart parts inside ChartContainer. Each part adds one piece of the chart, such as the bars, an axis or the grid. Give ChartContainer your data and a config with the label and color of each series. Starwind draws the chart with TanStack Charts.

In Next.js, a chart must be a Client Component, so the React examples start with "use client".

---
import {
ChartBar,
ChartContainer,
ChartGrid,
ChartLegend,
ChartXAxis,
ChartYAxis,
} from "@/components/starwind/chart";
import { visitorConfig, visitorData } from "@/charts/visitor-charts";
---
<ChartContainer config={visitorConfig} data={visitorData} class="max-w-xl">
<ChartGrid vertical={false} />
<ChartXAxis dataKey="month" tickFormatter={{ maxLength: 3 }} />
<ChartYAxis />
<ChartBar dataKey="desktop" radius={4} />
<ChartBar dataKey="mobile" radius={4} />
<ChartLegend />
</ChartContainer>

Composition

ChartContainer
├── ChartBar, ChartLine or ChartArea (one or more)
├── ChartPie, ChartRadar or ChartRadialBar
├── ChartXAxis
├── ChartYAxis
├── ChartGrid
├── ChartPolarGrid
├── ChartPolarAngleAxis
├── ChartLabel (one or more)
├── ChartLinearGradient (one or more)
├── ChartTooltip
│ └── ChartTooltipContent
└── ChartLegend
└── ChartLegendContent

The mark parts decide the chart type. ChartBar, ChartLine and ChartArea can share one chart. Use ChartPie, ChartRadar and ChartRadialBar alone.

ChartContainer shows a tooltip by default. Add ChartTooltip to change the tooltip content.

From shadcn/ui

Put the parts straight in ChartContainer, and keep the props of each part.

shadcn/uiStarwind
BarChart, LineChart, AreaChart, PieChart, RadarChart, RadialBarChartChartContainer. The mark parts set the chart type.
stackOffset on the chart wrapperstackOffset on ChartContainer
Bar, Line, Area, Pie, Radar, RadialBarChartBar, ChartLine, ChartArea, ChartPie, ChartRadar, ChartRadialBar
XAxis, YAxisChartXAxis, ChartYAxis
CartesianGridChartGrid
PolarGrid, PolarAngleAxisChartPolarGrid, ChartPolarAngleAxis
Label in a pieOne ChartLabel position="center" for each line of text
LabelList in a markThe label prop of the mark. See Labels.
linearGradient in defsChartLinearGradient. See Gradients.
chartConfig[value]?.label in a formatter{ configLabel: true }. See Formatting.
ChartTooltip, ChartTooltipContent, ChartLegend, ChartLegendContentThe same names

Your First Chart

Define Your Data

The data below gives the desktop and mobile visitors for each month.

Info

Your data can have any shape. Use the dataKey prop of each part to pick the field it draws.

src/charts/visitor-charts.ts
export const visitorData = [
{ month: "January", desktop: 186, mobile: 80 },
{ month: "February", desktop: 305, mobile: 200 },
{ month: "March", desktop: 237, mobile: 120 },
{ month: "April", desktop: 73, mobile: 190 },
{ month: "May", desktop: 209, mobile: 130 },
{ month: "June", desktop: 214, mobile: 140 },
];

Define Your Chart Config

The chart config gives each series a label and a color. The tooltip and the legend show the labels. See Chart Config.

src/charts/visitor-charts.ts
import type { ChartConfig } from "@/components/starwind/chart";
export const visitorConfig = {
desktop: { label: "Desktop", color: "var(--chart-1)" },
mobile: { label: "Mobile", color: "var(--chart-2)" },
} satisfies ChartConfig;

Build Your Chart

Add one ChartBar for each series. Its dataKey is the data field and the config key of the series. Bars without a stackId stand side by side for each category. The chart already shows a tooltip when you move the pointer over it or move between points with the keyboard.

---
import { ChartBar, ChartContainer } from "@/components/starwind/chart";
import { visitorConfig, visitorData } from "@/charts/visitor-charts";
---
<ChartContainer config={visitorConfig} data={visitorData} class="max-w-xl">
<ChartBar dataKey="desktop" radius={4} />
<ChartBar dataKey="mobile" radius={4} />
</ChartContainer>

To render a static chart, set interactive={false} on ChartContainer.

Add a Grid

Add ChartGrid to draw grid lines. vertical={false} keeps only the horizontal lines.

---
import { ChartBar, ChartContainer, ChartGrid } from "@/components/starwind/chart";
import { visitorConfig, visitorData } from "@/charts/visitor-charts";
---
<ChartContainer config={visitorConfig} data={visitorData} class="max-w-xl">
<ChartGrid vertical={false} />
<ChartBar dataKey="desktop" radius={4} />
<ChartBar dataKey="mobile" radius={4} />
</ChartContainer>

Add an Axis

Add ChartXAxis to show the months. Its dataKey is the category field of your data. tickFormatter={{ maxLength: 3 }} keeps the first three letters of each month. See Formatting.

---
import { ChartBar, ChartContainer, ChartGrid, ChartXAxis } from "@/components/starwind/chart";
import { visitorConfig, visitorData } from "@/charts/visitor-charts";
---
<ChartContainer config={visitorConfig} data={visitorData} class="max-w-xl">
<ChartGrid vertical={false} />
<ChartXAxis dataKey="month" tickFormatter={{ maxLength: 3 }} />
<ChartBar dataKey="desktop" radius={4} />
<ChartBar dataKey="mobile" radius={4} />
</ChartContainer>

Customize the Tooltip

Add ChartTooltip with a ChartTooltipContent to change the tooltip. indicator="line" shows a line in place of the dot. See Tooltip.

---
import {
ChartBar,
ChartContainer,
ChartGrid,
ChartTooltip,
ChartTooltipContent,
ChartXAxis,
} from "@/components/starwind/chart";
import { visitorConfig, visitorData } from "@/charts/visitor-charts";
---
<ChartContainer config={visitorConfig} data={visitorData} class="max-w-xl">
<ChartGrid vertical={false} />
<ChartXAxis dataKey="month" tickFormatter={{ maxLength: 3 }} />
<ChartBar dataKey="desktop" radius={4} />
<ChartBar dataKey="mobile" radius={4} />
<ChartTooltip>
<ChartTooltipContent slot="content" indicator="line" />
</ChartTooltip>
</ChartContainer>

Add a Legend

Add a ChartLegend. Click a legend item to hide or show its series.

---
import {
ChartBar,
ChartContainer,
ChartGrid,
ChartLegend,
ChartTooltip,
ChartTooltipContent,
ChartXAxis,
} from "@/components/starwind/chart";
import { visitorConfig, visitorData } from "@/charts/visitor-charts";
---
<ChartContainer config={visitorConfig} data={visitorData} class="max-w-xl">
<ChartGrid vertical={false} />
<ChartXAxis dataKey="month" tickFormatter={{ maxLength: 3 }} />
<ChartBar dataKey="desktop" radius={4} />
<ChartBar dataKey="mobile" radius={4} />
<ChartTooltip>
<ChartTooltipContent slot="content" indicator="line" />
</ChartTooltip>
<ChartLegend />
</ChartContainer>

You built your first chart. Next, read about:

Chart Config

The chart config sets the label, the icon and the color of each series. Each key is a series key, such as the dataKey of a ChartBar. For a pie or radial chart, each key is a value of the nameKey field, such as one month or one browser.

import type { ChartConfig } from "@/components/starwind/chart";
export const chartConfig = {
desktop: {
label: "Desktop",
color: "var(--chart-1)",
},
mobile: {
label: "Mobile",
// Use theme in place of color to set one color for each mode.
theme: { light: "var(--chart-2)", dark: "var(--chart-3)" },
},
} satisfies ChartConfig;
  • label is the text that the tooltip and the legend show for the series.
  • icon replaces the color indicator in the tooltip and the color swatch in the legend. Give SVG path data as { viewBox, paths }, or an icon component in React, Vue and Svelte.
  • color is any CSS color. To set one color for light mode and one for dark mode, use theme with light and dark colors in place of color.

Example Data

The examples on this page import their data and configs from this file.

Show the complete example file
src/charts/visitor-charts.ts
// Data and configs for the Chart docs examples. Astro, React, Vue and Svelte use this same file.
// The examples draw their charts with chart parts. The chart module of the "Advanced: chart
// modules" section is in horizontal-bar-chart.ts.
import type { ChartConfig } from "@/components/starwind/chart";
export interface VisitorRow {
month: string;
desktop: number;
mobile: number;
}
export const visitorData: VisitorRow[] = [
{ month: "January", desktop: 186, mobile: 80 },
{ month: "February", desktop: 305, mobile: 200 },
{ month: "March", desktop: 237, mobile: 120 },
{ month: "April", desktop: 73, mobile: 190 },
{ month: "May", desktop: 209, mobile: 130 },
{ month: "June", desktop: 214, mobile: 140 },
];
/** Desktop uses one token. Mobile changes token between light and dark mode. */
export const visitorConfig = {
desktop: { label: "Desktop", color: "var(--chart-1)" },
mobile: { label: "Mobile", theme: { light: "var(--chart-2)", dark: "var(--chart-3)" } },
} satisfies ChartConfig;
/** The donut has one slice per month, so each month gets one chart token. */
export const monthConfig = {
January: { label: "Jan", color: "var(--chart-1)" },
February: { label: "Feb", color: "var(--chart-2)" },
March: { label: "Mar", color: "var(--chart-3)" },
April: { label: "Apr", color: "var(--chart-4)" },
May: { label: "May", color: "var(--chart-5)" },
June: { label: "Jun", color: "var(--chart-1)" },
} satisfies ChartConfig;
export const browserData = [
{ browser: "chrome", visitors: 275 },
{ browser: "safari", visitors: 200 },
{ browser: "firefox", visitors: 187 },
{ browser: "edge", visitors: 173 },
{ browser: "other", visitors: 90 },
];
/** The radial chart has one bar per browser, so each browser gets one chart token. */
export const browserConfig = {
visitors: { label: "Visitors" },
chrome: { label: "Chrome", color: "var(--chart-1)" },
safari: { label: "Safari", color: "var(--chart-2)" },
firefox: { label: "Firefox", color: "var(--chart-3)" },
edge: { label: "Edge", color: "var(--chart-4)" },
other: { label: "Other", color: "var(--chart-5)" },
} satisfies ChartConfig;

Bar Chart

ChartBar draws one bar for each value. Bars with the same stackId stack. Other bars stand side by side. A number radius rounds the bar end. Add ChartYAxis to show the values.

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

Stacked Bars

Four numbers in radius set the top left, top right, bottom right and bottom left corners, as in Recharts. In a stack, round the bottom of the first bar and the top of the last bar.

Set stackOffset="expand" on ChartContainer to stack each category to 100%. The y axis then runs from 0 to 1, so format its ticks as percents. Areas stack the same way.

---
import {
ChartBar,
ChartContainer,
ChartGrid,
ChartXAxis,
ChartYAxis,
} from "@/components/starwind/chart";
import { visitorConfig, visitorData } from "@/charts/visitor-charts";
---
<ChartContainer config={visitorConfig} data={visitorData} stackOffset="expand" class="max-w-xl">
<ChartGrid vertical={false} />
<ChartXAxis dataKey="month" tickFormatter={{ maxLength: 3 }} />
<ChartYAxis tickFormatter={{ number: { style: "percent" } }} />
<ChartBar dataKey="desktop" stackId="a" radius={[0, 0, 4, 4]} />
<ChartBar dataKey="mobile" stackId="a" radius={[4, 4, 0, 0]} />
</ChartContainer>

Area Chart

ChartArea draws a filled area under a line. Areas with the same stackId stack. Other areas overlap. type sets the curve: natural, monotone, linear or step. This chart also uses a line indicator in the tooltip.

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

Line Chart

ChartLine draws a line through the values. Set dot to draw a dot at every value. The chart draws a dot at the focused value by default. Set activeDot={false} to remove it. An object, such as dot={{ r: 4, fill: "var(--card)" }}, sets the dot radius, fill and stroke, as in shadcn/ui.

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

Donut Chart

ChartPie draws one slice for each data row. dataKey is the value field and nameKey is the field that names each slice. The config gives each slice its label and color by that name. An innerRadius above 0 makes a donut. A radius is a number of pixels or a percent of the available radius. ChartLabel shows the total of the visible slices in the center. Give it a value to show your own text. Add one ChartLabel for each line, and move a line down with dy. fontSize, fontWeight and fill set the look of each line.

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

The pie draws a thin line in the card color between slices. stroke and strokeWidth set its color and width, and paddingAngle sets the gap in degrees.

Radar Chart

ChartRadar draws one closed shape for each series. ChartPolarAngleAxis sets the category field and shows its labels. ChartPolarGrid draws the rings. Set gridType="circle" for round rings. dot and activeDot work as on ChartLine.

ChartPolarGrid takes the grid props of shadcn/ui radar charts:

  • radialLines={false} removes the lines from the center.
  • fill and fillOpacity fill the rings.
  • stroke and strokeWidth set the color and width of the rings and the lines.
  • polarRadius sets the ring radii in pixels, such as polarRadius={[90]} for one ring.
Use arrow keys to inspect values. Enter pins details. Escape dismisses. Exact values follow in a table.

Radial Chart

ChartRadialBar draws one ring bar for each data row. Like ChartPie, it uses nameKey to find the label and color of each bar in the config. background draws a muted track behind each bar.

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

Gradients

Add a ChartLinearGradient with an id and its color stops. Then set fill="url(#id)" on a ChartArea or ChartBar. Offsets take numbers from 0 to 1 or percent strings such as "5%". Without coordinates, the gradient runs from left to right, as in SVG. Set x2={0} and y2={1} for a gradient from top to bottom, as in shadcn/ui.

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

Labels

The label prop of ChartBar, ChartLine, ChartArea and ChartPie draws the value of each bar, point or slice. It takes the place of a shadcn/ui LabelList. Set label to true, or give an object with dataKey, position, offset, fill, fontSize and formatter. position takes top, inside, insideLeft, insideStart, right or outside. formatter takes a ChartFormat object in every framework and a function in React, Vue and Svelte.

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

Pie labels sit outside the slices, and a line joins each label to its slice. Set labelLine={false} to remove the lines, or label={{ position: "inside" }} to put the labels in the slices.

Theming

Charts use your theme colors. Use CSS variables (recommended) or colors in any CSS format, such as hex, hsl or oklch.

CSS Variables

starwind add chart adds the chart tokens --chart-1 to --chart-5 to your CSS file. They use the blue ramp of the Starwind theme. Change them to use other colors:

src/styles/starwind.css
:root {
--chart-1: var(--color-blue-300);
--chart-2: var(--color-blue-500);
--chart-3: var(--color-blue-600);
--chart-4: var(--color-blue-700);
--chart-5: var(--color-blue-800);
}
.dark {
--chart-1: var(--color-blue-300);
--chart-2: var(--color-blue-500);
--chart-3: var(--color-blue-600);
--chart-4: var(--color-blue-700);
--chart-5: var(--color-blue-800);
}

Then use the tokens in your chart config:

export const chartConfig = {
desktop: { label: "Desktop", color: "var(--chart-1)" },
mobile: { label: "Mobile", color: "var(--chart-2)" },
} satisfies ChartConfig;

Color Formats

You can also set colors in the chart config directly. Use the color format that you prefer:

export const chartConfig = {
desktop: { label: "Desktop", color: "#2563eb" },
mobile: { label: "Mobile", color: "oklch(0.62 0.19 260)" },
} satisfies ChartConfig;

Using Colors

ChartContainer writes the color of each config key to a --color-<key> CSS variable inside the chart. In your own tooltip or legend content, use it in a Tailwind class such as bg-(--color-desktop). To give one part its own color, set fill or stroke on the part, for example <ChartBar dataKey="desktop" fill="var(--color-mobile)" />.

Formatting

tickFormatter on ChartXAxis, ChartYAxis and ChartPolarAngleAxis changes the tick labels. It takes a ChartFormat object in every framework. React, Vue and Svelte also take a function.

In Astro, use a format object, because functions cannot go from the server to the browser.

A ChartFormat object is plain data:

FieldTypeDescription
configLabelbooleanShows the config label of the value, as chartConfig[value]?.label.
maxLengthnumberKeeps the first N characters. { maxLength: 3 } gives the same text as value.slice(0, 3).
numberIntl.NumberFormatOptionsFormats numbers.
dateIntl.DateTimeFormatOptionsFormats Date values, date strings and timestamps.
prefixstringText before the result.
suffixstringText after the result.
localestringThe locale of number and date. The default is "en-US".

Dates use the UTC time zone unless date.timeZone sets one.

// 1250 becomes "$1,250".
const currency = { number: { style: "currency", currency: "USD", maximumFractionDigits: 0 } };
// "2024-04-01" becomes "Apr 1".
const shortDate = { date: { month: "short", day: "numeric" } };
// 0.42 becomes "42%".
const percent = { number: { style: "percent" } };
// "chrome" becomes "Chrome", the label of the chrome config key.
const browserName = { configLabel: true };

In React, Vue and Svelte, you can pass a function in place of the object:

---
import { ChartBar, ChartContainer, ChartGrid, ChartXAxis } from "@/components/starwind/chart";
import { visitorConfig, visitorData } from "@/charts/visitor-charts";
---
<ChartContainer config={visitorConfig} data={visitorData} class="max-w-xl">
<ChartGrid vertical={false} />
<ChartXAxis dataKey="month" tickFormatter={{ maxLength: 3 }} />
<ChartBar dataKey="desktop" radius={4} />
<ChartBar dataKey="mobile" radius={4} />
</ChartContainer>

Tooltip

A chart tooltip shows a label, and a name, an indicator and a value for each series. Use the ChartTooltipContent props to change which parts it shows.

ChartContainer shows the tooltip with a dot indicator by default. Set tooltip={false} to remove it, or tooltip="native" to use the TanStack Charts tooltip.

A bar chart draws a hover band behind the focused bars. Set cursor={false} on ChartTooltip to remove it, as in shadcn/ui.

Props

PropTypeDescription
indicatordot, line or dashedThe indicator style. The default is dot.
hideLabelbooleanHides the label.
hideIndicatorbooleanHides the indicator.
labelstring or framework contentThe label to show in place of the data label.
labelKeystringThe config or data key to use for the label.
nameKeystringThe config or data key to use for the name.
valueKeystringThe data key to use for the value.
colorstringOne indicator color for all series.
formatterChartFormat or functionFormats each row. A ChartFormat object formats the value. A function gives the complete row, with the same arguments as shadcn/ui charts.
labelFormatterChartFormat or functionFormats the label. A function gives the complete label, with the same arguments as shadcn/ui charts.

The label class prop is labelClassName in React and labelClass in Astro, Vue and Svelte.

Pie and radial charts pass their nameKey to the tooltip for you.

Formatters

formatter and labelFormatter take a ChartFormat object in every framework. See Formatting. React, Vue and Svelte also take functions.

---
import {
ChartBar,
ChartContainer,
ChartGrid,
ChartTooltip,
ChartTooltipContent,
ChartXAxis,
} from "@/components/starwind/chart";
import { visitorConfig, visitorData } from "@/charts/visitor-charts";
---
<ChartContainer config={visitorConfig} data={visitorData} class="max-w-xl">
<ChartGrid vertical={false} />
<ChartXAxis dataKey="month" tickFormatter={{ maxLength: 3 }} />
<ChartBar dataKey="desktop" radius={4} />
<ChartBar dataKey="mobile" radius={4} />
<ChartTooltip>
<ChartTooltipContent
slot="content"
labelFormatter={{ suffix: " 2024" }}
formatter={{ number: { maximumFractionDigits: 0 }, suffix: " visitors" }}
/>
</ChartTooltip>
</ChartContainer>

Colors

The tooltip gets each series color from the chart config.

Custom

Give ChartTooltip its content with the content prop in React, a content slot in Astro and Vue, or a content snippet in Svelte. See the Area Chart example.

To set the tooltip content on ChartContainer itself, use the tooltip prop in React, a tooltip slot in Astro and Vue, or a tooltip snippet in Svelte.

Legend

Add a ChartLegend to show a legend where you place it. ChartLegend renders ChartLegendContent for you.

The legend lists the series that the chart draws. Each legend item is a button that hides or shows its series. For a pie or radial chart, each item hides or shows one slice or bar. Set hideIcon to show the color swatch when the config gives a series an icon.

Colors

The legend gets each series color from the chart config.

Visible Series

To control the visible series, use visible, defaultVisible and onVisibleChange in React, v-model:visible and the visibleChange event in Vue, and bind:visible with onVisibleChange in Svelte. In Astro, set visible for the first keys.

Accessibility

  • Focus a chart with the Tab key. Use the arrow keys, Home and End to move between points. The keyboard shows the same tooltip as the pointer.
  • Screen readers announce the visible tooltip rows.
  • Each legend item is a toggle button. Screen readers announce if its series is visible.
  • Each chart gets an accessible name from its mark parts and config labels, such as “Bar chart of Desktop and Mobile”. Set aria-label on ChartContainer to tell what the chart shows.
---
import { ChartBar, ChartContainer, ChartGrid, ChartXAxis } from "@/components/starwind/chart";
import { visitorConfig, visitorData } from "@/charts/visitor-charts";
---
<ChartContainer
config={visitorConfig}
data={visitorData}
aria-label="Desktop and mobile visitors from January to June"
class="max-w-xl"
>
<ChartGrid vertical={false} />
<ChartXAxis dataKey="month" tickFormatter={{ maxLength: 3 }} />
<ChartBar dataKey="desktop" radius={4} />
<ChartBar dataKey="mobile" radius={4} />
</ChartContainer>

RTL

Put the chart inside a container with dir="rtl", or use an RTL page. The tooltip and the legend follow the direction. The plot stays unmirrored, as in shadcn/ui charts, so the first category stays on the left.

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

Advanced: Chart Modules

For other charts, such as horizontal bars, a scatter chart or a custom mark, write a chart module. A chart module uses native TanStack Charts marks and scales. Starwind still adds the tooltip, the legend toggles and the config colors.

Call defineChartModule with an id, an ariaLabel and a create function. The chart calls create with a chart context each time the data or the visible series change. Use the context to read the data, remove the hidden series with isVisible, and give TanStack Charts the config colors, the chart theme and the Starwind tooltip.

Keep the module in its own file, so a page that imports only your data loads no chart module code.

src/charts/horizontal-bar-chart.ts
import { barX, defineChart } from "@tanstack/charts";
import { scaleBand } from "@tanstack/charts/scales/band";
import { scaleLinear } from "@tanstack/charts/scales/linear";
import type { VisitorRow } from "@/charts/visitor-charts";
import { defineChartModule } from "@/components/starwind/chart";
/** A horizontal bar chart of desktop visitors. The chart parts draw vertical bars only. */
export const horizontalBarChart = defineChartModule<VisitorRow>({
id: "visitors-horizontal-bar",
ariaLabel: "Horizontal bar chart of desktop visitors",
create(ctx) {
// One row for each month. Hiding Desktop in a legend removes every bar.
const rows = ctx.isVisible("desktop")
? ctx.data.map((row) => ({ month: row.month, series: "desktop", value: row.desktop }))
: [];
return defineChart(
{
marks: [
barX(rows, { x: "value", y: "month", color: "series", key: "month", radius: { end: 4 } }),
],
scales: {
x: { scale: scaleLinear, nice: true, grid: { stroke: "var(--border)" }, axis: false },
y: {
scale: () =>
scaleBand<string>()
.domain(ctx.data.map((row) => row.month))
.padding(0.28),
axis: { line: false, ticks: { size: 0, format: (month: string) => month.slice(0, 3) } },
},
},
color: ctx.color,
theme: ctx.theme,
},
{ focus: "group-y", maxFocusDistance: Infinity, tooltip: ctx.tooltip({ labelKey: "month" }) },
);
},
});

Pass the module to the chart prop of ChartContainer, with no chart parts inside.

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

In Astro, import the chart module in a client <script>. The chart starts when its module loads.

For a fixed native TanStack Charts definition, use the definition prop in place of chart.

API Reference

Styled Component API

These props are added or materially changed by the installed styled component. Standard HTML attributes remain available through the inherited interfaces noted below. Expand a prop to see named type definitions and framework-specific imports. Follow the Primitive and Runtime links for lower-level behavior props.

Chart

Inherits import("@starwind-ui/runtime").ChartRootProps<T, D, X, Y>.

Contains the following additional props:

Prop Type Default Toggle details
tooltip boolean | "native" —
Description
Provides tooltip content for the control.
Classification
Wrapper prop

Chart Tooltip Content

Inherits Omit<import("@starwind-ui/runtime").ChartTooltipContentProps<T>, "children">.

Contains the following additional props:

Prop Type Default Toggle details
labelClass string —
Description
Adds classes to the tooltip label heading.
Classification
Primitive override
Primitive prop
chart.TooltipName.labelClass

Primitive And Runtime API

Use these references when you need the lower-level behavior APIs behind Chart.

Primitive API

Runtime API

Chart primitive
createChart from @starwind-ui/runtime/chart

Changelog

View version history v1.0.0 1 release

v1.0.0

  • First release. Chart gives you shadcn-style parts in Astro, React, Vue and Svelte. Put ChartBar, ChartLine, ChartArea, ChartPie, ChartRadar or ChartRadialBar inside ChartContainer with your data and a ChartConfig for the label and color of each series. Add ChartXAxis, ChartYAxis, ChartGrid, ChartPolarGrid, ChartPolarAngleAxis and ChartLabel for axes, grid lines and center text. Add ChartLinearGradient for gradient fills, as in shadcn/ui. A radar chart needs ChartPolarAngleAxis. Other axes are optional, as in shadcn/ui: without ChartXAxis, a bar, line or area chart takes its categories from the first text or date field in your data and shows no x-axis labels.
  • The parts also take the props of common shadcn/ui examples. The label prop draws values on bars, lines, areas and pie slices, in place of a nested LabelList. ChartBar takes four corner radii for stacked bars, stackOffset="expand" on ChartContainer stacks to 100%, and cursor={false} on ChartTooltip removes the hover band. Several ChartLabel parts give a donut a total and a caption.
  • ChartTooltip, ChartTooltipContent, ChartLegend and ChartLegendContent add the Starwind tooltip and a legend that hides and shows series. The legend lists only the series that the chart draws. tickFormatter, formatter and labelFormatter take a ChartFormat object in every framework, and a function in React, Vue and Svelte. { configLabel: true } shows the config label of a value.
  • Chart gets its behavior from Starwind Runtime. Runtime draws the chart with TanStack Charts and adds the tooltip, the legend toggles and the series colors from your theme tokens. For a chart that the parts cannot draw, pass a TanStack Charts chart module to the chart prop of ChartContainer.
  • starwind add chart also installs @tanstack/charts and adds any missing chart color tokens to your CSS file. If it cannot edit that file, it prints the token block for you to paste.
  • See the Chart Primitive for the unstyled parts and the behavior API.