Skip to content
Focsd homeFocsd homeFocsd
Forms

Chart

Bar, line, area, stacked, scatter and donut charts whose data is also a summary, a table and keyboard-explorable points.

  • Tag: focsd-chart
  • Pattern: Figure + data table + keyboard-explorable points
  • Category: Charts

Example

HTML
<div class="full">
<focsd-chart id="chart-demo" label="Revenue by quarter" x="quarter"></focsd-chart>
</div>
<script type="module">
const chart = document.getElementById('chart-demo');
chart.series = [
{ key: 'online', label: 'Online' },
{ key: 'stores', label: 'Stores' },
];
chart.format = { style: 'currency', currency: 'USD', maximumFractionDigits: 0 };
chart.data = [
{ quarter: 'Q1', online: 1200, stores: 900 },
{ quarter: 'Q2', online: 1500, stores: 950 },
{ quarter: 'Q3', online: 1700, stores: 1100 },
{ quarter: 'Q4', online: 2100, stores: 1300 },
];
</script>

Usage

Import the module once, then use the tag like any HTML element. Every framework below renders the same element; see Frameworks for setup.

<script type="module">
import '@focsd-dev/charts';
</script>
<focsd-chart label="Revenue by quarter" x="quarter"></focsd-chart>

API

Attributes

AttributePropertyTypeDefault
labellabelstring—
descriptiondescriptionstring—
typetype'bar' | 'line' | 'area' | 'scatter' | 'donut'bar
xxChartKeylabel
yyChartKey—
stackedstackedbooleanfalse
mirrormirrorbooleanfalse
heightheightnumberDEFAULT_HEIGHT
show-tableshowTablebooleanfalse

CSS parts

Style the inside of the component with ::part(), for example focsd-chart::part(figure).

PartDescription
figureThe figure.
captionThe caption (the chart's label).
chartThe drawing area.
pointEach data point (bar, marker or slice); `point-active` when focused.
tooltipThe value shown for the focused or hovered point.
legendThe legend list.
table-toggleThe "Show data table" button.
tableThe data table.

Accessibility

  • A figure named by its caption and described by a generated summary ("Bar chart, 4 categories, 2 series. Highest: Online, Q4, $2,100."), or your own description.
  • Data points are one tab stop: arrow keys move between categories (left and right) and series (up and down), Home and End jump to the ends, and each point is named "Series, category: value".
  • The Show data table button reveals the same numbers as a real table with row and column headers.
  • Series differ by pattern and marker shape as well as color, so the chart works in grayscale and for color-blind readers.
  • Values are formatted with Intl.NumberFormat (format property) in the page language.
  • Set type to area or scatter, add stacked to bars or areas, and mirror to flip the horizontal direction. See the charts guide for each type.

Keyboard

KeyAction
TabMove to the chart, then to the table button
Arrow Left / RightPrevious / next category
Arrow Up / DownPrevious / next series
Home / EndFirst / last category in the series