Theme, sync, and range
These recipes use options on main. Start with the Charts overview
for installation and release compatibility.
Theme a group of charts
Section titled “Theme a group of charts”ChartThemeProvider sets defaults for the charts below it. A chart’s
theme overrides those defaults, and an explicit series color wins
over the palette. Provide enough contrast in both schemes. Turn on
texture to distinguish supported series by more than colour.
import { BarChart, ChartThemeProvider } from '@hozo/charts'export function ThemedOrders() { return ( <ChartThemeProvider theme={{ palette: { light: ['#115e59', '#9a3412'], dark: ['#6ee7b7', '#fdba74'] }, bar: { radius: 3, maxWidth: 32 }, texture: true, }} > <BarChart accessibilityLabel="Orders and returns by month" data={[ { month: 'Jan', orders: 48, returns: 8 }, { month: 'Feb', orders: 61, returns: 6 }, ]} x={{ key: 'month' }} series={[ { key: 'orders', label: 'Orders' }, { key: 'returns', label: 'Returns' }, ]} height={220} /> </ChartThemeProvider> )}Link the active category
Section titled “Link the active category”ChartSync matches the active category by its label, not its row index.
One chart can omit a month without shifting the others. Only the chart
the reader is exploring announces the value. Use category and
onCategoryChange if the app needs to control or display the selection.
import { BarChart, ChartSync, LineChart } from '@hozo/charts'const orders = [ { month: 'Jan', count: 72 }, { month: 'Feb', count: 80 }, { month: 'Mar', count: 65 },]const wait = [ { month: 'Jan', minutes: 36 }, { month: 'Mar', minutes: 27 },]export function LinkedCharts() { return ( <ChartSync> <BarChart accessibilityLabel="Orders by month" data={orders} x={{ key: 'month' }} series={[{ key: 'count', label: 'Orders' }]} height={190} /> <LineChart accessibilityLabel="Wait time by month" data={wait} x={{ key: 'month' }} y={{ format: (value) => `${value} min` }} series={[{ key: 'minutes', label: 'Wait' }]} height={190} /> </ChartSync> )}Select a visible range
Section titled “Select a visible range”Bar, Line, Area, and Composed accept a brush for selecting a consecutive
window of rows. The start and end are zero-based and inclusive. Use
brush={true} for an uncontrolled brush initially showing all rows, or
range and onRangeChange to keep it in app state:
import { type BrushRange, LineChart } from '@hozo/charts'import { useState } from 'react'const visits = [ { day: 'Mon', count: 42 }, { day: 'Tue', count: 63 }, { day: 'Wed', count: 49 }, { day: 'Thu', count: 69 }, { day: 'Fri', count: 79 },]export function VisitWindow() { const [range, setRange] = useState<BrushRange>({ start: 1, end: 3 }) return ( <LineChart accessibilityLabel="Visits in the selected day range" data={visits} x={{ key: 'day' }} series={[{ key: 'count', label: 'Visits' }]} brush={{ range, onRangeChange: setRange }} height={220} /> )}This starts with Tuesday through Thursday. The brush exposes two sliders
on Web and two adjustable controls on Native. The chart’s summary and
table describe the displayed window. ChartSync shares the active
category, not this window.