Skip to content

Theme, sync, and range

These recipes use options on main. Start with the Charts overview for installation and release compatibility.

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.

Web preview
CategoryOrdersReturns
Jan488
Feb616
ThemedOrders.tsx
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>  )}

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.

Web preview
CategoryOrders
Jan72
Feb80
Mar65
CategoryWait
Jan36 min
Mar27 min
LinkedCharts.tsx
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>  )}

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:

Web preview
CategoryVisits
Tue63
Wed49
Thu69
VisitWindow.tsx
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.