Quire UI
Charts10

Chart

Lines, areas and bars without a chart library. One tooltip reads every series, arrow keys read it too, and several charts can follow one cursor.

Visitors by day
DayVisitors
Oct 14,082
Oct 24,432
Oct 34,534
Oct 44,584
Oct 54,871
Oct 63,156
Oct 73,018
Oct 84,764
Oct 94,815
Oct 104,921
Oct 114,966
Oct 125,273
Oct 133,659
Oct 143,258
Oct 155,139
Oct 165,186
Oct 175,296
Oct 185,725
Oct 195,661
Oct 203,926
Oct 213,490
Oct 225,502
Oct 235,949
Oct 245,658
Oct 256,114
Oct 266,036
Oct 274,185
Oct 283,985
Oct 295,853
Oct 30, so far2,210

Installation

npx shadcn@latest add @quireui/chart

Usage

Pass the rows, the field that names each row, and the series to draw from them.

<Chart
  label="Visitors by day"
  data={[
    { day: "Oct 1", visitors: 4200 },
    { day: "Oct 2", visitors: 4410 },
    // ...
  ]}
  x="day"
  type="area"
  series={[{ key: "visitors", label: "Visitors" }]}
/>

label names the chart for screen readers and the table. format takes the options of Intl.NumberFormat or your own function, and the axis switches to 12K and 1.2M on its own once the numbers get that big.

Lines, areas and bars

  • line for a level that moves, like response time. Its scale fits the data, so small changes show.
  • area for a total and its shape, like visitors. It starts at zero, because an area is read by its size.
  • bar for counts, like signups per week. Bars start at zero too, and the one under the pointer stays solid while the rest step back.

It is one component either way: every option below is a prop on Chart, off until you set it, so a plain chart stays plain.

Curves

curve sets how lines and areas run between points. linear joins them straight, and is the default. smooth curves through them without ever overshooting, so it cannot draw a peak or a dip the data does not have. step holds each value until the next, for things that change in jumps, like a price, a plan or a seat count.

Response time by day
DayResponse time
Oct 1182 ms
Oct 2187 ms
Oct 3190 ms
Oct 4191 ms
Oct 5189 ms
Oct 6207 ms
Oct 7178 ms
Oct 8170 ms
Oct 9163 ms
Oct 10156 ms
Oct 11152 ms
Oct 12151 ms
Oct 13174 ms
Oct 14156 ms
Oct 15161 ms
Oct 16165 ms
Oct 17168 ms
Oct 18169 ms
Oct 19166 ms
Oct 20184 ms
Oct 21155 ms
Oct 22147 ms
Oct 23139 ms
Oct 24133 ms
Oct 25130 ms
Oct 26129 ms
Oct 27153 ms
Oct 28135 ms
Oct 29139 ms
Oct 30144 ms

Several series

Each series takes the next chart colour in a fixed order, picked so neighbours stay apart for colour-blind readers and checked against both themes. The legend names them, and clicking a name hides that series. The others keep their colours, so nothing you were reading changes under you. The legend also offers the numbers as a table, which can be downloaded as CSV. table turns that on or off; it is on by default with more than one series.

Visitors by source
DayOrganicPaidReferral
Oct 12,123898490
Oct 22,3051,019496
Oct 32,3581,088472
Oct 42,3841,146550
Oct 52,5331,072546
Oct 61,641726328
Oct 71,569724362
Oct 82,4771,191534
Oct 92,5041,059501
Oct 102,5591,132591
Oct 112,5821,192556
Oct 122,7421,318548
Oct 131,903805439
Oct 141,694749365
Oct 152,6721,233534
Oct 162,6971,297622
Oct 172,7541,165593
Oct 182,9771,317595
Oct 192,9441,359679
Oct 202,042982440
Oct 211,815768363
Oct 222,8611,265660
Oct 233,0931,428666
Oct 242,9421,415588
Oct 253,1791,345734
Oct 263,1391,388676
Oct 272,1761,004435
Oct 282,072996478
Oct 293,0441,288656
Oct 301,150480260

Bars side by side for comparing, stacked for a total and its parts. Stacked parts are split by a hairline of the surface, not an outline.

Signups by plan
WeekFreePro
Sep 818064
Sep 1521685
Sep 2225282
Sep 29222103
Oct 6258100
Oct 13294121
Oct 20264118
Oct 27300139
Signups by plan, stacked
WeekFreeProTeam
Sep 81806418
Sep 152168521
Sep 222528224
Sep 2922210327
Oct 625810030
Oct 1329412133
Oct 2026411836
Oct 2730013939

The tooltip on a stack adds a total under the parts, so nobody has to add them up.

stacked="percent" stacks the parts as shares of the whole, each row adding up to 100%, for how a mix changes over time. The tooltip shows each part's value and its share.

Share of visitors by source
DayOrganicPaidReferral
Oct 12,123898490
Oct 22,3051,019496
Oct 32,3581,088472
Oct 42,3841,146550
Oct 52,5331,072546
Oct 61,641726328
Oct 71,569724362
Oct 82,4771,191534
Oct 92,5041,059501
Oct 102,5591,132591
Oct 112,5821,192556
Oct 122,7421,318548
Oct 131,903805439
Oct 141,694749365
Oct 152,6721,233534
Oct 162,6971,297622
Oct 172,7541,165593
Oct 182,9771,317595
Oct 192,9441,359679
Oct 202,042982440
Oct 211,815768363
Oct 222,8611,265660
Oct 233,0931,428666
Oct 242,9421,415588
Oct 253,1791,345734
Oct 263,1391,388676
Oct 272,1761,004435
Oct 282,072996478
Oct 293,0441,288656

Bars and a line together

A series can set its own type, so a line can run over bars, like daily signups with their weekly average. They share one scale; there is no second axis, because two scales on one plot let any two lines look related. If the line is a different unit, give it its own chart and sync their cursors.

Signups by day, with the weekly average
DaySignups7-day average
Oct 1127
Oct 2153
Oct 3151
Oct 4148
Oct 5151
Oct 6109
Oct 7101134
Oct 8153138
Oct 9149137
Oct 10170140
Oct 11166143
Oct 12170145
Oct 13113146
Oct 14113148
Oct 15172150
Oct 16167153
Oct 17164152
Oct 18198157
Oct 19189159
Oct 20126161
Oct 21108161
Oct 22190163
Oct 23199168
Oct 24182170
Oct 25190169
Oct 26209172
Oct 27140174
Oct 28128177
Oct 29181176
Oct 30, so far64156

Stacks take negative values too: positive parts build up from zero and negative ones down, so profit and loss reads right. Here costs and refunds sit below the line, with the net drawn over them.

Profit and loss by month
MonthRevenueCostsRefundsNet
Jan$42,000-$31,000-$6,000$5,000
Feb$45,000-$32,000-$4,000$9,000
Mar$51,000-$35,000-$9,000$7,000
Apr$48,000-$38,000-$12,000-$2,000
May$56,000-$36,000-$5,000$15,000
Jun$61,000-$40,000-$7,000$14,000

The period before

previous on a series names a field with the same point in the period before. It is drawn dashed behind the series, and the tooltip shows both.

A period still running

partial says the last row is still being counted, like today. Its line turns dashed for the last step, or its bar fades, and it reads "Oct 30, so far", so a half-finished day does not look like a crash.

The scale

Bars and areas start at zero, and lines fit their data; zero changes that. min and max set the ends exactly, like 99% to 100% for uptime, where any dip matters, or 0 to 100 for a percentage. A value past an end you set is drawn at the edge.

Uptime by day
DayUptime
Oct 1100.00%
Oct 299.99%
Oct 399.98%
Oct 4100.00%
Oct 599.99%
Oct 6100.00%
Oct 799.99%
Oct 899.98%
Oct 9100.00%
Oct 1099.99%
Oct 11100.00%
Oct 1299.42%
Oct 1399.98%
Oct 14100.00%
Oct 1599.99%
Oct 16100.00%
Oct 1799.99%
Oct 1899.98%
Oct 19100.00%
Oct 2099.99%
Oct 21100.00%
Oct 2299.99%
Oct 2399.98%
Oct 2499.81%
Oct 2599.99%
Oct 26100.00%
Oct 2799.99%
Oct 2899.98%
Oct 29100.00%
Oct 3099.99%

Goals and limits

references draws a line across the plot for a goal or a limit, named at its end. With to, it is a band between two values, like an acceptable range for response time. The scale always makes room for them.

Notes on the timeline

notes marks events by a row's x: a deploy, a launch, an outage. A note is a thin line with its name beside it, or with to, a shaded span. Its name shows in the tooltip and is read out with the row, so a spike explains itself. Pass the same notes to every chart on a page and they line up across all of them.

Visitors by day, with events
DayVisitors
Oct 14,082
Oct 24,432
Oct 34,534
Oct 44,584
Oct 54,871
Oct 63,156
Oct 73,018
Oct 84,764
Oct 94,815
Oct 104,921
Oct 114,966
Oct 125,273
Oct 133,659
Oct 143,258
Oct 155,139
Oct 165,186
Oct 175,296
Oct 185,725
Oct 195,661
Oct 203,926
Oct 213,490
Oct 225,502
Oct 235,949
Oct 245,658
Oct 256,114
Oct 266,036
Oct 274,185
Oct 283,985
Oct 295,853
Oct 30, so far2,210
<Chart
  {...visitors}
  references={[{ value: 5500, label: "Goal" }]}
  notes={[
    { x: "Oct 9", label: "Launched on Hacker News" },
    { x: "Oct 20", to: "Oct 23", label: "Pricing test" },
  ]}
/>

Choosing a range

With onRangeSelect, a drag across the plot chooses a range of rows and calls it with the first and last x. By keyboard, hold Shift with the arrow keys and press Enter. Hand it to a Date range picker and the whole page follows the range you drew. A click that stays put still picks a single row. On touch, a drag keeps reading the chart, so it never fights scrolling.

Drag across the chart to choose dates.
Signups by day
DaySignups
Oct 1127
Oct 2153
Oct 3151
Oct 4148
Oct 5151
Oct 6109
Oct 7101
Oct 8153
Oct 9149
Oct 10170
Oct 11166
Oct 12170
Oct 13113
Oct 14113
Oct 15172
Oct 16167
Oct 17164
Oct 18198
Oct 19189
Oct 20126
Oct 21108
Oct 22190
Oct 23199
Oct 24182
Oct 25190
Oct 26209
Oct 27140
Oct 28128
Oct 29181
Oct 30, so far64

One cursor for several charts

active is the row under the cursor, by its x, and onActiveChange reports it. Give several charts the same value and they all read the same day; the one you are pointing at shows the tooltip, the others show the line. Stat cards in a group match on the same names.

Point at either chart.

Visitors by day
DayVisitors
Oct 14,082
Oct 24,432
Oct 34,534
Oct 44,584
Oct 54,871
Oct 63,156
Oct 73,018
Oct 84,764
Oct 94,815
Oct 104,921
Oct 114,966
Oct 125,273
Oct 133,659
Oct 143,258
Oct 155,139
Oct 165,186
Oct 175,296
Oct 185,725
Oct 195,661
Oct 203,926
Oct 213,490
Oct 225,502
Oct 235,949
Oct 245,658
Oct 256,114
Oct 266,036
Oct 274,185
Oct 283,985
Oct 295,853
Oct 30, so far2,210
Signups by day
DaySignups
Oct 1127
Oct 2153
Oct 3151
Oct 4148
Oct 5151
Oct 6109
Oct 7101
Oct 8153
Oct 9149
Oct 10170
Oct 11166
Oct 12170
Oct 13113
Oct 14113
Oct 15172
Oct 16167
Oct 17164
Oct 18198
Oct 19189
Oct 20126
Oct 21108
Oct 22190
Oct 23199
Oct 24182
Oct 25190
Oct 26209
Oct 27140
Oct 28128
Oct 29181
Oct 30, so far64

onPick is called with a row's x on click or Enter, for pinning a day or opening it.

Loading and empty

While new rows load, a chart that already has some keeps them, dimmed, so nothing jumps. Without rows it holds its height with a placeholder. With no rows at all it says so.

Signups by plan
WeekFree
Sep 8180
Sep 15216
Sep 22252
Sep 29222
Oct 6258
Oct 13294
Oct 20264
Oct 27300
No data
Refunds by day
DayRefunds

Making it your own

Every part can go or change, without a second chart component to learn:

  • legend, axes (both, x, y or none) and grid turn the legend, the axis labels and the gridlines on or off.
  • fill sets areas to fade toward the baseline, the default, or to one flat tint.
  • tooltip={false} drops the tooltip; the row still reads out to screen readers. A function instead draws your own content in the tooltip's frame, given the row, every series' value, the total and any notes.
  • Each part has a data-slot to style from your own CSS: chart-legend, chart-y-axis, chart-x-axis, chart-grid, chart-bar, chart-line, chart-area, chart-tooltip, chart-reference, chart-note.

A tooltip with the conversion rate worked out from two fields:

Visitors and signups by day
DayVisitors
Oct 14,082
Oct 24,432
Oct 34,534
Oct 44,584
Oct 54,871
Oct 63,156
Oct 73,018
Oct 84,764
Oct 94,815
Oct 104,921
Oct 114,966
Oct 125,273
Oct 133,659
Oct 143,258
Oct 155,139
Oct 165,186
Oct 175,296
Oct 185,725
Oct 195,661
Oct 203,926
Oct 213,490
Oct 225,502
Oct 235,949
Oct 245,658
Oct 256,114
Oct 266,036
Oct 274,185
Oct 283,985
Oct 295,853
Oct 30, so far2,210

With no axes, grid or legend, a chart fits a small card:

Visitors

Visitors, last 30 days
dayVisitors
Oct 14,082
Oct 24,432
Oct 34,534
Oct 44,584
Oct 54,871
Oct 63,156
Oct 73,018
Oct 84,764
Oct 94,815
Oct 104,921
Oct 114,966
Oct 125,273
Oct 133,659
Oct 143,258
Oct 155,139
Oct 165,186
Oct 175,296
Oct 185,725
Oct 195,661
Oct 203,926
Oct 213,490
Oct 225,502
Oct 235,949
Oct 245,658
Oct 256,114
Oct 266,036
Oct 274,185
Oct 283,985
Oct 295,853
Oct 302,210

Signups

Signups, last 30 days
daySignups
Oct 1127
Oct 2153
Oct 3151
Oct 4148
Oct 5151
Oct 6109
Oct 7101
Oct 8153
Oct 9149
Oct 10170
Oct 11166
Oct 12170
Oct 13113
Oct 14113
Oct 15172
Oct 16167
Oct 17164
Oct 18198
Oct 19189
Oct 20126
Oct 21108
Oct 22190
Oct 23199
Oct 24182
Oct 25190
Oct 26209
Oct 27140
Oct 28128
Oct 29181
Oct 3064

Colours

The series colours are tokens in the foundation, --qui-chart-1 to --qui-chart-8, with steps for each theme. Override them there for your brand, or give one series its own color. Stay at eight or fewer; past that, fold the smallest into "Other".

Accessibility

The plot is a slider over the rows. Screen readers hear its name, then every series at the row you move to and any note on it, like "Oct 9: Visitors 4,612. Launched on Hacker News". The numbers are also in a table read with it, and with more than one series the legend can show that table on screen. Every series is named in the legend, so none is told apart by colour alone.

KeyAction
← / →, ↓ / ↑Previous or next row
PageDown / PageUpBack or forward a tenth
Home / EndFirst or last row
Shift + ← / →With onRangeSelect: grows a range from where the cursor was
EnterChooses the range, or calls onPick with the row
EscDrops the range, then leaves the row

Motion

When the chart first scrolls into view, its bars grow up from the baseline a few milliseconds apart and its lines rise into place, all within a quarter of a second; a chart already on screen when the page loads stays put. When new data arrives with the same rows, bars and lines glide to the new numbers while the scale stays still; try the month switch at the top. Hiding a series in the legend glides too: its bars narrow and sink away while the rest slide together and the scale settles, and a line fades out. Pointing at a legend name eases the other series back. The crosshair and the tooltip follow the pointer and the keys without easing, so a value is never on its way; the tooltip and the cursor dots only fade in once. From the keyboard nothing waits, and with reduced motion only the fades remain. animate={false} turns the arrival and the gliding off.

Chart or something else?

  • One figure with its trend: a Stat card, whose sparkline reads the same way.
  • How much of a limit is used: a Meter.

API reference

Chart

Lines, areas or bars, drawn without a chart library. Point at it, or arrow along it, and one tooltip reads every series at that row. The numbers are also a table, for screen readers and on request.

Prop

Type

Also takes every <figure> attribute. Style it with [data-slot="chart"].

On this page