Charts
Pulze's charts are built on Recharts (MIT), wrapped
so they all share the same colours, tooltip, axes, spacing and motion rules.
Import them from @pulze/blocks.
| Chart | Use it for |
|---|---|
AreaChart |
A trend over time; compare with the previous period |
BarChart |
Comparing periods or categories; grouped, stacked or one bar highlighted |
DonutChart + DonutLegend |
Parts of a whole (traffic sources, storage) |
RingProgress |
One percentage (target reached) |
FunnelChart |
Stages that narrow (sales pipeline, sign-up steps) |
Sparkline |
A tiny trend inside a KPI card or table cell |
Colours
Series use the theme tokens --chart-1 … --chart-4 in order. --chart-1
follows the accent colour, so charts match your brand automatically. Pass
color on a series to override it, using any CSS colour or token:
color: "var(--success)".
Motion
Charts draw in once (lines grow left to right, bars grow up, about 700 ms). They don't animate:
- when the person has turned Animations off;
- when their device asks for reduced motion;
- on server-rendered first paint.
To turn chart motion off everywhere, edit useChartMotion() in
charts/use-chart-motion.ts.
AreaChart
<AreaChart
data={days} // [{ date, current, previous }, …]
x="date"
series={[
{ key: "current", label: "This period" },
{ key: "previous", label: "Last period", dashed: true },
]}
formatX={(v) => formatDate(String(v), "short")}
formatY={(v) => formatCompact(v)}
formatValue={(v) => `${formatNumber(v)} visitors`}
height={300}
/>
| Prop | Type | Default | Notes |
|---|---|---|---|
data |
object[] | One object per point | |
x |
field name | x-axis field | |
series |
{ key, label, color?, dashed? }[] |
dashed = comparison line, no fill |
|
height |
number | 300 | Width always fills the card |
formatX / formatY |
function | Axis labels | |
formatValue |
function | formatY |
Tooltip values |
showGrid / showXAxis / showYAxis |
boolean | true | Hide parts for mini charts |
A header with a legend and range switch, as on the Analytics dashboard:
<Card>
<CardHeader
title="Traffic overview"
description="Unique visitors, this period vs last"
action={
<>
<ChartLegend items={[{ label: "This period", color: "var(--chart-1)" },
{ label: "Last period", color: "var(--muted-foreground)", dashed: true }]} />
<Segmented label="Range" value={range} onChange={setRange}
options={[{ value: 7, label: "7D" }, { value: 30, label: "30D" }, { value: 90, label: "90D" }]} />
</>
}
/>
<AreaChart … />
</Card>
BarChart
<BarChart data={months} x="month"
series={[{ key: "store", label: "Store" }, { key: "marketplace", label: "Marketplace" }]}
formatY={(v) => formatMoney(v, { compact: true })} />
<BarChart … stacked /> // stack series
<BarChart … highlight={3} /> // grey out every bar except index 3
| Extra prop | Notes |
|---|---|
stacked |
Stack the series instead of side by side |
highlight |
Index of the one bar to keep coloured (single series) |
barSize |
Maximum bar width in px (default 28) |
DonutChart and DonutLegend
<DonutChart data={[{ label: "Direct", value: 18322 }, …]}
center={{ value: "48.2k", label: "visitors" }} size={168} thickness={22}
formatValue={(v) => formatNumber(v)} />
<DonutLegend data={…same data…} formatValue={(v) => formatNumber(v)} />
The legend shows each slice's value and share of the total.
RingProgress
<RingProgress value={0.84} label="84%" sublabel="of target" size={160} />
FunnelChart
<FunnelChart
steps={[
{ label: "Lead", count: 142, value: "$1.2M" },
{ label: "Qualified", count: 88, value: "$780k" },
{ label: "Won", count: 12, value: "$148k", color: "var(--success)" },
]}
/>
The "62% from lead" text is worked out for you. Each step should count the
items that reached it or went further. The sample getPipeline() does this.
Sparkline
<Sparkline data={[3, 4, 3.5, 5, 6, 7]} className="h-9 w-28" />
<Sparkline data={…} color="var(--chart-4)" fill />
A plain SVG with no Recharts cost, so use it freely in tables and cards.
A new chart type
Recharts has many more charts (line, scatter, radar, treemap). To add one in the Pulze style:
- Copy
bar-chart.tsxas a starting point. - Keep
ResponsiveContainer, theChartTooltipcontent, the axis tick styles and{...useChartMotion()}. - Export it from
charts/index.ts.