Chart

Small dependency-free SVG charts: BarChart for periods or categories, LineChart for a trend, AreaChart for a total that accumulates. One ink series (--text-1) and a quiet comparison (--n-04) on one value axis, hairline gridlines, mono tick labels. Hover or focus and use the arrow keys for a readout of every series at that point; the title and description name the chart for assistive tech, which also gets the data as a table. A legend appears only when there are two series. Bars grow from the baseline and lines fade in, both by transform and opacity, and not at all with reduced motion.

import { BarChart, LineChart, AreaChart } from "@puckoops/camelot";
This yearLast year
Invoiced by month, this year against last yearInvoiced grew in most months; December is the highest at £36,800.

Invoiced by month, this year against last year
MonthThis yearLast year
Jan£18,400£16,200
Feb£21,200£17,900
Mar£19,800£18,600
Apr£26,400£20,100
May£24,100£22,800
Jun£29,800£21,400
Jul£22,600£19,700
Aug£31,500£24,300
Sep£28,900£25,100
Oct£34,200£27,600
Nov£30,100£26,900
Dec£36,800£29,400
NameDescriptionDefaultControl
data*
ChartDatum[]
-
title*
Not drawn; names the chart
string
-
description
string
-
seriesLabel
string
-
comparisonLabel
string
-
categoryLabel
Heads the first column of the data table, such as Month.
string
-
format
(value: number) => string
--
formatTick
Labels on the value axis; defaults to format.
(value: number) => string
--
height
Axis labels included
number
-
140360240
ticks
Roughly how many gridlines; the scale rounds to clean steps.
number
-
284
legend
Shown by default when there is a comparison series, and never for one series.
boolean
-
className
string
-

When to use

Use BarChart to compare periods or categories, LineChart for a trend over time, AreaChart for a total that accumulates. One ink series; the comparison (last year, the target) is always the quiet one. Always pass title; the legend appears only when there are two series. One value axis only: two measures of different scale are two charts.

  • Use Cards/FigureCard instead when the story is one number; its Sparkbars footer covers a small trend without axes.
  • Use Meter instead for a single share of a whole.
  • Use Table instead when the reader needs exact values more than the shape.

Examples

Bars Single Series

One series needs no legend; the card's heading names it.

Invoiced by month

Invoiced by month
MonthThis year
Jan£18,400
Feb£21,200
Mar£19,800
Apr£26,400
May£24,100
Jun£29,800
Jul£22,600
Aug£31,500
Sep£28,900
Oct£34,200
Nov£30,100
Dec£36,800

Many Bars

Thirty slots: bars thin out and the labels skip so they never collide.

Tasks closed per day in September

Tasks closed per day in September
MonthClosed
014 tasks
026 tasks
038 tasks
0410 tasks
0511 tasks
067 tasks
078 tasks
088 tasks
098 tasks
108 tasks
113 tasks
123 tasks
134 tasks
144 tasks
155 tasks
161 tasks
173 tasks
184 tasks
196 tasks
208 tasks
215 tasks
227 tasks
239 tasks
2410 tasks
2511 tasks
267 tasks
277 tasks
287 tasks
297 tasks
307 tasks

Negative Values

Bars below the baseline grow downward, with the rounded end at the bottom.

Margin over budget by month

Margin over budget by month
MonthMargin
Jan12%
Feb8%
Mar-4%
Apr6%
May14%
Jun-9%
Jul3%
Aug11%
Sep7%

Line

A trend: the ink line over last year's quiet line, with a crosshair that snaps to the month.

This yearLast year
Invoiced by month, this year against last yearInvoiced grew in most months; December is the highest at £36,800.

Invoiced by month, this year against last year
MonthThis yearLast year
Jan£18,400£16,200
Feb£21,200£17,900
Mar£19,800£18,600
Apr£26,400£20,100
May£24,100£22,800
Jun£29,800£21,400
Jul£22,600£19,700
Aug£31,500£24,300
Sep£28,900£25,100
Oct£34,200£27,600
Nov£30,100£26,900
Dec£36,800£29,400

Line Against Target

The comparison can be a flat target.

LoggedTarget
Hours logged this week against the 8-hour day

Hours logged this week against the 8-hour day
MonthLoggedTarget
Mon7.5 hrs8 hrs
Tue8 hrs8 hrs
Wed6.5 hrs8 hrs
Thu9 hrs8 hrs
Fri5 hrs8 hrs

Area

A total that accumulates: an ink line over a faint ink wash, last year as a quiet line.

This yearLast year
Invoiced to date, this year against last yearThe year to date passed last year's total in April.

Invoiced to date, this year against last year
MonthThis yearLast year
Jan£18,400£16,200
Feb£39,600£34,100
Mar£59,400£52,700
Apr£85,800£72,800
May£109,900£95,600
Jun£139,700£117,000
Jul£162,300£136,700
Aug£193,800£161,000
Sep£222,700£186,100
Oct£256,900£213,700
Nov£287,000£240,600
Dec£323,800£270,000

In A Card

On a card: the heading carries the headline, the chart the shape.

Invoiced

£323,800 this year

This yearLast year
Invoiced by month, this year against last yearInvoiced grew in most months; December is the highest at £36,800.

Invoiced by month, this year against last year
MonthThis yearLast year
Jan£18,400£16,200
Feb£21,200£17,900
Mar£19,800£18,600
Apr£26,400£20,100
May£24,100£22,800
Jun£29,800£21,400
Jul£22,600£19,700
Aug£31,500£24,300
Sep£28,900£25,100
Oct£34,200£27,600
Nov£30,100£26,900
Dec£36,800£29,400

All Variants

All three charts on a 6 + 6 and a 7 + 5 row.

BarChart

This yearLast year
Invoiced by month

Invoiced by month
CategoryThis yearLast year
Jan£18,400£16,200
Feb£21,200£17,900
Mar£19,800£18,600
Apr£26,400£20,100
May£24,100£22,800
Jun£29,800£21,400
Jul£22,600£19,700
Aug£31,500£24,300
Sep£28,900£25,100
Oct£34,200£27,600
Nov£30,100£26,900
Dec£36,800£29,400

LineChart

This yearLast year
Invoiced by month

Invoiced by month
CategoryThis yearLast year
Jan£18,400£16,200
Feb£21,200£17,900
Mar£19,800£18,600
Apr£26,400£20,100
May£24,100£22,800
Jun£29,800£21,400
Jul£22,600£19,700
Aug£31,500£24,300
Sep£28,900£25,100
Oct£34,200£27,600
Nov£30,100£26,900
Dec£36,800£29,400

AreaChart

This yearLast year
Invoiced to date

Invoiced to date
CategoryThis yearLast year
Jan£18,400£16,200
Feb£39,600£34,100
Mar£59,400£52,700
Apr£85,800£72,800
May£109,900£95,600
Jun£139,700£117,000
Jul£162,300£136,700
Aug£193,800£161,000
Sep£222,700£186,100
Oct£256,900£213,700
Nov£287,000£240,600
Dec£323,800£270,000

Single series

Hours logged this week

Hours logged this week
CategoryValue
Mon7.5 hrs
Tue8 hrs
Wed6.5 hrs
Thu9 hrs
Fri5 hrs