Skip to content

Line Chart ​

x-h-chart-line draws a line chart from a single reactive configuration object. Multiple series are overlaid on a shared axis. Charts inherit the active theme colors and adapt to light and dark mode automatically.

Usage ​

Give the chart a container with an explicit height (charts fill their parent). Provide one or more series, each a list of numeric data points, and a matching labels array naming the points along the axis. Use a line chart to show a trend across an ordered sequence. To compare discrete categories use a Bar Chart, and for parts of a whole use a Pie Chart.

API Reference ​

Component attribute(s) ​

x-h-chart-line

Attributes ​

AttributeTypeRequiredDescription
data-font-sizexs
sm
base
lg
falseChanges the size of all chart text, such as labels, axis ticks, and the legend. Defaults to xs.

Configuration ​

KeyTypeDefaultDescription
series{ name?, color?, data: number[] }[][]One entry per line. Multiple series are overlaid. For color values, see Colors.
labelsstring[][]Label for each data index.
legendbooleantrueShow the color/label key.
axesbooleantrueShow the numeric axis ticks and labels.
gridlinesbooleantrueShow gridlines behind the lines.
tooltipbooleantrueShow a tooltip on hover and emit interaction events.
dataLabelsbooleanfalseDraw each point's value next to it.
tickCountnumber5Target number of numeric axis ticks.
valueFormat(value) => stringlocale numberFormats values in tooltips and numeric axis ticks.
palettestring[]color-1 to color-9Chart colors cycled for series without an explicit color. See Colors for more information.
seriesLabelstringSeries {index}Template naming a series that has no name. {index} is substituted.
tableLabels{ category? }English defaultsColumn headers of the hidden data table read by screen readers.

Colors ​

A series color (and the palette entries) is one of the chart colors color-1 to color-12. They paint with the theme's --chart-color-1 to --chart-color-12 variables (see Theme Customization). By default, they map to blue, red, green, orange, purple, teal, pink, indigo, yellow, gray, white and black. The standard color names (red, orange, yellow, green, teal, blue, indigo, purple, pink, gray, white and black) are deprecated. They still work but they will be removed in the next major version.

Accessibility ​

The chart is exposed to assistive technologies as a figure with a visually-hidden data table of its values, so screen-reader users get the underlying numbers (the visual lines, axes, and legend are marked decorative). It defaults to the accessible name "Line chart". Set an aria-label attribute on the element to give it a more meaningful name.

Events ​

When tooltip is enabled, hovering and clicking points emit bubbling CustomEvents on the chart element - chart-hover, chart-leave, and chart-click. See the events reference for the shared detail shape.

Data Slots ​

SlotElement
chartx-h-chart-line
chart-svgThe chart drawing
chart-plotThe plot area
chart-segmentThe line of a series
chart-pointA data point
chart-labelA value label
chart-legendThe legend
chart-legend-swatchA legend color swatch
chart-tooltipThe hover tooltip
chart-tableThe data table for assistive technologies
chart-emptyThe message shown when there is no data

Examples ​

Basic ​

html
<div style="height: 20rem" x-h-chart-line="{ labels: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri'], series: [{ name: 'Visitors', data: [120, 200, 150, 280, 240] }] }"></div>

Multiple series ​

html
<div
  style="height: 20rem"
  x-h-chart-line="{
    labels: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri'],
    series: [
      { name: 'Visitors', data: [120, 200, 150, 280, 240] },
      { name: 'Signups', data: [40, 60, 55, 90, 80] }
    ]
  }"
></div>