LineChart
StableA line chart for change over time. Lines are named at their ends and can be explored with the keyboard.
Also known as line graph, time series chart
Install with npm install @tattva/ui (setup), or copy the code from the kit in Downloads.
Two lines, named at their ends
- Typical order
- Slowest orders
<div className="w-full">
<LineChart series={LATENCY} x={DAYS} unit="minutes" ariaLabel="How long orders take" />
</div>A key shows for two or more lines. The names at the line ends repeat it. Click or tap the chart, or tab to it and use the arrow keys.
When to use it
Shows change over time for up to five lines. Lines are named at their ends where there is room, so people do not have to look back and forth at a key.
Made of: Key · Side scale with 4 to 6 marks · Thin grid lines · Lines · End dots and names · Bottom labels · Guide line and pop-up
Use it for
- A measure tracked over days, hours or months.
- Comparing a few groups over the same time.
- A forecast after real values: set where the projection starts.
- Live data where the latest point may still change: turn on streaming.
Do and avoid
Orders per day
Orders, last 5 days
Do
- Use it for change over time. Keep to four lines where you can.
- Use solid lines for real numbers and dotted lines only for forecasts.
- Put it in a ChartFrame with a summary and a table.
- Switch to several small charts when lines bunch up and their names would overlap.
- Group extra lines into one "Other" line. Lines after the fifth are not drawn.
Avoid
- Don't put two different measures on one chart. Use two charts.
- Don't add a sixth line. Group the smallest into one grey "Other" line.
- Don't change the other colors when a filter removes a line. Each line keeps its color.
- Don't use amber for a line. It is saved for things that need a person.
On a phone
- The chart measures its container and redraws at that width, so it fills a phone screen.
- Touch or drag on the chart to show the tooltip. Vertical swipes still scroll the page, and the tooltip stays until you tap elsewhere.
- The tooltip flips to the left of your finger past the middle of the chart, and axis labels at the edges are pulled inward so they are not cut off.
- Give the chart a height of about 200 to 240px on a phone, and it never goes below 160px.
Seen in products
- Mailchimp uses solid lines for actuals and dotted lines for averages or projections, reported in the Supernova roundup.
- The UK Analysis Function says to use multi-series lines only when essential and to prefer small multiples to many lines.
- Datawrapper recommends direct-labeling lines instead of legends, and notes that dashes or dots can differentiate lines though they may read as projections.
- The UK Analysis Function checklist keeps legend order matching chart order and limits light grey gridlines to at most 10.
Properties
| Prop | Type | Default | Description |
|---|---|---|---|
| seriesrequired | LineSeries[] | none | Up to five series. Each has id, label, data (numbers or null) and optional projectionFrom. Color follows position. |
| xrequired | string[] | none | X labels, one per data position, already formatted. |
| formatValue | (n: number) => string | formatNumber | Formats the axis, labels and tooltip. |
| unit | string | "" | Unit word read after each value by screen readers. |
| height | number | 240 | Plot height in px including the x axis band. Minimum 160. |
| yDomain | [number, number] | none | Fixed y domain. Overrides zeroBaseline. |
| zeroBaseline | boolean | true | Start the y axis at zero when all values are non-negative. |
| streaming | boolean | none | Makes the latest point of each series hollow because it is not final. |
| animate | boolean | none | Reveals the lines once on mount, from left to right in --dur-slow on --ease-arrive. Skipped when the person prefers reduced motion. |
| ariaLabel | string | "Line chart" | Name for the chart region. |
| className | string | none | Extra classes on the wrapper. |
"Show code under the preview gives the code for the example on the stage."
In Figma
In Figma, one LineChart switches all of this from its properties panel, across 4 variants. Each property sets the React prop beside it, so design and code use the same names.
| Figma property | React | Values |
|---|---|---|
| Zero baseline | zeroBaseline | On or off |
| Streaming | streaming | On or off |
Tokens
Change one of these and every part that uses it follows.
--chart-1--chart-2--chart-3--chart-4--chart-5--chart-grid--chart-axis--surface--fg--fg-muted--dur-slow--ease-arrive--radius-overlay
Built in
- You can tab to the chart. Left and Right move between points, Up and Down switch lines, Home and End jump to the ends, and Escape clears.
- Each step is read out as line, time, value and unit, with "projected" or "provisional" added when it applies.
- From the third line on, a dash pattern and a marker shape back up the color.
- The pop-up is hidden from screen readers, because the same values are read out as you move.
- The draw-in animation is skipped when people turn off motion in their system settings.
What you need to do
- Put it in a ChartFrame with a summary and a table.
- Give it an ariaLabel and a unit, so each point is read with what it measures.
Built toward WCAG 2.2 AA and checked automatically; no independent audit yet. Read the accessibility guide