# CartesianChart Compare numeric series on a shared category axis with bars, lines, or areas. Inspect values by pointer, touch, or keyboard, and enable the data table when readers need the full set. [Interactive guide](/docs/components/cartesianchart) · 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 CartesianChart for bar, line or area series on a shared category axis and unit family. ### How to compose it Supply a row per category with stable series keys and use null for missing measurements. Provide a title, a meaningful summary and an axis formatter for the units. ### What to verify Use arrow keys and Home or End to inspect categories. Verify grouped, stacked or percent presentation fits the comparison and exposes exact values when needed. ## Usage ```tsx import { CartesianChart } from 'wss3-forge' import type { ChartDatum, ChartSeries } from 'wss3-forge' ``` - Provide one row per category and use the same unique series keys in the row values and series metadata. For a missing date, include its row with null values so the gap stays visible. - Use a number for a measured value, including zero or negatives. Omit a series key or pass null for a missing measurement. - Give the chart a title and summarize the trend or exception that matters. Pass showTable to let readers open the full set of values. - Tab to the plot, then use the arrow keys or Home and End to move between categories. Hover or tap a category to inspect its values. - Use one unit family on the shared y-axis, and set a matching axis formatter when the series use a custom number format. Chart colors follow ForgeProvider in light and dark mode. - Set barLayout to stacked for diverging totals or percent for normalized shares. The percent mode normalizes positive and negative values separately. ```tsx ``` ## Runnable examples ### Sales with negative and missing values ```tsx import { CartesianChart } from 'wss3-forge' import type { ChartDatum, ChartSeries, ChartThreshold } from 'wss3-forge' const formatUsd = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD', maximumFractionDigits: 0 }).format const sales: ChartDatum[] = [ { label: 'May 12', values: { sales: 420, forecast: 350 } }, { label: 'May 13', values: { sales: -160, forecast: 350 } }, { label: 'May 14', values: { sales: null, forecast: null } }, { label: 'May 15', values: { sales: 0, forecast: 350 } }, { label: 'May 16', values: { sales: 560, forecast: 350 } } ] const salesSeries: ChartSeries[] = [ { key: 'sales', label: 'Net sales', kind: 'bar', formatValue: formatUsd }, { key: 'forecast', label: 'Forecast', kind: 'line', formatValue: formatUsd } ] const thresholds: ChartThreshold[] = [ { value: 500, label: 'Stretch goal', color: 'var(--color-success)' } ] export default function Example() { return () } ``` ### Traffic dashboard with three series ```tsx import { CartesianChart } from 'wss3-forge' import type { ChartDatum, ChartSeries } from 'wss3-forge' const traffic: ChartDatum[] = [ { label: 'Jan', values: { visitors: 2400, sessions: 1800, newUsers: 800 } }, { label: 'Feb', values: { visitors: 2800, sessions: 2100, newUsers: 950 } }, { label: 'Mar', values: { visitors: 3200, sessions: 2400 } }, { label: 'Apr', values: { visitors: 2900, sessions: 2200, newUsers: 1000 } }, { label: 'May', values: { visitors: 3800, sessions: 2900, newUsers: 1400 } } ] const trafficSeries: ChartSeries[] = [ { key: 'visitors', label: 'Unique visitors', kind: 'area', unit: 'visitors' }, { key: 'sessions', label: 'Sessions', kind: 'line', unit: 'sessions' }, { key: 'newUsers', label: 'New users', kind: 'line', unit: 'users' } ] export default function Example() { return () } ``` ### Empty reporting period ```tsx import { CartesianChart } from 'wss3-forge' export default function Example() { return () } ``` ## Root package API ### CartesianChart Compare numeric series on a shared category axis with bars, lines, or areas. Inspect values by pointer, touch, or keyboard, and enable the data table when readers need the full set. Props type: `CartesianChartProps` - `data` — `readonly ChartDatum[]` Ordered categories with values keyed by series. - `series` — `readonly ChartSeries[]` Series keys, labels, marks, colors, units and value formatters. - `title` — `string` Accessible chart name. - `summary?` — `string` Text describing the trend or exception. - `headerAction?` — `ReactNode` Place a control beside the caption; it wraps beneath the caption on narrow surfaces. - `domain?` — `ChartDomain` Optional ascending pair of finite y-axis bounds. - `barLayout?` — `ChartBarLayout` Default `'grouped'`. Options `"grouped"`, `"stacked"`, `"percent"`. Place bars side by side, stack values by sign, or normalize each side to 100%. - `interpolation?` — `'linear' | 'step'` Default `'linear'`. Options `"linear"`, `"step"`. Connect line and area points directly or step halfway between categories. - `areaFill?` — `'solid' | 'gradient'` Default `'solid'`. Options `"solid"`, `"gradient"`. Fill area marks with a constant tint or a vertical fade. - `thresholds?` — `readonly ChartThreshold[]` Default `[]`. Named reference values drawn across the plot. - `xAxis?` — `ChartCategoryAxisOptions` Category axis label, label visibility and category formatter. - `yAxis?` — `ChartValueAxisOptions` Value axis label, labels, grid, tick count and number formatter. - `width?` — `number | string` Default `'100%'`. Figure width, constrained by its container. - `height?` — `number` Default `240`. Height of the plot in pixels, excluding the caption, legend and table. - `showLegend?` — `boolean` Default `true`. Show the series and reference values below the caption. - `showTooltip?` — `boolean` Default `true`. Enable category inspection by pointer, keyboard and touch. The data table is controlled separately. - `showTable?` — `boolean` Default `false`. Offer a disclosure with the source values. - `emptyLabel?` — `string` Default `'No data to display.'`. Message displayed when the series have no finite values. - `categoryLabel?` — `string` Default `xAxis?.label ?? 'Category'`. Heading for the first column of the data table. - `className?` — `string` - `style?` — `CSSProperties` ## Related types ```ts export interface ChartDatum { label: string values: Readonly> } export interface ChartSeries { key: string label?: string kind?: 'bar' | 'line' | 'area' color?: string unit?: string formatValue?: (value: number) => string } export type ChartDomain = readonly [min: number, max: number] export type ChartBarLayout = 'grouped' | 'stacked' | 'percent' export interface ChartThreshold { value: number label: string color?: string } export interface ChartCategoryAxisOptions { label?: string showLabels?: boolean formatLabel?: (label: string) => string } export interface ChartValueAxisOptions { label?: string showLabels?: boolean showGrid?: boolean tickCount?: number formatValue?: (value: number) => string } export interface CartesianChartProps { data: readonly ChartDatum[] series: readonly ChartSeries[] title: string summary?: string /** Place a control beside the caption; it wraps beneath the caption on narrow surfaces. */ headerAction?: ReactNode domain?: ChartDomain /** Place bars side by side, stack values by sign, or normalize each side to 100%. */ barLayout?: ChartBarLayout /** Connect line and area points directly or step halfway between categories. @default 'linear' */ interpolation?: 'linear' | 'step' /** Fill area marks with a constant tint or a vertical fade. @default 'solid' */ areaFill?: 'solid' | 'gradient' thresholds?: readonly ChartThreshold[] xAxis?: ChartCategoryAxisOptions yAxis?: ChartValueAxisOptions width?: number | string height?: number showLegend?: boolean showTooltip?: boolean /** Offer a disclosure with the source values. @default false */ showTable?: boolean emptyLabel?: string categoryLabel?: string className?: string style?: CSSProperties } ```