Chart

Line chart and sparkline web components: thin marks, recessive grid, crosshair tooltip, keyboard access and a text summary.

  • 6.1 KB gzipped
  • @lit-material/chart 0.2.0
  • Renders on the server

Example

Install

npm install @lit-material/chart @lit-material/tokens
import "@lit-material/chart";

Link @lit-material/tokens/css/index.css once per page for the colour, type and shape tokens. Install guide

API

<lit-material-bar-chart>

A horizontal bar chart comparing one value across named items, e.g. requests per second per server.

Properties

PropertyAttributeTypeDefaultDescription
datadataBarDatum[][]The bars, drawn in this order unless sort is set. Non-finite values are skipped; negatives draw as zero.
labellabelstring""The chart's accessible name, e.g. "Requests per second, higher is better".
highlighthighlightstring""Name of the item to emphasise.
sortsort"" | "desc" | "asc"""desc or asc sorts by value; anything else keeps the given order.
unitunitstring""A unit appended to values, e.g. "req/s".
formatproperty only(n: number) => stringformatNumberFormats values (default: compact numbers).

CSS parts

PartDescription
chartThe rows container.
tooltipThe hover/focus readout.

CSS custom properties

PropertyDescription
--lit-material-chart-series-1Bar colour without highlight, and the highlighted bar's colour by default.
--lit-material-bar-chart-highlightThe highlighted bar's colour.
--lit-material-bar-chart-mutedThe other bars' colour when highlight is set.
--lit-material-bar-chart-name-widthWidth of the name column (112px).

<lit-material-line-chart>

A line chart for one to eight series over a shared x axis (numbers or times).

Properties

PropertyAttributeTypeDefaultDescription
seriesseriesChartSeries[][]
labellabelstring""The chart's accessible name, e.g. "Requests per second, last 10 minutes".
heightheightnumber240Height in px.
yMiny-minnumber | undefinednoneLower bound of the y axis (default 0, or the data's minimum if it's negative).
formatXproperty only(x: number) => stringformatNumberFormats x values for the axis, tooltip and table (default: numbers).
formatYproperty only(y: number) => stringformatNumberFormats y values (default: compact numbers).
unitunitstring""A unit appended to y values in the tooltip and table, e.g. "req/s".

CSS parts

PartDescription
chartThe chart area.
legendThe legend.
tooltipThe hover/focus readout.

CSS custom properties

PropertyDescription
--lit-material-chart-series-1First series colour (… through -8).

<lit-material-sparkline>

A sparkline: a word-sized line showing the shape of a series, beside the number it explains (a stat tile, a table cell). No axes, so it states its range for screen readers: "label: latest X, from MIN to MAX".

Properties

PropertyAttributeTypeDefaultDescription
valuesvaluesnumber[][]
labellabelstring""What the line shows, e.g. "Requests per second".
showLastshow-lastbooleanfalseMark the last value with a dot.
formatproperty only(value: number) => stringformatNumber

CSS custom properties

PropertyDescription
--lit-material-chart-series-1Line colour.

Source on GitHub npm