Calm motion: animations on this site only fade, with no movement
Line chart
Lines or areas over a number or a date axis
Shows how amounts change, for example listeners each day. For amounts in categories, use the bar chart. For a small trend inside text or a table, use the sparkline.
Basic
| Day | Web | App |
|---|---|---|
| 320 | 210 | |
| 340 | 230 | |
| 310 | 260 | |
| 380 | – | |
| 420 | 300 | |
| 390 | 320 | |
| 450 | 310 | |
| 470 | 350 | |
| 440 | 380 | |
| 500 | 400 | |
| 530 | 390 | |
| 510 | 430 | |
| 560 | 460 | |
| 590 | 480 |
- Web
- App
datais a list of rows.xnames the field with the x value, and each item ofseries({ key, label, color }) names a field with a number.- If every x value is a number, the x axis is a number axis with round steps. Else each x value is read as a date (a
Date, a time in milliseconds, or a date text), and the axis shows a short date in the local format. - The rows are drawn in the order of x, so the data can come in any order. A missing value (
null, empty, or not a number) breaks the line, and the line starts again at the next value. - The value axis has round steps that cover the data. It does not have to start at zero, so a small change is easy to see.
areafills the area under each line. A hover shows a line at the nearest point, with the value of each series in a box.- Put the chart in a
BlessChartwithheight="auto"for a title, a description, and a legend. Colors go through the chart colors in the same order as its legend. - The chart draws at the width of its container, measured in the browser, and
heightsets the height (default 280). The dates are written after the page loads, so the server and the browser agree on the time zone. - The chart is hidden from screen readers, and a table of the values is read in its place.
labelnames the table, andx-labelnames its first column.formatsets the text of a value, andformat-xthe text of an x value. - The chart is drawn as plain SVG. There is no chart library to install.
Usage
ts
import { BlessLineChart, type BlessChartSeries } from "blessing-ui";API
Props
| Name | Type | Default | Description |
|---|---|---|---|
data* | BlessChartRow[] | — | one row for each point on the x axis |
x* | string | — | the field of a row with its x value: a number, a `Date`, or a date text |
series* | BlessChartSeries[] | — | one line for each series |
area | boolean | — | fill the area under each line |
height | number | 280 | |
format | ((v: number) => string) | — | text for one value, for example `(v) => v + " ms"` |
formatX | ((x: number | Date) => string) | — | text for one x value; default: the number, or a short date in the local format |
xLabel | string | — | the name of the x column in the table for screen readers; default: `x` |
label | string | "Chart" | names the chart and its table for screen readers |