Skip to content

Comparisons and trends

Start with the Charts overview for installation. The overview’s bar example and the basic line example here work with @hozo/charts@0.5.1. Area, Composed, Sparkline, and the newer options below describe main.

The grouped bar example compares each series side by side. On main, pass horizontal if long category labels read better down the left. Use stacked when both the total and its parts matter. The value axis is still configured with y, even in the horizontal layout.

Use a line for ordered observations. A missing value breaks the line; it does not plot a zero.

Web preview
DayVisits
Mon40
TueNo value
Wed56
Thu61
DailyVisits.tsx
import { LineChart } from '@hozo/charts'const visits = [  { day: 'Mon', total: 40 },  { day: 'Tue', total: null },  { day: 'Wed', total: 56 },  { day: 'Thu', total: 61 },]export function DailyVisits() {  return (    <LineChart      accessibilityLabel="Visits by day"      data={visits}      x={{ key: 'day', label: 'Day' }}      series={[{ key: 'total', label: 'Visits' }]}      points      height={220}    />  )}

For unequal time intervals on main, sort the rows chronologically and use x={{ key: 'date', type: 'time' }} with timestamps or dates in that field. Without a time scale the categories are evenly spaced.

Use a stacked area when the growing total and the contribution of each series both matter. The table still reports each series’ own value.

Web preview
MonthFreePaid
Jan3612
Feb4818
Mar5424
SignupsByPlan.tsx
import { AreaChart } from '@hozo/charts'const signups = [  { month: 'Jan', free: 36, paid: 12 },  { month: 'Feb', free: 48, paid: 18 },  { month: 'Mar', free: 54, paid: 24 },]export function SignupsByPlan() {  return (    <AreaChart      accessibilityLabel="Monthly sign-ups by plan"      data={signups}      x={{ key: 'month', label: 'Month' }}      series={[        { key: 'free', label: 'Free' },        { key: 'paid', label: 'Paid' },      ]}      stacked      height={240}    />  )}

Use ComposedChart when two series need to be read together, such as actual orders and the target in the same units. Set type: 'line' on the line series. If two series use different units, prefer separate charts unless comparing the two scales in a single plot is essential.

Web preview
CategoryOrdersTarget
Week 16472
Week 27976
Week 38180
DeliveriesAgainstTarget.tsx
import { ComposedChart } from '@hozo/charts'const deliveries = [  { week: 'Week 1', orders: 64, target: 72 },  { week: 'Week 2', orders: 79, target: 76 },  { week: 'Week 3', orders: 81, target: 80 },]export function DeliveriesAgainstTarget() {  return (    <ComposedChart      accessibilityLabel="Weekly orders against target"      data={deliveries}      x={{ key: 'week' }}      series={[        { key: 'orders', label: 'Orders' },        { key: 'target', label: 'Target', type: 'line' },      ]}      height={240}    />  )}

Use a sparkline in a table cell or beside a number when only the shape of the trend matters. Its accessible image description summarizes the values; it does not add a tab stop or a data table.

Web preview
VisitsTrend.tsx
import { Sparkline } from '@hozo/charts'export function VisitsTrend() {  return (    <Sparkline accessibilityLabel="Visits over seven days" values={[41, 38, 46, 52, 73, 64, 69]} />  )}