Perceivable

The parts and numbers of a chart can be seen or heard: with enough contrast, not only by colour, as a table for screen readers, on paper and at any size.

Contrast

A bar, a line, a slice or a part of a stack needs a contrast of at least 3:1 with the background, so it can be seen well. A value inside a bar or column is still text, and needs 4.5:1 contrast with the bar. These are the requirements of WCAG 1.4.11 and 1.4.3.

  • A number inside a bar or column gets at least 5:1 with it where possible, a little more than the 4.5:1 that is needed, so it is easier to read. It is in one of two colours that you can set, or else black or white. --tablechart-value-contrast sets the 5:1. With APCA it is Lc 60, see below. See Numbers inside bars or columns.
  • The parts of a stack and the slices of a donut have a gap in the background colour between them. So two parts in similar colours do not need contrast with each other, only with the background.
  • Without a palette, each next line, part or slice is lighter than the one before it, so it has less contrast with the background. With many lines or slices, the last ones can have less than 3:1. If so, a palette or a range of colours helps: if both ends of a range have at least 3:1 with the background, every step between them has too. See A range of colours.
  • If a column, bar or slice has a colour with less than 3:1 contrast with the background, Tablechart gives it an edge that has enough. See Colours with low contrast. A line gets no edge, so its colour still needs 3:1.
  • A name next to a line has the colour of its line. A line only needs 3:1, but a name is text and needs 4.5:1. If the colour of the line has less, the name gets darker or lighter towards the text colour, just far enough to reach 4.5:1, so it still looks like its line.

For each line, bar, slice or text with too little contrast, a warning in the console shows its name and the contrast it has. That is also text on the background, such as the names next to the lines and the numbers along an axis. The check runs for every chart once it is rendered, also without the debug option, because a printed page or a PDF has the same colours.

WCAG 2 or APCA

By default, Tablechart measures contrast as WCAG 2 does, with a ratio such as 4.5:1. That is the standard that most accessibility rules ask for now. APCA follows what people see more closely. APCA™ is the candidate contrast method for WCAG 3, and is currently in public beta. On a middle colour, such as a teal or a brown, WCAG 2 often prefers black text where white is easier to read.

If you want APCA, set --tablechart-contrast-wcag to 3. Tablechart then uses APCA for everything: to choose the colour of a number inside a bar, and for the warnings in the console. Contrast is then a value such as Lc 60.

WCAG 2, the default APCA, with 3
A bar, line or slice needs 3:1 Lc 30
A number inside a bar needs 4.5:1, or 3:1 if it is large Lc 60, or Lc 45 if it is large
A number inside a bar aims for 5:1 Lc 60
Large text is 24px, or 18.66px bold 36px, or 24px bold

APCA gives light text on a dark background a negative Lc, such as Lc -60. The console shows it with its sign. The minimums in this table count both ways.

Tablechart measures APCA with apca-w3 (opens in a new tab), version 0.1.9 (APCA 0.0.98G-4g). For what APCA is, see Why APCA (opens in a new tab). For questions about APCA, see the APCA discussions (opens in a new tab). APCA is a trademark of Myndex Research and Andrew Somers.

With APCA, a page can have text that an audit tool for WCAG 2 reports, because those tools measure the WCAG 2 way.

The dropdown in this example switches between the two.

How do visitors rate each apple?
% of votes
Variety Love it Like it Fine Not keen Dislike it
Elstar 34 22 18 14 12
Jonagold 28 25 20 15 12
Granny Smith 18 20 24 20 18

The text colour of this chart is changed to deep blue, so it is easy to tell apart from black. That is only for this demo. The numbers have no colour set. Each number gets the pink of the card or the deep blue text colour, whichever has 5:1. On the red parts, that is the pink. On the blue parts, it is the deep blue. On the green and purple parts, neither has 5:1, so the numbers get to be white. On the amber parts, they get to be black.

The text colour of this chart is changed to yellow, so it is easy to tell apart from white. That is only for this demo. The numbers have no colour set. Each number gets the dark pink of the card or the yellow text colour, whichever has 5:1. On the red parts, that is the yellow. On the blue parts, it is the dark pink. On the green and purple parts, neither has 5:1, so the numbers get to be white. On the amber parts, they get to be black.

The text colour of this chart is changed to deep blue, so it is easy to tell apart from black. That is only for this demo. The numbers have no colour set. With --tablechart-contrast-wcag: 3, each number gets the pink of the card or the deep blue text colour, whichever has Lc 60. On the red, green, amber and purple parts, that is the pink. On the blue parts, neither has Lc 60, so the numbers get to be white.

The text colour of this chart is changed to yellow, so it is easy to tell apart from white. That is only for this demo. The numbers have no colour set. With --tablechart-contrast-wcag: 3, each number gets the dark pink of the card or the yellow text colour, whichever has Lc 60. On the red, green, amber and purple parts, that is the yellow. On the blue parts, neither has Lc 60, so the numbers get to be white.

Colour vision

About 8 in 100 men and 1 in 200 women have a colour vision deficiency. Most of them have trouble telling red and green apart: protanopia and deuteranopia are the strongest forms. Trouble with blue and yellow, tritanopia, is rare. So is seeing no colour at all, achromatopsia.

So a line in Tablechart is not told apart by its colour alone. Each line also has its own points, in a fixed order: a filled circle, an open circle, a filled square, an open square, a filled diamond and an open diamond. Lines 7 to 12 have the same points and are dashed, lines 13 to 18 are dotted, and lines 19 to 24 have dashes and dots. If you want another point for a line, set data-marker on its column header. If you want a dashed or dotted line, set data-line. If you want another order for all charts, set the lines option. See Points, Dashed and dotted lines and Your own order.

The dropdown shows this chart about as someone with that colour vision sees it. It is a simulation, and people differ. At first, the markers and dashes are turned off, which only this demo can do. Then only the colours tell the lines apart. If you turn them on, each line also gets its own points and dashes.

Year North South East West
2016 41 30 22 12
2019 58 39 35 20
2022 77 52 41 33
2025 105 61 70 45
HTML
<figure class="a11y-colours" data-chart="line" data-chart-legend>
	<table>
		<thead>
			<tr><th>Year</th><th>North</th><th data-line="dashed">South</th><th>East</th><th data-marker="diamond open">West</th></tr>
		</thead>
		<tbody>
			<tr><th>2016</th><td>41</td><td>30</td><td>22</td><td>12</td></tr>
			<tr><th>2019</th><td>58</td><td>39</td><td>35</td><td>20</td></tr>
			<tr><th>2022</th><td>77</td><td>52</td><td>41</td><td>33</td></tr>
			<tr><th>2025</th><td>105</td><td>61</td><td>70</td><td>45</td></tr>
		</tbody>
	</table>
</figure>

What a screen reader gets

The table stays on the page. It is hidden from sight, but screen readers read it like any other table: the names of the rows and columns, and every value. The chart is hidden from screen readers, with aria-hidden="true", so they do not read everything twice.

If you turn on this switch, the example shows the table that a screen reader reads out loud:

Apples picked
thousands
Spring 58
Summer 72
Autumn 70
Winter 41
HTML
<figure id="a11y-table" data-chart="column" data-chart-table="print">
	<figcaption><b>Apples picked</b><br><span>thousands</span></figcaption>
	<table>
		<tbody>
			<tr><th>Spring</th><td>58</td></tr>
			<tr><th>Summer</th><td>72</td></tr>
			<tr><th>Autumn</th><td>70</td></tr>
			<tr><th>Winter</th><td>41</td></tr>
		</tbody>
	</table>
</figure>

If the chart has a title in a figcaption, Tablechart makes it the name of the figure and of the table, with aria-labelledby. So a screen reader that jumps to the table also reads the title and the unit. If the figure or the table already has a name, with aria-label, aria-labelledby or a caption, it keeps that name.

A screen reader does not read a line break. So Tablechart puts a full stop before each br in the title, hidden from sight, and a screen reader pauses between the title and the subtitle. If the line already ends with a full stop, a question mark, a colon or a comma, nothing is added.

If the chart has no figcaption, add aria-label to the figure, such as aria-label="Apples picked, in thousands".

A summary for a long table

A table is a good alternative to a chart, up to a point. Someone who sees a chart of 60 months sees the highest month and the trend at a glance. Someone who listens to its table hears 60 names and 60 numbers, one after the other, and cannot remember a number from four rows back. To find the highest month, they have to go through every row.

A summary gives a listener what the chart gives at a glance: a few sentences with, for example, the highest and the lowest value, the change from the first value to the last, the trend, and the values far from it. You write the sentences, and Tablechart fills in the numbers from the table, formatted as on the chart.

HTML
<div class="chart-summary">
	<p>The highest price was {highest.value}, in {highest.name}.</p>
	<p data-summary="trend">Without the outliers, the trend is {trend}: from {trend.from} to {trend.to}.</p>
</div>

A screen reader reads the summary right after the title of the chart. The table stays, for a listener who wants every number. The summary is real text in the page, so it can be shown to everyone too, and translated like any other text.

On paper, the summary is often the only alternative a long table has: text that is hidden on the page does not reach a PDF, and a table of 60 rows can take a page of its own. See In print and PDF.

A chart with more than about 15 values needs a summary. See Summary.

Numbers that do not fit

Some charts do not show all their numbers: a stack with small parts, a narrow chart, a chart with many rows, or a line chart with lines close together. The numbers are still in the table, so screen readers read them. If you hover over a column, bar or point (or tap it on a touch device), a tooltip shows them.

If you want to show the table under the chart as well, add data-chart-table="always" to the figure. This chart has three lines close together, so it has to omit numbers. The table under it has them all.

Apples per tree
Year North South East
2018 41 38 35
2019 45 44 42
2020 48 47 49
2021 52 50 51
2022 55 56 53
2023 58 57 59
2024 61 60 62
2025 64 66 63
HTML
<figure data-chart="line" data-chart-table="always">
	<figcaption><b>Apples per tree</b></figcaption>
	<table>
		<thead>
			<tr><th>Year</th><th>North</th><th>South</th><th>East</th></tr>
		</thead>
		<tbody>
			<tr><th>2018</th><td>41</td><td>38</td><td>35</td></tr>
			<tr><th>2019</th><td>45</td><td>44</td><td>42</td></tr>
			<tr><th>2020</th><td>48</td><td>47</td><td>49</td></tr>
			<tr><th>2021</th><td>52</td><td>50</td><td>51</td></tr>
			<tr><th>2022</th><td>55</td><td>56</td><td>53</td></tr>
			<tr><th>2023</th><td>58</td><td>57</td><td>59</td></tr>
			<tr><th>2024</th><td>61</td><td>60</td><td>62</td></tr>
			<tr><th>2025</th><td>64</td><td>66</td><td>63</td></tr>
		</tbody>
	</table>
</figure>

The total of a donut

If a donut has no total row, the central value is the sum of the slices. Tablechart adds it to the table, in a hidden row at the bottom, so screen readers read it with a name: "Total, 74.5". The totallabel option sets the name.

Annotations

The text of an annotation, such as +24% on a bracket, stays in the page under the table, hidden from sight. Screen readers read it there. The badge in the drawing is hidden from them.

In print and PDF

If a chart has to omit numbers, the tooltip shows them on screen. On paper there is no tooltip, so such a chart also needs its table. data-chart-table, or the table option for all charts, says when the table is shown under the chart:

Value On screen In print and PDF
never Hidden Hidden. The default.
auto Hidden Shown, if the chart does not show all its numbers, and the table has no more than 15 values
print Hidden Always shown
always Shown Shown

If your pages become PDFs, use auto. Then a table only takes room on the page when the chart needs it.

With auto, a table with more than 15 values is not printed, and the summary is printed instead. A chart that has neither on paper has no alternative in the PDF. See A summary for a long table.

JS
init({ table: "auto" });

Whether a chart has to omit numbers depends on its width. auto uses the width the chart has on the page.

Zoom and text size

All text is HTML, sized in em. It follows the text size and the zoom of the browser, and stays sharp. Long names beside the bars of a bar chart wrap onto more lines.

Operable

How a chart is used with a keyboard or a pointer, and its movement for visitors who ask for less.

Keyboard

The table is the way to the numbers for screen readers, and they move through it with their own keys. The tooltip only works with a pointer or a tap. If people who use a keyboard, without a screen reader, must be able to read every number, show the table with data-chart-table="always".

Motion

If the visitor has asked for reduced motion in their system settings, charts are shown without animation.

Understandable

Text is read in the language of the page, and numbers have the format of that language.

Language

If the html element has a lang attribute, such as lang="en", screen readers use it to read the text in the right language, and Tablechart uses it to format the numbers. See Numbers.

Robust

A chart is a real table in the page, so it also works without JavaScript.

Without JavaScript

If JavaScript does not run, there is no chart. The table is then shown instead, with its title.

A chart with data-chart-src has no table until JavaScript has read the JSON file. If JavaScript does not run, there is no table and no chart. If the file cannot be read, the figure has a short message instead of the chart, which a screen reader announces. If you want to be sure that the data is always available, write the table in the HTML instead of as a JSON data source.

Standards

Websites in the European Union must meet the European Accessibility Act, which refers to the standard EN 301 549, and through it to WCAG 2.1 at level AA. For a chart, the most important requirements are a text alternative (WCAG 1.1.1) and information that is available as structure (WCAG 1.3.1). A real data table meets both, and Tablechart keeps that table in the page. For a long table, a summary is the alternative a listener can use, and in a PDF it is often the only one.

Tablechart helps with these requirements, but whether a website meets them depends on the whole website. Test your own pages, for example with a screen reader.

Next

For the kinds of chart, see Chart types.