A table

A chart is a figure with data-chart and a table in it. Each row of the table is a bar or a point. The first cell of a row is its name, the other cells are its values.

A chart is always a figure, with a figcaption for the title. Then the chart has a name, also for screen readers. If the element is not a figure, a message in the console shows this.

Apples picked
thousands
Spring 58
Summer 72
Autumn 70
HTML
<figure data-chart="column">
	<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>
		</tbody>
	</table>
</figure>

The table stays on the page, but it is hidden for sighted users. Screen readers, search engines and translation scripts can still read it. If JavaScript does not run, the table is all there is.

The figcaption is the title of the chart. Text after a br is shown as its subtitle. A figcaption is not needed: you can also put a heading above the figure, and style it like the other headings on your page.

Several value columns

If the table has more than 1 value column, each column is a line, or a bar in each group. The table then needs a thead: its headers are the names of the columns.

HTML
<table>
	<thead>
		<tr><th>Variety</th><th>2022</th><th>2026</th></tr>
	</thead>
	<tbody>
		<tr><th>Elstar</th><td>118</td><td>131</td></tr>
	</tbody>
</table>

See Column, Bar, Line and Area.

Attributes on rows and headers

Attribute On Does
data-kind="total" A row Makes the row a total, in a waterfall or a donut
class A row Is copied to the bar, the number and the name of the row
data-kind="focus" A column header Highlights that line or bar
data-marker A column header Sets the point of a line
data-line A column header Makes a line dashed or dotted

A JSON file or endpoint

If the data comes from a JSON file or an API endpoint, see Data from a file or API.

A table from Markdown

If your Markdown tool can add attributes to a table, add data-chart to the table. This example uses markdown-it-attrs, which reads the attributes from the line after the table.

Markdown
: **Apples picked**\
thousands

| Season | Apples |
| ------ | ------ |
| Spring | 58     |
| Summer | 72     |
| Autumn | 70     |
{data-chart=column}

Markdown has no figcaption, so a paragraph that starts with ": " just before or after the table is the title. A line break in it starts the subtitle. Tablechart puts the table and the title together in a div with the chart attributes.

You can also leave out the ": " paragraph and write the title as a heading above the table, such as #### Apples picked.

: Apples picked
thousands

Season Apples
Spring 58
Summer 72
Autumn 70

In the first column, a name in **bold** makes the row a total. In the header, a name in bold is highlighted.

Next

If you want to change how the numbers are shown, see Numbers. For what a screen reader gets from a chart, see Accessibility.