Skip to content

Charts (@hozo/charts)

Use @hozo/charts when you have data rather than drawing instructions. It handles scales, axes, interaction, and what assistive technology reads. For custom vector artwork use SVG; for a custom drawing scene use 2D Canvas. Charts use SVG on both platforms and do not require Skia.

@hozo/charts@0.5.1 exports BarChart and LineChart. The bar example below and the basic line example work with that release. The wider chart selection and the newer large-data behavior documented here are from main; check your installed version before using those APIs.

The previews run in your browser. On the plot, use a pointer or touch to explore the data. With a keyboard, Tab to the plot and use the arrow keys. The code beneath each preview is the source used to render it.

sh
pnpm add @hozo/charts# In the React Native app only (Expo):npx expo install react-native-svg

The Native app must declare react-native-svg itself (15.9.0 or later), so the app’s build can link it. Web needs no native dependency.

Web preview
MonthOnlineIn store
Jan$120$80
Feb$200No value
Mar$90$60
MonthlyRevenue.tsx
import { BarChart } from '@hozo/charts'const revenue = [  { month: 'Jan', online: 120, store: 80 },  { month: 'Feb', online: 200, store: null },  { month: 'Mar', online: 90, store: 60 },]const series = [  { key: 'online', label: 'Online' },  { key: 'store', label: 'In store' },]export function MonthlyRevenue() {  return (    <BarChart      accessibilityLabel="Monthly revenue by channel"      data={revenue}      x={{ key: 'month', label: 'Month' }}      y={{ label: 'Revenue', format: (value) => `$${value}` }}      series={series}      height={240}      showTable    />  )}

The x.key names the category in each row; each series names a value field. height is required, and the chart measures its container unless you supply width. A missing or null value is a gap, not zero. In this example, February has no store bar and the table says “No value”.

  • Compare categories: use BarChart. Use horizontal for long labels, or stacked when the sum and its parts both matter.
  • See a trend: use LineChart or AreaChart. Use x.type: 'time' and chronological rows to show real time intervals. ComposedChart overlays lines and bars when they need to be read together.
  • Find a relationship or a dense spot: use ScatterChart for two numeric axes, or HeatmapChart for values indexed by row and column.
  • Show parts, stages, or flows: use PieChart or DonutChart for shares, TreemapChart for nested parts, FunnelChart for stages, and SankeyChart for flows. RadarChart and RadialBarChart offer radial layouts.
  • Summarize in a small space: use Sparkline. It exposes one image description, without a keyboard stop or table.

Give the plot a specific accessibilityLabel. On Web, Tab reaches the plot as a single stop; use the arrow keys to explore its values. On Native, the plot exposes adjustable actions to VoiceOver and TalkBack. A pointer or touch can also pick a value. The summary and data table describe the data without requiring the reader to interpret the SVG marks.

Use showTable when readers should see the values as well as the plot. Without it, tables are visually hidden. On main, Native mounts the hidden table when a screen reader is detected. The default limit on main is TABLE_ROW_LIMIT (1,000 categories, or cells for a heatmap); above it the chart keeps the summary and value exploration, but omits the table unless you request it explicitly. For a large dataset, offer a filtered view or separate data download rather than forcing a very large table onto the screen.

See the package reference for full props, theming, synchronized charts, and range selection, and the scale measurements for tested device configurations and results.