Chart
---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>"use client";
import { ChartBar, ChartContainer, ChartGrid, ChartLegend, ChartXAxis, ChartYAxis,} from "@/components/starwind/chart";import { visitorConfig, visitorData } from "@/charts/visitor-charts";
export function Example() { return ( <ChartContainer config={visitorConfig} data={visitorData} className="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> );}<script setup lang="ts">import { ChartBar, ChartContainer, ChartGrid, ChartLegend, ChartXAxis, ChartYAxis,} from "@/components/starwind/chart";import { visitorConfig, visitorData } from "@/charts/visitor-charts";</script>
<template> <ChartContainer :config="visitorConfig" :data="visitorData" class="max-w-xl"> <ChartGrid :vertical="false" /> <ChartXAxis data-key="month" :tick-formatter="{ maxLength: 3 }" /> <ChartYAxis /> <ChartBar data-key="desktop" :radius="4" /> <ChartBar data-key="mobile" :radius="4" /> <ChartLegend /> </ChartContainer></template><script lang="ts"> import { ChartBar, ChartContainer, ChartGrid, ChartLegend, ChartXAxis, ChartYAxis, } from "@/components/starwind/chart"; import { visitorConfig, visitorData } from "@/charts/visitor-charts";</script>
<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>Installation
pnpx starwind@latest add chart --framework astronpx starwind@latest add chart --framework astroyarn dlx starwind@latest add chart --framework astropnpx starwind@latest add chart --framework reactnpx starwind@latest add chart --framework reactyarn dlx starwind@latest add chart --framework reactpnpx starwind@latest add chart --framework vuenpx starwind@latest add chart --framework vueyarn dlx starwind@latest add chart --framework vuepnpx starwind@latest add chart --framework sveltenpx starwind@latest add chart --framework svelteyarn dlx starwind@latest add chart --framework svelteStarwind 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>"use client";
import { ChartBar, ChartContainer, ChartGrid, ChartLegend, ChartXAxis, ChartYAxis,} from "@/components/starwind/chart";import { visitorConfig, visitorData } from "@/charts/visitor-charts";
export function Example() { return ( <ChartContainer config={visitorConfig} data={visitorData} className="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> );}<script setup lang="ts">import { ChartBar, ChartContainer, ChartGrid, ChartLegend, ChartXAxis, ChartYAxis,} from "@/components/starwind/chart";import { visitorConfig, visitorData } from "@/charts/visitor-charts";</script>
<template> <ChartContainer :config="visitorConfig" :data="visitorData" class="max-w-xl"> <ChartGrid :vertical="false" /> <ChartXAxis data-key="month" :tick-formatter="{ maxLength: 3 }" /> <ChartYAxis /> <ChartBar data-key="desktop" :radius="4" /> <ChartBar data-key="mobile" :radius="4" /> <ChartLegend /> </ChartContainer></template><script lang="ts"> import { ChartBar, ChartContainer, ChartGrid, ChartLegend, ChartXAxis, ChartYAxis, } from "@/components/starwind/chart"; import { visitorConfig, visitorData } from "@/charts/visitor-charts";</script>
<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 └── ChartLegendContentThe 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/ui | Starwind |
|---|---|
BarChart, LineChart, AreaChart, PieChart, RadarChart, RadialBarChart | ChartContainer. The mark parts set the chart type. |
stackOffset on the chart wrapper | stackOffset on ChartContainer |
Bar, Line, Area, Pie, Radar, RadialBar | ChartBar, ChartLine, ChartArea, ChartPie, ChartRadar, ChartRadialBar |
XAxis, YAxis | ChartXAxis, ChartYAxis |
CartesianGrid | ChartGrid |
PolarGrid, PolarAngleAxis | ChartPolarGrid, ChartPolarAngleAxis |
Label in a pie | One ChartLabel position="center" for each line of text |
LabelList in a mark | The label prop of the mark. See Labels. |
linearGradient in defs | ChartLinearGradient. See Gradients. |
chartConfig[value]?.label in a formatter | { configLabel: true }. See Formatting. |
ChartTooltip, ChartTooltipContent, ChartLegend, ChartLegendContent | The 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.
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.
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>"use client";
import { ChartBar, ChartContainer } from "@/components/starwind/chart";import { visitorConfig, visitorData } from "@/charts/visitor-charts";
export function Example() { return ( <ChartContainer config={visitorConfig} data={visitorData} className="max-w-xl"> <ChartBar dataKey="desktop" radius={4} /> <ChartBar dataKey="mobile" radius={4} /> </ChartContainer> );}<script setup lang="ts">import { ChartBar, ChartContainer } from "@/components/starwind/chart";import { visitorConfig, visitorData } from "@/charts/visitor-charts";</script>
<template> <ChartContainer :config="visitorConfig" :data="visitorData" class="max-w-xl"> <ChartBar data-key="desktop" :radius="4" /> <ChartBar data-key="mobile" :radius="4" /> </ChartContainer></template><script lang="ts"> import { ChartBar, ChartContainer } from "@/components/starwind/chart"; import { visitorConfig, visitorData } from "@/charts/visitor-charts";</script>
<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>"use client";
import { ChartBar, ChartContainer, ChartGrid } from "@/components/starwind/chart";import { visitorConfig, visitorData } from "@/charts/visitor-charts";
export function Example() { return ( <ChartContainer config={visitorConfig} data={visitorData} className="max-w-xl"> <ChartGrid vertical={false} /> <ChartBar dataKey="desktop" radius={4} /> <ChartBar dataKey="mobile" radius={4} /> </ChartContainer> );}<script setup lang="ts">import { ChartBar, ChartContainer, ChartGrid } from "@/components/starwind/chart";import { visitorConfig, visitorData } from "@/charts/visitor-charts";</script>
<template> <ChartContainer :config="visitorConfig" :data="visitorData" class="max-w-xl"> <ChartGrid :vertical="false" /> <ChartBar data-key="desktop" :radius="4" /> <ChartBar data-key="mobile" :radius="4" /> </ChartContainer></template><script lang="ts"> import { ChartBar, ChartContainer, ChartGrid } from "@/components/starwind/chart"; import { visitorConfig, visitorData } from "@/charts/visitor-charts";</script>
<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>"use client";
import { ChartBar, ChartContainer, ChartGrid, ChartXAxis } from "@/components/starwind/chart";import { visitorConfig, visitorData } from "@/charts/visitor-charts";
export function Example() { return ( <ChartContainer config={visitorConfig} data={visitorData} className="max-w-xl"> <ChartGrid vertical={false} /> <ChartXAxis dataKey="month" tickFormatter={{ maxLength: 3 }} /> <ChartBar dataKey="desktop" radius={4} /> <ChartBar dataKey="mobile" radius={4} /> </ChartContainer> );}<script setup lang="ts">import { ChartBar, ChartContainer, ChartGrid, ChartXAxis } from "@/components/starwind/chart";import { visitorConfig, visitorData } from "@/charts/visitor-charts";</script>
<template> <ChartContainer :config="visitorConfig" :data="visitorData" class="max-w-xl"> <ChartGrid :vertical="false" /> <ChartXAxis data-key="month" :tick-formatter="{ maxLength: 3 }" /> <ChartBar data-key="desktop" :radius="4" /> <ChartBar data-key="mobile" :radius="4" /> </ChartContainer></template><script lang="ts"> import { ChartBar, ChartContainer, ChartGrid, ChartXAxis } from "@/components/starwind/chart"; import { visitorConfig, visitorData } from "@/charts/visitor-charts";</script>
<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>"use client";
import { ChartBar, ChartContainer, ChartGrid, ChartTooltip, ChartTooltipContent, ChartXAxis,} from "@/components/starwind/chart";import { visitorConfig, visitorData } from "@/charts/visitor-charts";
export function Example() { return ( <ChartContainer config={visitorConfig} data={visitorData} className="max-w-xl"> <ChartGrid vertical={false} /> <ChartXAxis dataKey="month" tickFormatter={{ maxLength: 3 }} /> <ChartBar dataKey="desktop" radius={4} /> <ChartBar dataKey="mobile" radius={4} /> <ChartTooltip content={<ChartTooltipContent indicator="line" />} /> </ChartContainer> );}<script setup lang="ts">import { ChartBar, ChartContainer, ChartGrid, ChartTooltip, ChartTooltipContent, ChartXAxis,} from "@/components/starwind/chart";import { visitorConfig, visitorData } from "@/charts/visitor-charts";</script>
<template> <ChartContainer :config="visitorConfig" :data="visitorData" class="max-w-xl"> <ChartGrid :vertical="false" /> <ChartXAxis data-key="month" :tick-formatter="{ maxLength: 3 }" /> <ChartBar data-key="desktop" :radius="4" /> <ChartBar data-key="mobile" :radius="4" /> <ChartTooltip> <template #content> <ChartTooltipContent indicator="line" /> </template> </ChartTooltip> </ChartContainer></template><script lang="ts"> import { ChartBar, ChartContainer, ChartGrid, ChartTooltip, ChartTooltipContent, ChartXAxis, } from "@/components/starwind/chart"; import { visitorConfig, visitorData } from "@/charts/visitor-charts";</script>
<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> {#snippet content()} <ChartTooltipContent indicator="line" /> {/snippet} </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>"use client";
import { ChartBar, ChartContainer, ChartGrid, ChartLegend, ChartTooltip, ChartTooltipContent, ChartXAxis,} from "@/components/starwind/chart";import { visitorConfig, visitorData } from "@/charts/visitor-charts";
export function Example() { return ( <ChartContainer config={visitorConfig} data={visitorData} className="max-w-xl"> <ChartGrid vertical={false} /> <ChartXAxis dataKey="month" tickFormatter={{ maxLength: 3 }} /> <ChartBar dataKey="desktop" radius={4} /> <ChartBar dataKey="mobile" radius={4} /> <ChartTooltip content={<ChartTooltipContent indicator="line" />} /> <ChartLegend /> </ChartContainer> );}<script setup lang="ts">import { ChartBar, ChartContainer, ChartGrid, ChartLegend, ChartTooltip, ChartTooltipContent, ChartXAxis,} from "@/components/starwind/chart";import { visitorConfig, visitorData } from "@/charts/visitor-charts";</script>
<template> <ChartContainer :config="visitorConfig" :data="visitorData" class="max-w-xl"> <ChartGrid :vertical="false" /> <ChartXAxis data-key="month" :tick-formatter="{ maxLength: 3 }" /> <ChartBar data-key="desktop" :radius="4" /> <ChartBar data-key="mobile" :radius="4" /> <ChartTooltip> <template #content> <ChartTooltipContent indicator="line" /> </template> </ChartTooltip> <ChartLegend /> </ChartContainer></template><script lang="ts"> import { ChartBar, ChartContainer, ChartGrid, ChartLegend, ChartTooltip, ChartTooltipContent, ChartXAxis, } from "@/components/starwind/chart"; import { visitorConfig, visitorData } from "@/charts/visitor-charts";</script>
<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> {#snippet content()} <ChartTooltipContent indicator="line" /> {/snippet} </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;labelis the text that the tooltip and the legend show for the series.iconreplaces 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.coloris any CSS color. To set one color for light mode and one for dark mode, usethemewithlightanddarkcolors in place ofcolor.
Example Data
The examples on this page import their data and configs from this file.
Show the complete example file
// 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.
---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>"use client";
import { ChartBar, ChartContainer, ChartGrid, ChartLegend, ChartXAxis, ChartYAxis,} from "@/components/starwind/chart";import { visitorConfig, visitorData } from "@/charts/visitor-charts";
export function Example() { return ( <ChartContainer config={visitorConfig} data={visitorData} className="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> );}<script setup lang="ts">import { ChartBar, ChartContainer, ChartGrid, ChartLegend, ChartXAxis, ChartYAxis,} from "@/components/starwind/chart";import { visitorConfig, visitorData } from "@/charts/visitor-charts";</script>
<template> <ChartContainer :config="visitorConfig" :data="visitorData" class="max-w-xl"> <ChartGrid :vertical="false" /> <ChartXAxis data-key="month" :tick-formatter="{ maxLength: 3 }" /> <ChartYAxis /> <ChartBar data-key="desktop" :radius="4" /> <ChartBar data-key="mobile" :radius="4" /> <ChartLegend /> </ChartContainer></template><script lang="ts"> import { ChartBar, ChartContainer, ChartGrid, ChartLegend, ChartXAxis, ChartYAxis, } from "@/components/starwind/chart"; import { visitorConfig, visitorData } from "@/charts/visitor-charts";</script>
<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>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>"use client";
import { ChartBar, ChartContainer, ChartGrid, ChartXAxis, ChartYAxis,} from "@/components/starwind/chart";import { visitorConfig, visitorData } from "@/charts/visitor-charts";
export function Example() { return ( <ChartContainer config={visitorConfig} data={visitorData} stackOffset="expand" className="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> );}<script setup lang="ts">import { ChartBar, ChartContainer, ChartGrid, ChartXAxis, ChartYAxis,} from "@/components/starwind/chart";import { visitorConfig, visitorData } from "@/charts/visitor-charts";</script>
<template> <ChartContainer :config="visitorConfig" :data="visitorData" stack-offset="expand" class="max-w-xl" > <ChartGrid :vertical="false" /> <ChartXAxis data-key="month" :tick-formatter="{ maxLength: 3 }" /> <ChartYAxis :tick-formatter="{ number: { style: 'percent' } }" /> <ChartBar data-key="desktop" stack-id="a" :radius="[0, 0, 4, 4]" /> <ChartBar data-key="mobile" stack-id="a" :radius="[4, 4, 0, 0]" /> </ChartContainer></template><script lang="ts"> import { ChartBar, ChartContainer, ChartGrid, ChartXAxis, ChartYAxis, } from "@/components/starwind/chart"; import { visitorConfig, visitorData } from "@/charts/visitor-charts";</script>
<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.
---import { ChartArea, ChartContainer, ChartGrid, ChartLegend, ChartTooltip, ChartTooltipContent, 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 /> <ChartArea dataKey="desktop" type="monotone" stackId="a" /> <ChartArea dataKey="mobile" type="monotone" stackId="a" /> <ChartTooltip> <ChartTooltipContent slot="content" indicator="line" /> </ChartTooltip> <ChartLegend /></ChartContainer>"use client";
import { ChartArea, ChartContainer, ChartGrid, ChartLegend, ChartTooltip, ChartTooltipContent, ChartXAxis, ChartYAxis,} from "@/components/starwind/chart";import { visitorConfig, visitorData } from "@/charts/visitor-charts";
export function Example() { return ( <ChartContainer config={visitorConfig} data={visitorData} className="max-w-xl"> <ChartGrid vertical={false} /> <ChartXAxis dataKey="month" tickFormatter={{ maxLength: 3 }} /> <ChartYAxis /> <ChartArea dataKey="desktop" type="monotone" stackId="a" /> <ChartArea dataKey="mobile" type="monotone" stackId="a" /> <ChartTooltip content={<ChartTooltipContent indicator="line" />} /> <ChartLegend /> </ChartContainer> );}<script setup lang="ts">import { ChartArea, ChartContainer, ChartGrid, ChartLegend, ChartTooltip, ChartTooltipContent, ChartXAxis, ChartYAxis,} from "@/components/starwind/chart";import { visitorConfig, visitorData } from "@/charts/visitor-charts";</script>
<template> <ChartContainer :config="visitorConfig" :data="visitorData" class="max-w-xl"> <ChartGrid :vertical="false" /> <ChartXAxis data-key="month" :tick-formatter="{ maxLength: 3 }" /> <ChartYAxis /> <ChartArea data-key="desktop" type="monotone" stack-id="a" /> <ChartArea data-key="mobile" type="monotone" stack-id="a" /> <ChartTooltip> <template #content> <ChartTooltipContent indicator="line" /> </template> </ChartTooltip> <ChartLegend /> </ChartContainer></template><script lang="ts"> import { ChartArea, ChartContainer, ChartGrid, ChartLegend, ChartTooltip, ChartTooltipContent, ChartXAxis, ChartYAxis, } from "@/components/starwind/chart"; import { visitorConfig, visitorData } from "@/charts/visitor-charts";</script>
<ChartContainer config={visitorConfig} data={visitorData} class="max-w-xl"> <ChartGrid vertical={false} /> <ChartXAxis dataKey="month" tickFormatter={{ maxLength: 3 }} /> <ChartYAxis /> <ChartArea dataKey="desktop" type="monotone" stackId="a" /> <ChartArea dataKey="mobile" type="monotone" stackId="a" /> <ChartTooltip> {#snippet content()} <ChartTooltipContent indicator="line" /> {/snippet} </ChartTooltip> <ChartLegend /></ChartContainer>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.
---import { ChartContainer, ChartGrid, ChartLine, 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 }} /> <ChartLine dataKey="desktop" /> <ChartTooltip> <ChartTooltipContent slot="content" hideLabel /> </ChartTooltip></ChartContainer>"use client";
import { ChartContainer, ChartGrid, ChartLine, ChartTooltip, ChartTooltipContent, ChartXAxis,} from "@/components/starwind/chart";import { visitorConfig, visitorData } from "@/charts/visitor-charts";
export function Example() { return ( <ChartContainer config={visitorConfig} data={visitorData} className="max-w-xl"> <ChartGrid vertical={false} /> <ChartXAxis dataKey="month" tickFormatter={{ maxLength: 3 }} /> <ChartLine dataKey="desktop" /> <ChartTooltip content={<ChartTooltipContent hideLabel />} /> </ChartContainer> );}<script setup lang="ts">import { ChartContainer, ChartGrid, ChartLine, ChartTooltip, ChartTooltipContent, ChartXAxis,} from "@/components/starwind/chart";import { visitorConfig, visitorData } from "@/charts/visitor-charts";</script>
<template> <ChartContainer :config="visitorConfig" :data="visitorData" class="max-w-xl"> <ChartGrid :vertical="false" /> <ChartXAxis data-key="month" :tick-formatter="{ maxLength: 3 }" /> <ChartLine data-key="desktop" /> <ChartTooltip> <template #content> <ChartTooltipContent hide-label /> </template> </ChartTooltip> </ChartContainer></template><script lang="ts"> import { ChartContainer, ChartGrid, ChartLine, ChartTooltip, ChartTooltipContent, ChartXAxis, } from "@/components/starwind/chart"; import { visitorConfig, visitorData } from "@/charts/visitor-charts";</script>
<ChartContainer config={visitorConfig} data={visitorData} class="max-w-xl"> <ChartGrid vertical={false} /> <ChartXAxis dataKey="month" tickFormatter={{ maxLength: 3 }} /> <ChartLine dataKey="desktop" /> <ChartTooltip> {#snippet content()} <ChartTooltipContent hideLabel /> {/snippet} </ChartTooltip></ChartContainer>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.
---import { ChartContainer, ChartLabel, ChartLegend, ChartPie, ChartTooltip, ChartTooltipContent,} from "@/components/starwind/chart";import { monthConfig, visitorData } from "@/charts/visitor-charts";---
<ChartContainer config={monthConfig} data={visitorData} aria-label="Donut chart of desktop visitors by month" class="max-w-sm"> <ChartPie dataKey="desktop" nameKey="month" innerRadius="58.5%" /> <ChartLabel position="center" fontSize={30} fontWeight={700} /> <ChartLabel position="center" value="Visitors" dy={24} fontSize={12} fill="var(--muted-foreground)" /> <ChartTooltip> <ChartTooltipContent slot="content" hideLabel /> </ChartTooltip> <ChartLegend /></ChartContainer>"use client";
import { ChartContainer, ChartLabel, ChartLegend, ChartPie, ChartTooltip, ChartTooltipContent,} from "@/components/starwind/chart";import { monthConfig, visitorData } from "@/charts/visitor-charts";
export function Example() { return ( <ChartContainer config={monthConfig} data={visitorData} aria-label="Donut chart of desktop visitors by month" className="max-w-sm" > <ChartPie dataKey="desktop" nameKey="month" innerRadius="58.5%" /> <ChartLabel position="center" fontSize={30} fontWeight={700} /> <ChartLabel position="center" value="Visitors" dy={24} fontSize={12} fill="var(--muted-foreground)" /> <ChartTooltip content={<ChartTooltipContent hideLabel />} /> <ChartLegend /> </ChartContainer> );}<script setup lang="ts">import { ChartContainer, ChartLabel, ChartLegend, ChartPie, ChartTooltip, ChartTooltipContent,} from "@/components/starwind/chart";import { monthConfig, visitorData } from "@/charts/visitor-charts";</script>
<template> <ChartContainer :config="monthConfig" :data="visitorData" aria-label="Donut chart of desktop visitors by month" class="max-w-sm" > <ChartPie data-key="desktop" name-key="month" inner-radius="58.5%" /> <ChartLabel position="center" :font-size="30" :font-weight="700" /> <ChartLabel position="center" value="Visitors" :dy="24" :font-size="12" fill="var(--muted-foreground)" /> <ChartTooltip> <template #content> <ChartTooltipContent hide-label /> </template> </ChartTooltip> <ChartLegend /> </ChartContainer></template><script lang="ts"> import { ChartContainer, ChartLabel, ChartLegend, ChartPie, ChartTooltip, ChartTooltipContent, } from "@/components/starwind/chart"; import { monthConfig, visitorData } from "@/charts/visitor-charts";</script>
<ChartContainer config={monthConfig} data={visitorData} aria-label="Donut chart of desktop visitors by month" class="max-w-sm"> <ChartPie dataKey="desktop" nameKey="month" innerRadius="58.5%" /> <ChartLabel position="center" fontSize={30} fontWeight={700} /> <ChartLabel position="center" value="Visitors" dy={24} fontSize={12} fill="var(--muted-foreground)" /> <ChartTooltip> {#snippet content()} <ChartTooltipContent hideLabel /> {/snippet} </ChartTooltip> <ChartLegend /></ChartContainer>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.fillandfillOpacityfill the rings.strokeandstrokeWidthset the color and width of the rings and the lines.polarRadiussets the ring radii in pixels, such aspolarRadius={[90]}for one ring.
---import { ChartContainer, ChartLegend, ChartPolarAngleAxis, ChartPolarGrid, ChartRadar,} from "@/components/starwind/chart";import { visitorConfig, visitorData } from "@/charts/visitor-charts";---
<ChartContainer config={visitorConfig} data={visitorData} class="max-w-sm"> <ChartPolarGrid /> <ChartPolarAngleAxis dataKey="month" tickFormatter={{ maxLength: 3 }} /> <ChartRadar dataKey="desktop" /> <ChartRadar dataKey="mobile" /> <ChartLegend /></ChartContainer>"use client";
import { ChartContainer, ChartLegend, ChartPolarAngleAxis, ChartPolarGrid, ChartRadar,} from "@/components/starwind/chart";import { visitorConfig, visitorData } from "@/charts/visitor-charts";
export function Example() { return ( <ChartContainer config={visitorConfig} data={visitorData} className="max-w-sm"> <ChartPolarGrid /> <ChartPolarAngleAxis dataKey="month" tickFormatter={{ maxLength: 3 }} /> <ChartRadar dataKey="desktop" /> <ChartRadar dataKey="mobile" /> <ChartLegend /> </ChartContainer> );}<script setup lang="ts">import { ChartContainer, ChartLegend, ChartPolarAngleAxis, ChartPolarGrid, ChartRadar,} from "@/components/starwind/chart";import { visitorConfig, visitorData } from "@/charts/visitor-charts";</script>
<template> <ChartContainer :config="visitorConfig" :data="visitorData" class="max-w-sm"> <ChartPolarGrid /> <ChartPolarAngleAxis data-key="month" :tick-formatter="{ maxLength: 3 }" /> <ChartRadar data-key="desktop" /> <ChartRadar data-key="mobile" /> <ChartLegend /> </ChartContainer></template><script lang="ts"> import { ChartContainer, ChartLegend, ChartPolarAngleAxis, ChartPolarGrid, ChartRadar, } from "@/components/starwind/chart"; import { visitorConfig, visitorData } from "@/charts/visitor-charts";</script>
<ChartContainer config={visitorConfig} data={visitorData} class="max-w-sm"> <ChartPolarGrid /> <ChartPolarAngleAxis dataKey="month" tickFormatter={{ maxLength: 3 }} /> <ChartRadar dataKey="desktop" /> <ChartRadar dataKey="mobile" /> <ChartLegend /></ChartContainer>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.
---import { ChartContainer, ChartRadialBar } from "@/components/starwind/chart";import { browserConfig, browserData } from "@/charts/visitor-charts";---
<ChartContainer config={browserConfig} data={browserData} class="max-w-sm"> <ChartRadialBar dataKey="visitors" nameKey="browser" background /></ChartContainer>"use client";
import { ChartContainer, ChartRadialBar } from "@/components/starwind/chart";import { browserConfig, browserData } from "@/charts/visitor-charts";
export function Example() { return ( <ChartContainer config={browserConfig} data={browserData} className="max-w-sm"> <ChartRadialBar dataKey="visitors" nameKey="browser" background /> </ChartContainer> );}<script setup lang="ts">import { ChartContainer, ChartRadialBar } from "@/components/starwind/chart";import { browserConfig, browserData } from "@/charts/visitor-charts";</script>
<template> <ChartContainer :config="browserConfig" :data="browserData" class="max-w-sm"> <ChartRadialBar data-key="visitors" name-key="browser" background /> </ChartContainer></template><script lang="ts"> import { ChartContainer, ChartRadialBar } from "@/components/starwind/chart"; import { browserConfig, browserData } from "@/charts/visitor-charts";</script>
<ChartContainer config={browserConfig} data={browserData} class="max-w-sm"> <ChartRadialBar dataKey="visitors" nameKey="browser" background /></ChartContainer>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.
---import { ChartArea, ChartContainer, ChartGrid, ChartLinearGradient, ChartTooltip, 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 }} /> <ChartTooltip cursor={false} /> <ChartLinearGradient id="fillDesktop" x1={0} y1={0} x2={0} y2={1} stops={[ { offset: "5%", stopColor: "var(--color-desktop)", stopOpacity: 0.8 }, { offset: "95%", stopColor: "var(--color-desktop)", stopOpacity: 0.1 }, ]} /> <ChartLinearGradient id="fillMobile" x1={0} y1={0} x2={0} y2={1} stops={[ { offset: "5%", stopColor: "var(--color-mobile)", stopOpacity: 0.8 }, { offset: "95%", stopColor: "var(--color-mobile)", stopOpacity: 0.1 }, ]} /> <ChartArea dataKey="mobile" type="natural" fill="url(#fillMobile)" fillOpacity={0.4} stackId="a" /> <ChartArea dataKey="desktop" type="natural" fill="url(#fillDesktop)" fillOpacity={0.4} stackId="a" /></ChartContainer>"use client";
import { ChartArea, ChartContainer, ChartGrid, ChartLinearGradient, ChartTooltip, ChartXAxis,} from "@/components/starwind/chart";import { visitorConfig, visitorData } from "@/charts/visitor-charts";
export function Example() { return ( <ChartContainer config={visitorConfig} data={visitorData} className="max-w-xl"> <ChartGrid vertical={false} /> <ChartXAxis dataKey="month" tickFormatter={{ maxLength: 3 }} /> <ChartTooltip cursor={false} /> <ChartLinearGradient id="fillDesktop" x1={0} y1={0} x2={0} y2={1} stops={[ { offset: "5%", stopColor: "var(--color-desktop)", stopOpacity: 0.8 }, { offset: "95%", stopColor: "var(--color-desktop)", stopOpacity: 0.1 }, ]} /> <ChartLinearGradient id="fillMobile" x1={0} y1={0} x2={0} y2={1} stops={[ { offset: "5%", stopColor: "var(--color-mobile)", stopOpacity: 0.8 }, { offset: "95%", stopColor: "var(--color-mobile)", stopOpacity: 0.1 }, ]} /> <ChartArea dataKey="mobile" type="natural" fill="url(#fillMobile)" fillOpacity={0.4} stackId="a" /> <ChartArea dataKey="desktop" type="natural" fill="url(#fillDesktop)" fillOpacity={0.4} stackId="a" /> </ChartContainer> );}<script setup lang="ts">import { ChartArea, ChartContainer, ChartGrid, ChartLinearGradient, ChartTooltip, ChartXAxis,} from "@/components/starwind/chart";import { visitorConfig, visitorData } from "@/charts/visitor-charts";</script>
<template> <ChartContainer :config="visitorConfig" :data="visitorData" class="max-w-xl"> <ChartGrid :vertical="false" /> <ChartXAxis data-key="month" :tick-formatter="{ maxLength: 3 }" /> <ChartTooltip :cursor="false" /> <ChartLinearGradient id="fillDesktop" :x1="0" :y1="0" :x2="0" :y2="1" :stops="[ { offset: '5%', stopColor: 'var(--color-desktop)', stopOpacity: 0.8 }, { offset: '95%', stopColor: 'var(--color-desktop)', stopOpacity: 0.1 }, ]" /> <ChartLinearGradient id="fillMobile" :x1="0" :y1="0" :x2="0" :y2="1" :stops="[ { offset: '5%', stopColor: 'var(--color-mobile)', stopOpacity: 0.8 }, { offset: '95%', stopColor: 'var(--color-mobile)', stopOpacity: 0.1 }, ]" /> <ChartArea data-key="mobile" type="natural" fill="url(#fillMobile)" :fill-opacity="0.4" stack-id="a" /> <ChartArea data-key="desktop" type="natural" fill="url(#fillDesktop)" :fill-opacity="0.4" stack-id="a" /> </ChartContainer></template><script lang="ts"> import { ChartArea, ChartContainer, ChartGrid, ChartLinearGradient, ChartTooltip, ChartXAxis, } from "@/components/starwind/chart"; import { visitorConfig, visitorData } from "@/charts/visitor-charts";</script>
<ChartContainer config={visitorConfig} data={visitorData} class="max-w-xl"> <ChartGrid vertical={false} /> <ChartXAxis dataKey="month" tickFormatter={{ maxLength: 3 }} /> <ChartTooltip cursor={false} /> <ChartLinearGradient id="fillDesktop" x1={0} y1={0} x2={0} y2={1} stops={[ { offset: "5%", stopColor: "var(--color-desktop)", stopOpacity: 0.8 }, { offset: "95%", stopColor: "var(--color-desktop)", stopOpacity: 0.1 }, ]} /> <ChartLinearGradient id="fillMobile" x1={0} y1={0} x2={0} y2={1} stops={[ { offset: "5%", stopColor: "var(--color-mobile)", stopOpacity: 0.8 }, { offset: "95%", stopColor: "var(--color-mobile)", stopOpacity: 0.1 }, ]} /> <ChartArea dataKey="mobile" type="natural" fill="url(#fillMobile)" fillOpacity={0.4} stackId="a" /> <ChartArea dataKey="desktop" type="natural" fill="url(#fillDesktop)" fillOpacity={0.4} stackId="a" /></ChartContainer>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.
---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={8} label={{ position: "top", offset: 12, fontSize: 12 }} /></ChartContainer>"use client";
import { ChartBar, ChartContainer, ChartGrid, ChartXAxis } from "@/components/starwind/chart";import { visitorConfig, visitorData } from "@/charts/visitor-charts";
export function Example() { return ( <ChartContainer config={visitorConfig} data={visitorData} className="max-w-xl"> <ChartGrid vertical={false} /> <ChartXAxis dataKey="month" tickFormatter={{ maxLength: 3 }} /> <ChartBar dataKey="desktop" radius={8} label={{ position: "top", offset: 12, fontSize: 12 }} /> </ChartContainer> );}<script setup lang="ts">import { ChartBar, ChartContainer, ChartGrid, ChartXAxis } from "@/components/starwind/chart";import { visitorConfig, visitorData } from "@/charts/visitor-charts";</script>
<template> <ChartContainer :config="visitorConfig" :data="visitorData" class="max-w-xl"> <ChartGrid :vertical="false" /> <ChartXAxis data-key="month" :tick-formatter="{ maxLength: 3 }" /> <ChartBar data-key="desktop" :radius="8" :label="{ position: 'top', offset: 12, fontSize: 12 }" /> </ChartContainer></template><script lang="ts"> import { ChartBar, ChartContainer, ChartGrid, ChartXAxis } from "@/components/starwind/chart"; import { visitorConfig, visitorData } from "@/charts/visitor-charts";</script>
<ChartContainer config={visitorConfig} data={visitorData} class="max-w-xl"> <ChartGrid vertical={false} /> <ChartXAxis dataKey="month" tickFormatter={{ maxLength: 3 }} /> <ChartBar dataKey="desktop" radius={8} label={{ position: "top", offset: 12, fontSize: 12 }} /></ChartContainer>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:
: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:
| Field | Type | Description |
|---|---|---|
configLabel | boolean | Shows the config label of the value, as chartConfig[value]?.label. |
maxLength | number | Keeps the first N characters. { maxLength: 3 } gives the same text as value.slice(0, 3). |
number | Intl.NumberFormatOptions | Formats numbers. |
date | Intl.DateTimeFormatOptions | Formats Date values, date strings and timestamps. |
prefix | string | Text before the result. |
suffix | string | Text after the result. |
locale | string | The 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>"use client";
import { ChartBar, ChartContainer, ChartGrid, ChartXAxis } from "@/components/starwind/chart";import { visitorConfig, visitorData } from "@/charts/visitor-charts";
export function Example() { return ( <ChartContainer config={visitorConfig} data={visitorData} className="max-w-xl"> <ChartGrid vertical={false} /> <ChartXAxis dataKey="month" tickFormatter={(value: string) => value.slice(0, 3)} /> <ChartBar dataKey="desktop" radius={4} /> <ChartBar dataKey="mobile" radius={4} /> </ChartContainer> );}<script setup lang="ts">import { ChartBar, ChartContainer, ChartGrid, ChartXAxis } from "@/components/starwind/chart";import { visitorConfig, visitorData } from "@/charts/visitor-charts";const shortMonth = (value: string) => value.slice(0, 3);</script>
<template> <ChartContainer :config="visitorConfig" :data="visitorData" class="max-w-xl"> <ChartGrid :vertical="false" /> <ChartXAxis data-key="month" :tick-formatter="shortMonth" /> <ChartBar data-key="desktop" :radius="4" /> <ChartBar data-key="mobile" :radius="4" /> </ChartContainer></template><script lang="ts"> import { ChartBar, ChartContainer, ChartGrid, ChartXAxis } from "@/components/starwind/chart"; import { visitorConfig, visitorData } from "@/charts/visitor-charts"; const shortMonth = (value: string) => value.slice(0, 3);</script>
<ChartContainer config={visitorConfig} data={visitorData} class="max-w-xl"> <ChartGrid vertical={false} /> <ChartXAxis dataKey="month" tickFormatter={shortMonth} /> <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
| Prop | Type | Description |
|---|---|---|
indicator | dot, line or dashed | The indicator style. The default is dot. |
hideLabel | boolean | Hides the label. |
hideIndicator | boolean | Hides the indicator. |
label | string or framework content | The label to show in place of the data label. |
labelKey | string | The config or data key to use for the label. |
nameKey | string | The config or data key to use for the name. |
valueKey | string | The data key to use for the value. |
color | string | One indicator color for all series. |
formatter | ChartFormat or function | Formats each row. A ChartFormat object formats the value. A function gives the complete row, with the same arguments as shadcn/ui charts. |
labelFormatter | ChartFormat or function | Formats 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>"use client";
import { ChartBar, ChartContainer, ChartGrid, ChartTooltip, ChartTooltipContent, ChartXAxis,} from "@/components/starwind/chart";import { visitorConfig, visitorData } from "@/charts/visitor-charts";
export function Example() { return ( <ChartContainer config={visitorConfig} data={visitorData} className="max-w-xl"> <ChartGrid vertical={false} /> <ChartXAxis dataKey="month" tickFormatter={{ maxLength: 3 }} /> <ChartBar dataKey="desktop" radius={4} /> <ChartBar dataKey="mobile" radius={4} /> <ChartTooltip content={ <ChartTooltipContent labelFormatter={(label) => `${label} 2024`} formatter={{ number: { maximumFractionDigits: 0 }, suffix: " visitors" }} /> } /> </ChartContainer> );}<script setup lang="ts">import { ChartBar, ChartContainer, ChartGrid, ChartTooltip, ChartTooltipContent, ChartXAxis,} from "@/components/starwind/chart";import { visitorConfig, visitorData } from "@/charts/visitor-charts";</script>
<template> <ChartContainer :config="visitorConfig" :data="visitorData" class="max-w-xl"> <ChartGrid :vertical="false" /> <ChartXAxis data-key="month" :tick-formatter="{ maxLength: 3 }" /> <ChartBar data-key="desktop" :radius="4" /> <ChartBar data-key="mobile" :radius="4" /> <ChartTooltip> <template #content> <ChartTooltipContent :label-formatter="(label: unknown) => `${label} 2024`" :formatter="{ number: { maximumFractionDigits: 0 }, suffix: ' visitors' }" /> </template> </ChartTooltip> </ChartContainer></template><script lang="ts"> import { ChartBar, ChartContainer, ChartGrid, ChartTooltip, ChartTooltipContent, ChartXAxis, } from "@/components/starwind/chart"; import { visitorConfig, visitorData } from "@/charts/visitor-charts";</script>
<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> {#snippet content()} <ChartTooltipContent labelFormatter={(label) => `${label} 2024`} formatter={{ number: { maximumFractionDigits: 0 }, suffix: " visitors" }} /> {/snippet} </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-labelonChartContainerto 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>"use client";
import { ChartBar, ChartContainer, ChartGrid, ChartXAxis } from "@/components/starwind/chart";import { visitorConfig, visitorData } from "@/charts/visitor-charts";
export function Example() { return ( <ChartContainer config={visitorConfig} data={visitorData} aria-label="Desktop and mobile visitors from January to June" className="max-w-xl" > <ChartGrid vertical={false} /> <ChartXAxis dataKey="month" tickFormatter={{ maxLength: 3 }} /> <ChartBar dataKey="desktop" radius={4} /> <ChartBar dataKey="mobile" radius={4} /> </ChartContainer> );}<script setup lang="ts">import { ChartBar, ChartContainer, ChartGrid, ChartXAxis } from "@/components/starwind/chart";import { visitorConfig, visitorData } from "@/charts/visitor-charts";</script>
<template> <ChartContainer :config="visitorConfig" :data="visitorData" aria-label="Desktop and mobile visitors from January to June" class="max-w-xl" > <ChartGrid :vertical="false" /> <ChartXAxis data-key="month" :tick-formatter="{ maxLength: 3 }" /> <ChartBar data-key="desktop" :radius="4" /> <ChartBar data-key="mobile" :radius="4" /> </ChartContainer></template><script lang="ts"> import { ChartBar, ChartContainer, ChartGrid, ChartXAxis } from "@/components/starwind/chart"; import { visitorConfig, visitorData } from "@/charts/visitor-charts";</script>
<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.
---import type { ChartConfig } from "@/components/starwind/chart";import { ChartBar, ChartContainer, ChartGrid, ChartLegend, ChartXAxis,} from "@/components/starwind/chart";
const chartData = [ { month: "يناير", desktop: 186, mobile: 80 }, { month: "فبراير", desktop: 305, mobile: 200 }, { month: "مارس", desktop: 237, mobile: 120 }, { month: "أبريل", desktop: 73, mobile: 190 }, { month: "مايو", desktop: 209, mobile: 130 }, { month: "يونيو", desktop: 214, mobile: 140 },];
const chartConfig = { desktop: { label: "سطح المكتب", color: "var(--chart-2)" }, mobile: { label: "الجوال", color: "var(--chart-1)" },} satisfies ChartConfig;---
<div class="w-full max-w-xl" dir="rtl"> <ChartContainer config={chartConfig} data={chartData}> <ChartGrid vertical={false} /> <ChartXAxis dataKey="month" /> <ChartBar dataKey="desktop" radius={4} /> <ChartBar dataKey="mobile" radius={4} /> <ChartLegend /> </ChartContainer></div>"use client";
import type { ChartConfig } from "@/components/starwind/chart";import { ChartBar, ChartContainer, ChartGrid, ChartLegend, ChartXAxis,} from "@/components/starwind/chart";
const chartData = [ { month: "يناير", desktop: 186, mobile: 80 }, { month: "فبراير", desktop: 305, mobile: 200 }, { month: "مارس", desktop: 237, mobile: 120 }, { month: "أبريل", desktop: 73, mobile: 190 }, { month: "مايو", desktop: 209, mobile: 130 }, { month: "يونيو", desktop: 214, mobile: 140 },];
const chartConfig = { desktop: { label: "سطح المكتب", color: "var(--chart-2)" }, mobile: { label: "الجوال", color: "var(--chart-1)" },} satisfies ChartConfig;
export function Example() { return ( <div className="w-full max-w-xl" dir="rtl"> <ChartContainer config={chartConfig} data={chartData}> <ChartGrid vertical={false} /> <ChartXAxis dataKey="month" /> <ChartBar dataKey="desktop" radius={4} /> <ChartBar dataKey="mobile" radius={4} /> <ChartLegend /> </ChartContainer> </div> );}<script setup lang="ts">import type { ChartConfig } from "@/components/starwind/chart";import { ChartBar, ChartContainer, ChartGrid, ChartLegend, ChartXAxis,} from "@/components/starwind/chart";
const chartData = [ { month: "يناير", desktop: 186, mobile: 80 }, { month: "فبراير", desktop: 305, mobile: 200 }, { month: "مارس", desktop: 237, mobile: 120 }, { month: "أبريل", desktop: 73, mobile: 190 }, { month: "مايو", desktop: 209, mobile: 130 }, { month: "يونيو", desktop: 214, mobile: 140 },];
const chartConfig = { desktop: { label: "سطح المكتب", color: "var(--chart-2)" }, mobile: { label: "الجوال", color: "var(--chart-1)" },} satisfies ChartConfig;</script>
<template> <div class="w-full max-w-xl" dir="rtl"> <ChartContainer :config="chartConfig" :data="chartData"> <ChartGrid :vertical="false" /> <ChartXAxis data-key="month" /> <ChartBar data-key="desktop" :radius="4" /> <ChartBar data-key="mobile" :radius="4" /> <ChartLegend /> </ChartContainer> </div></template><script lang="ts"> import type { ChartConfig } from "@/components/starwind/chart"; import { ChartBar, ChartContainer, ChartGrid, ChartLegend, ChartXAxis, } from "@/components/starwind/chart";
const chartData = [ { month: "يناير", desktop: 186, mobile: 80 }, { month: "فبراير", desktop: 305, mobile: 200 }, { month: "مارس", desktop: 237, mobile: 120 }, { month: "أبريل", desktop: 73, mobile: 190 }, { month: "مايو", desktop: 209, mobile: 130 }, { month: "يونيو", desktop: 214, mobile: 140 }, ];
const chartConfig = { desktop: { label: "سطح المكتب", color: "var(--chart-2)" }, mobile: { label: "الجوال", color: "var(--chart-1)" }, } satisfies ChartConfig;</script>
<div class="w-full max-w-xl" dir="rtl"> <ChartContainer config={chartConfig} data={chartData}> <ChartGrid vertical={false} /> <ChartXAxis dataKey="month" /> <ChartBar dataKey="desktop" radius={4} /> <ChartBar dataKey="mobile" radius={4} /> <ChartLegend /> </ChartContainer></div>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.
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.
---import { ChartContainer } from "@/components/starwind/chart";import { horizontalBarChart } from "@/charts/horizontal-bar-chart";import { visitorConfig, visitorData } from "@/charts/visitor-charts";---
<ChartContainer chart={horizontalBarChart} config={visitorConfig} data={visitorData} class="max-w-xl"/>
<script> import "@/charts/horizontal-bar-chart";</script>"use client";
import { ChartContainer } from "@/components/starwind/chart";import { horizontalBarChart } from "@/charts/horizontal-bar-chart";import { visitorConfig, visitorData } from "@/charts/visitor-charts";
export function Example() { return ( <ChartContainer chart={horizontalBarChart} config={visitorConfig} data={visitorData} className="max-w-xl" /> );}<script setup lang="ts">import { ChartContainer } from "@/components/starwind/chart";import { horizontalBarChart } from "@/charts/horizontal-bar-chart";import { visitorConfig, visitorData } from "@/charts/visitor-charts";</script>
<template> <ChartContainer :chart="horizontalBarChart" :config="visitorConfig" :data="visitorData" class="max-w-xl" /></template><script lang="ts"> import { ChartContainer } from "@/components/starwind/chart"; import { horizontalBarChart } from "@/charts/horizontal-bar-chart"; import { visitorConfig, visitorData } from "@/charts/visitor-charts";</script>
<ChartContainer chart={horizontalBarChart} config={visitorConfig} data={visitorData} class="max-w-xl"/>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:
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:
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
createChartfrom@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,ChartRadarorChartRadialBarinsideChartContainerwith your data and aChartConfigfor the label and color of each series. AddChartXAxis,ChartYAxis,ChartGrid,ChartPolarGrid,ChartPolarAngleAxisandChartLabelfor axes, grid lines and center text. AddChartLinearGradientfor gradient fills, as in shadcn/ui. A radar chart needsChartPolarAngleAxis. Other axes are optional, as in shadcn/ui: withoutChartXAxis, 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
labelprop draws values on bars, lines, areas and pie slices, in place of a nestedLabelList.ChartBartakes four corner radii for stacked bars,stackOffset="expand"onChartContainerstacks to 100%, andcursor={false}onChartTooltipremoves the hover band. SeveralChartLabelparts give a donut a total and a caption. ChartTooltip,ChartTooltipContent,ChartLegendandChartLegendContentadd the Starwind tooltip and a legend that hides and shows series. The legend lists only the series that the chart draws.tickFormatter,formatterandlabelFormattertake aChartFormatobject 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
chartprop ofChartContainer. starwind add chartalso installs@tanstack/chartsand 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.