Skip to content

Block 254 of 297

Line Chart

Trend lines for up to three series with each series' latest value in the legend and a data table for screen readers.

Puck key
LineChartBlock
Export
lineChartBlock
React component
<LineChart />
Path
components/puck/line-chart-block.tsx
Dependencies
None
License
MIT

About this block

When to use it, how to write for it, and what to change in the code.

What it's for

One to three series plotted over shared x-axis labels, with rounded axis ticks, optional shading under the lines and a legend showing each series' latest value. A "View data table" disclosure underneath lists every point. In a narrow card the chart shortens and shows about four x labels instead of seven. Labels and values accept P1 data bindings.

  • Monthly visits, enrollment or traffic over a year
  • Comparing two programs or channels over the same period
  • Tracking a metric against last year's line
Writing the content
  • Enter X-axis labels comma-separated, oldest first, then give each series one value per label in the same order.
  • Leave a value empty between commas, like 12, , 9, to draw a gap for a missing month instead of a zero.
  • The third series draws as a dashed gray line, which suits a baseline such as last year or a target.
  • Short suffixes like % show on the axis. Longer ones like visits appear only in the legend and data table.
Accessibility
  • The chart area has role="img" with a summary that gives the range and each series' latest, low and high values.
  • The data table behind "View data table" is a native details disclosure with a real table, column headers and periods as row headers (WCAG 1.3.1).
  • Series are told apart by shade, a dashed third line and the legend's names, and the disclosure toggle has a 44px minimum height and focus outline.
Customizing the code
  • Series colors and the dash pattern live in the STYLES array.
  • Chart height is the CHART_HEIGHT constant, h-44 @md:h-56.

Editor fields

What content editors see in the P1 sidebar when they select this block.

  • Titletext
  • Heading levelselect
  • Subtitle or periodtext
  • X-axis labelstext
  • Seriesarray
  • Value prefixtext
  • Value suffixtext
  • Shade under linesradio
  • Footnotetext