Chart

Chart is a high-level wrapper around the individual chart primitives — pick a type and pass data, the wrapper handles series detection, palette assignment, KPI display, an optional info tooltip, and the surrounding card layout.

  • Bar/line series are derived from the keys of the first data point (everything except x); each key auto-maps to a color from the built-in palette.
  • Pie data uses { label, value, color? } items — color falls back to the pie palette when omitted.
  • Heatmap data uses { rows, columns, matrix } with a plain number[][].
  • Bar-only props (layout, orientation) are typed off type="bar" so other types don't expose them.
  • KPIs render in a strip alongside the chart for at-a-glance summary metrics.

For full control over series colors, click handlers, gradients, or grouped-stacked layout, use the individual chart components: BarChart, LineChart, PieChart, HeatmapChart.

Import

import { Chart } from "h2o-library/charts";

Usage

Bar

The simplest case — pass type="bar" and a flat array. Series are derived from the keys of the first data point.

Website Traffic

Monthly page views and unique visitors

<Chart
  type="bar"
  title="Website Traffic"
  description="Monthly page views and unique visitors"
  data={[
    { x: "Jan", "Page Views": 4000, "Unique Visitors": 2400 },
    { x: "Feb", "Page Views": 3000, "Unique Visitors": 1398 },
  ]}
  kpis={[
    { label: "Total Page Views", value: "1.2M" },
    { label: "Unique Visitors", value: "800K" },
  ]}
/>;

Grouped Bar

Multiple series shown side-by-side per category.

Appointments by Month

Appointment status distribution

<Chart type="bar" layout="grouped" title="Appointments by Month" data={data} />;

Stacked Bar

Multiple series stacked into a single bar per category — best for part-to-whole comparison.

Cases by Specialty

Monthly case volume by medical specialty

<Chart type="bar" layout="stacked" title="Cases by Specialty" data={data} />;

Horizontal Bar

orientation="horizontal" flips the axes — use it when category labels are long.

Cases by Specialty (Horizontal)

Monthly case volume by medical specialty

<Chart
  type="bar"
  layout="stacked"
  orientation="horizontal"
  title="Cases"
  data={data}
/>;

Line

For time-series and trend data. Same { x, ...keys } shape as bar.

Customer Growth

New vs. returning customers over time

<Chart
  type="line"
  title="Customer Growth"
  data={[
    { x: "Jan", "New Customers": 30, "Returning Customers": 10 },
    { x: "Feb", "New Customers": 45, "Returning Customers": 20 },
  ]}
/>;

Pie

Pie data uses { label, value }. Colors are optional — omit to use the built-in pie palette.

Traffic Sources

Breakdown of website traffic by source

Organic Search
Direct
Referral
Social
<Chart
  type="pie"
  title="Traffic Sources"
  data={[
    { label: "Organic", value: 55 },
    { label: "Direct", value: 25 },
  ]}
  kpis={[{ label: "Total Sessions", value: "5.4K" }]}
/>;

Heatmap

Heatmap data uses { rows, columns, matrix }. Cell intensity is normalized to the matrix maximum.

User Engagement

Weekly user activity on different features

Mon
Tue
Wed
Thu
Fri
Feature A
10
25%
25
63%
15
38%
30
75%
20
50%
Feature B
5
13%
40
100%
12
30%
22
55%
18
45%
Feature C
35
88%
8
20%
28
70%
13
33%
24
60%
Feature D
18
45%
33
83%
9
23%
21
53%
27
68%
<Chart
  type="heatmap"
  title="User Engagement"
  data={{
    rows: ["Feature A", "Feature B"],
    columns: ["Mon", "Tue", "Wed"],
    matrix: [
      [10, 25, 15],
      [5, 40, 12],
    ],
  }}
/>;

Info Tooltip

The info prop renders an info icon next to the title with a tooltip on hover. It is independent of title — you can use one without the other.

<Chart
  type="line"
  title="User Activity"
  info="Weekly active and new user statistics"
  data={data}
/>;

KPI Strip

kpis renders a row of summary metrics next to the chart — useful for paired headline numbers.

<Chart
  type="bar"
  title="Financial Overview"
  data={data}
  kpis={[
    { label: "Avg Revenue", value: "$4.8K" },
    { label: "Avg Expenses", value: "$2.9K" },
  ]}
/>;

Playground

Loading playground…

Keyboard

The card Chart primitive does not forward pointer/keyboard drill-in props. For keyboard-accessible series or axis regions, use BarChart, LineChart, or HeatmapChart with the documented on*Click callbacks.

Props

Chart

PropTypeDefaultDescription
type*"bar" | "line" | "pie" | "heatmap"Which underlying chart to render.
data*BarChartDataPoint[] | LineChartDataPoint[] | PieChartDataPoint[] | HeatmapDataChart data. Bar/line: { x, ...keys }[]. Pie: { label, value, color? }[]. Heatmap: { rows, columns, matrix }.
titlestringundefinedTitle displayed above the chart.
descriptionstringundefinedSubtitle shown below the title.
infostringundefinedTooltip text shown on an info icon next to the title. Independent of title.
kpisChartKPI[]undefinedHeadline metrics rendered alongside the chart.
heightnumber400Height of the chart area in pixels.
classNamestringundefinedAdditional CSS class for the outer card.
layout"single" | "grouped" | "stacked" | "grouped-stacked""single"Bar only — controls how series are arranged.
orientation"vertical" | "horizontal""vertical"Bar only — flips the axes.

* Required

ChartKPI

PropTypeDefaultDescription
label*stringMetric label.
value*string | numberMetric value.

* Required

Design Guidelines

  • Reach for Chart for fast integration when you don't need custom colors, click handlers, or grouped-stacked layout.
  • Drop down to the individual primitives when you need per-series color overrides, click events, gradient toggles, or grouped-stacked bar layout.
  • Use bar for comparing discrete categories; grouped / stacked for sub-category breakdown.
  • Use line for trends over time — connected points emphasize change.
  • Use pie only for proportional composition with ≤ 5 categories — bar charts are more readable when comparing close values.
  • Use heatmap for density patterns across two categorical dimensions (e.g. weekday × hour).
  • Pair info with metrics whose definition isn't obvious from the title.

Accessibility

  • Tooltips appear on hover and are not keyboard-accessible by default.
  • KPIs render as plain text and are fully accessible to screen readers.
  • For critical or audited data, provide a companion data table.