# Chart Choose a chart by the shape of your data. Use a native Forge chart or compose series, axes and tooltips with the Recharts adapter. [Interactive guide](/docs/components/chart) · Forge 3.2.0 Use the API for your installed version. Run `npx --no-install wss3-forge api --json` inside the project. ## Implementation guidance ### When to use it Use a native Forge chart for its standard data model or the Recharts adapter when the plot needs custom marks, axes or tooltips. ### How to compose it For Recharts, give ChartContainer a height or aspect ratio. Match dataKey, config and data. Enable accessibilityLayer and give the plot an accessible name. ### What to verify Inspect the plot at a narrow width, with keyboard focus and across both themes. Verify the label and summary communicate the trend independently of color. ## Usage ```tsx import { Bar, BarChart } from 'recharts' import { ChartContainer } from 'wss3-forge/recharts' ``` - Give the container a height or aspect ratio. Match each dataKey to a field in the data and an entry in the chart config. - Give the plot an accessible name and enable accessibilityLayer. Focus the plot and use the arrow keys to inspect points. - Import native charts such as CartesianChart from wss3-forge. Its rows have a category label and a values object keyed by series. Set showTable when readers need access to the underlying values. - Use the shared Recharts adapter in Base UI, Radix and React Aria applications. Install Recharts 3.8 or later in the 3.x series. ```tsx const orders = [ { day: 'Monday', count: 12 }, { day: 'Tuesday', count: 19 }, ] const config = { count: { label: 'Orders', color: 'var(--chart-primary)' } } export function OrdersChart() { return } ``` ## Guide ### Chart families Browse live variants and copy the source for a chart. ### Native chart props Open the API for a specific chart to see its data shape, supported options and defaults. ### Recharts adapter Use the same wss3-forge/recharts entry with Base UI, Radix and React Aria. ChartTooltipContent and ChartLegendContent read the labels and colors from ChartContainer. ```tsx import { BarChart, Bar, XAxis } from 'recharts' import { ChartContainer, ChartTooltip, ChartTooltipContent, ChartLegend, ChartLegendContent } from 'wss3-forge/recharts' const config = { orders: { label: 'Orders', color: 'var(--chart-primary)' } } export default function OrdersByDay() { return } /> } /> } ``` ### Series colors Set a color on each config entry, or supply light and dark colors in theme. ChartContainer exposes each series color as a local CSS variable for the bars, legend and tooltip. ```tsx const config = { visits: { label: 'Visits', color: 'var(--chart-primary)' }, orders: { label: 'Orders', theme: { light: '#377966', dark: '#79b5a0' } }, } ``` ### Tooltip and legend ChartTooltipContent supports dot, line and dashed indicators. Hide the label or indicator with hideLabel and hideIndicator. Use nameKey or labelKey to select config entries and formatter or labelFormatter to format values and dates. Set itemSorter, filterNull, includeHidden, payloadUniqBy or separator to control tooltip rows. Legend callbacks receive the entry, index and event. Use containerProps for listeners on the legend container. ### Custom tooltip content Return React text from formatter to display reader-supplied values. For a trusted HTML template that replaces all rows, pass dangerouslySetInnerHTML to ChartTooltipContent and omit children. ### Reading direction Set dir="rtl" on the chart container for right-to-left labels. Set reversed on the category axis when the first day should appear on the right. ## Runnable examples ### Interactive bar chart ```tsx import { useState } from 'react' import { Bar, BarChart, CartesianGrid, XAxis } from 'recharts' import { Button, ButtonGroup, Card, CardContent, CardDescription, CardHeader, CardTitle, Heading, Text, VStack } from 'wss3-forge' import { ChartContainer, ChartTooltip, ChartTooltipContent, type ChartConfig } from 'wss3-forge/recharts' const trafficConfig = { desktop: { label: 'Desktop', theme: { light: '#386aa0', dark: '#81adcf' } }, mobile: { label: 'Mobile', theme: { light: '#377966', dark: '#79b5a0' } } } satisfies ChartConfig const dailyVisits = [ [195, 284], [336, 252], [411, 256], [266, 186], [218, 246], [134, 297], [172, 304], [265, 354], [286, 81], [346, 271], [240, 292], [187, 55], [142, 266], [237, 175], [322, 134], [225, 214], [299, 160], [299, 145], [346, 133], [211, 200], [343, 95], [103, 70], [390, 352], [443, 100], [363, 254], [260, 233], [275, 262], [345, 317], [425, 230], [313, 198], [290, 147], [220, 235], [151, 180], [313, 105], [248, 189], [165, 323], [101, 315], [441, 100], [76, 311], [337, 223], [376, 259], [207, 298], [155, 339], [174, 289], [190, 287], [264, 271], [408, 251], [173, 186], [442, 284], [264, 135], [218, 274], [111, 229], [380, 216], [79, 96], [425, 102], [103, 197], [270, 144], [203, 342], [287, 310], [363, 193], [347, 262], [405, 268], [420, 197], [327, 58], [176, 145], [380, 194], [313, 132], [82, 64], [349, 297], [202, 86], [136, 279], [124, 133], [289, 174], [259, 112], [170, 272], [354, 342], [89, 322], [257, 153], [208, 236], [326, 101], [269, 116], [340, 165], [122, 110], [276, 303], [141, 76], [316, 301], [408, 153], [187, 206], [249, 342], [184, 172] ].map(([desktop, mobile], index) => ({ date: Date.UTC(2025, 0, index + 1), desktop, mobile })) const visitTotals = { desktop: dailyVisits.reduce((sum, day) => sum + day.desktop, 0), mobile: dailyVisits.reduce((sum, day) => sum + day.mobile, 0), } const shortDate = new Intl.DateTimeFormat('en-US', { month: 'short', day: 'numeric', timeZone: 'UTC' }) const fullDate = new Intl.DateTimeFormat('en-US', { month: 'long', day: 'numeric', year: 'numeric', timeZone: 'UTC' }) function TrafficExample() { const [device, setDevice] = useState<'desktop' | 'mobile'>('desktop') return Daily visitorsJanuary–March 2025 {(['desktop', 'mobile'] as const).map(key => )} shortDate.format(date)} /> fullDate.format(Number(date))} />} /> } export default function Example() { return () } ``` ### First chart ```tsx import { Bar, BarChart } from 'recharts' import { ChartContainer, type ChartConfig } from 'wss3-forge/recharts' const trafficConfig = { desktop: { label: 'Desktop', theme: { light: '#386aa0', dark: '#81adcf' } }, mobile: { label: 'Mobile', theme: { light: '#377966', dark: '#79b5a0' } } } satisfies ChartConfig const weeklyVisits = [ { day: 1, desktop: 148, mobile: 70 }, { day: 2, desktop: 192, mobile: 105 }, { day: 3, desktop: 125, mobile: 86 }, { day: 4, desktop: 211, mobile: 132 }, { day: 5, desktop: 243, mobile: 165 }, { day: 6, desktop: 173, mobile: 103 }, { day: 7, desktop: 126, mobile: 84 }, ] export default function Example() { return ( ) } ``` ### Add a grid ```tsx import { Bar, BarChart, CartesianGrid } from 'recharts' import { ChartContainer, type ChartConfig } from 'wss3-forge/recharts' const trafficConfig = { desktop: { label: 'Desktop', theme: { light: '#386aa0', dark: '#81adcf' } }, mobile: { label: 'Mobile', theme: { light: '#377966', dark: '#79b5a0' } } } satisfies ChartConfig const weeklyVisits = [ { day: 1, desktop: 148, mobile: 70 }, { day: 2, desktop: 192, mobile: 105 }, { day: 3, desktop: 125, mobile: 86 }, { day: 4, desktop: 211, mobile: 132 }, { day: 5, desktop: 243, mobile: 165 }, { day: 6, desktop: 173, mobile: 103 }, { day: 7, desktop: 126, mobile: 84 }, ] export default function Example() { return ( ) } ``` ### Add an axis ```tsx import { Bar, BarChart, CartesianGrid, XAxis } from 'recharts' import { ChartContainer, type ChartConfig } from 'wss3-forge/recharts' const trafficConfig = { desktop: { label: 'Desktop', theme: { light: '#386aa0', dark: '#81adcf' } }, mobile: { label: 'Mobile', theme: { light: '#377966', dark: '#79b5a0' } } } satisfies ChartConfig const weeklyVisits = [ { day: 1, desktop: 148, mobile: 70 }, { day: 2, desktop: 192, mobile: 105 }, { day: 3, desktop: 125, mobile: 86 }, { day: 4, desktop: 211, mobile: 132 }, { day: 5, desktop: 243, mobile: 165 }, { day: 6, desktop: 173, mobile: 103 }, { day: 7, desktop: 126, mobile: 84 }, ] export default function Example() { return ( 'Feb ' + day} /> ) } ``` ### Add a tooltip ```tsx import { Bar, BarChart, CartesianGrid, XAxis } from 'recharts' import { ChartContainer, ChartTooltip, ChartTooltipContent, type ChartConfig } from 'wss3-forge/recharts' const trafficConfig = { desktop: { label: 'Desktop', theme: { light: '#386aa0', dark: '#81adcf' } }, mobile: { label: 'Mobile', theme: { light: '#377966', dark: '#79b5a0' } } } satisfies ChartConfig const weeklyVisits = [ { day: 1, desktop: 148, mobile: 70 }, { day: 2, desktop: 192, mobile: 105 }, { day: 3, desktop: 125, mobile: 86 }, { day: 4, desktop: 211, mobile: 132 }, { day: 5, desktop: 243, mobile: 165 }, { day: 6, desktop: 173, mobile: 103 }, { day: 7, desktop: 126, mobile: 84 }, ] export default function Example() { return ( 'Feb ' + day} /> } /> ) } ``` ### Add a legend ```tsx import { Bar, BarChart, CartesianGrid, XAxis } from 'recharts' import { ChartContainer, ChartLegend, ChartLegendContent, ChartTooltip, ChartTooltipContent, type ChartConfig } from 'wss3-forge/recharts' const trafficConfig = { desktop: { label: 'Desktop', theme: { light: '#386aa0', dark: '#81adcf' } }, mobile: { label: 'Mobile', theme: { light: '#377966', dark: '#79b5a0' } } } satisfies ChartConfig const weeklyVisits = [ { day: 1, desktop: 148, mobile: 70 }, { day: 2, desktop: 192, mobile: 105 }, { day: 3, desktop: 125, mobile: 86 }, { day: 4, desktop: 211, mobile: 132 }, { day: 5, desktop: 243, mobile: 165 }, { day: 6, desktop: 173, mobile: 103 }, { day: 7, desktop: 126, mobile: 84 }, ] export default function Example() { return ( 'Feb ' + day} /> } /> } /> ) } ``` ### Tooltip anatomy ```tsx import { useState } from 'react' import { Bar, BarChart, XAxis } from 'recharts' import { Text, ToggleGroup, VStack } from 'wss3-forge' import { ChartContainer, ChartTooltip, ChartTooltipContent, type ChartConfig } from 'wss3-forge/recharts' const trafficConfig = { desktop: { label: 'Desktop', theme: { light: '#386aa0', dark: '#81adcf' } }, mobile: { label: 'Mobile', theme: { light: '#377966', dark: '#79b5a0' } } } satisfies ChartConfig const weeklyVisits = [ { day: 1, desktop: 148, mobile: 70 }, { day: 2, desktop: 192, mobile: 105 }, { day: 3, desktop: 125, mobile: 86 }, { day: 4, desktop: 211, mobile: 132 }, { day: 5, desktop: 243, mobile: 165 }, { day: 6, desktop: 173, mobile: 103 }, { day: 7, desktop: 126, mobile: 84 }, ] function TooltipAnatomy() { const [indicator, setIndicator] = useState<'dot' | 'line' | 'dashed'>('dot') return ({ id, label: id }))} onValueChange={([next]: string[]) => { if (next === 'dot' || next === 'line' || next === 'dashed') setIndicator(next) }} /> The label identifies the day. Each indicator matches a series and its value. 'February ' + day} />} /> } export default function Example() { return () } ``` ### Grid, axis, tooltip and legend ```tsx import { Bar, BarChart, CartesianGrid, XAxis } from 'recharts' import { ChartContainer, ChartLegend, ChartLegendContent, ChartTooltip, ChartTooltipContent, type ChartConfig } from 'wss3-forge/recharts' const trafficConfig = { desktop: { label: 'Desktop', theme: { light: '#386aa0', dark: '#81adcf' } }, mobile: { label: 'Mobile', theme: { light: '#377966', dark: '#79b5a0' } } } satisfies ChartConfig const weeklyVisits = [ { day: 1, desktop: 148, mobile: 70 }, { day: 2, desktop: 192, mobile: 105 }, { day: 3, desktop: 125, mobile: 86 }, { day: 4, desktop: 211, mobile: 132 }, { day: 5, desktop: 243, mobile: 165 }, { day: 6, desktop: 173, mobile: 103 }, { day: 7, desktop: 126, mobile: 84 }, ] function ComparisonChart({ rtl = false }: { rtl?: boolean }) { return 'Feb ' + day} /> } /> } /> } export default function Example() { return () } ``` ### Right to left ```tsx import { Bar, BarChart, CartesianGrid, XAxis } from 'recharts' import { ChartContainer, ChartLegend, ChartLegendContent, ChartTooltip, ChartTooltipContent, type ChartConfig } from 'wss3-forge/recharts' const trafficConfig = { desktop: { label: 'Desktop', theme: { light: '#386aa0', dark: '#81adcf' } }, mobile: { label: 'Mobile', theme: { light: '#377966', dark: '#79b5a0' } } } satisfies ChartConfig const weeklyVisits = [ { day: 1, desktop: 148, mobile: 70 }, { day: 2, desktop: 192, mobile: 105 }, { day: 3, desktop: 125, mobile: 86 }, { day: 4, desktop: 211, mobile: 132 }, { day: 5, desktop: 243, mobile: 165 }, { day: 6, desktop: 173, mobile: 103 }, { day: 7, desktop: 126, mobile: 84 }, ] function ComparisonChart({ rtl = false }: { rtl?: boolean }) { return 'Feb ' + day} /> } /> } /> } export default function Example() { return () } ``` ### Native Forge chart with a data table ```tsx import { CartesianChart } from 'wss3-forge' export default function Example() { return () } ``` ## Primitive libraries ### Recharts ChartTooltip and ChartLegend expose Recharts components. Configure their content with the corresponding Forge content component, or supply your own. This chart uses Recharts in Base UI, Radix and React Aria applications. ```sh npm install wss3-forge recharts ``` [Recharts API reference](https://recharts.github.io/en-US/api/) ```tsx import { ChartContainer, ChartTooltip, ChartTooltipContent, ChartLegend, ChartLegendContent, ChartStyle } from 'wss3-forge/recharts' ``` ## Optional primitive contracts - [wss3-forge/recharts · Chart contract](/ai/skill/primitive-api/Chart.json)