Skip to content

Block 255 of 297

Bar Chart

Compare categories as columns or a labelled bar list, with optional sorting and a target line.

Puck key
BarChartBlock
Export
barChartBlock
React component
<BarChart />
Path
components/puck/bar-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

Compares categories either as vertical columns or as a horizontal bar list with each label above its bar, which handles long names. You can sort largest first and draw a target line for a goal or average. Vertical charts hide value labels as bars get crowded and thin out category labels past eight bars on narrow cards. Values accept P1 data bindings.

  • Volunteer hours or attendance by site against a goal
  • Yearly totals in order, such as gifts per fiscal year
  • Survey answers or service requests by category
Writing the content
  • Choose Horizontal for long labels or more than eight bars; Bars accepts up to 24.
  • Keep Order on As entered for months or years. Largest first suits rankings.
  • Set Target value and Target label to draw a reference line, like "Quarterly goal per site"; leave it blank to hide the line.
  • In vertical mode with entered order, the last bar is darker to highlight the latest period.
Accessibility
  • Vertical charts have role="img" with a summary listing every category and value plus the target, and a "View data table" disclosure with a real table.
  • In horizontal mode values are printed beside each label as text and the bars are aria-hidden. Each value adds hidden "meets target" or "below target" text when a target is set.
  • The target is drawn as a dark dashed or solid marker and labeled in a text key, not by color alone (WCAG 1.4.1).
Customizing the code
  • Bars use bg-indigo-600, with bg-indigo-400 for earlier periods; swap both to rebrand.
  • Vertical chart height is CHART_HEIGHT (h-48 @md:h-60); bar width is capped by max-w-12.

Editor fields

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

  • Titletext
  • Heading levelselect
  • Subtitle or periodtext
  • Barsarray
  • Orientationradio
  • Orderselect
  • Target valuetext
  • Target labeltext
  • Value prefixtext
  • Value suffixtext
  • Footnotetext