How to add an annotation

Annotations go in a div with the class chart-annotations inside the chart. Each annotation in it is a span with data-annotation. An annotation is placed by the data, so if you change a number, the annotation moves with it.

HTML
<figure data-chart="column">
	<table>…</table>
	<div class="chart-annotations"><span data-annotation="bracket">+11%</span></div>
</figure>

Bracket

A bracket shows the change between two bars. If the chart has two bars, no other attributes are needed.

Apple juice
thousands of litres
Last season 251.5
This season 279.6
+11%
HTML
<figure data-chart="column">
	<figcaption><b>Apple juice</b><br><span>thousands of litres</span></figcaption>
	<table>
		<tbody>
			<tr><th>Last season</th><td>251.5</td></tr>
			<tr><th>This season</th><td>279.6</td></tr>
		</tbody>
	</table>
	<div class="chart-annotations"><span data-annotation="bracket">+11%</span></div>
</figure>

Choose the bars

If the chart has more bars, set data-from and data-to to the row numbers. The first row is 1.

2021 74
2022 80
2023 91
2024 102
2025 116
+45%
HTML
<figure data-chart="column">
	<table>
		<tbody>
			<tr><th>2021</th><td>74</td></tr>
			<tr><th>2022</th><td>80</td></tr>
			<tr><th>2023</th><td>91</td></tr>
			<tr><th>2024</th><td>102</td></tr>
			<tr><th>2025</th><td>116</td></tr>
		</tbody>
	</table>
	<div class="chart-annotations"><span data-annotation="bracket" data-from="2" data-to="5">+45%</span></div>
</figure>

Trend

A trend arrow runs from the first value to the last. data-at sets where the badge is along the arrow, from 0 to 1.

If you set data-years to the number of years, Tablechart calculates the yearly rate, and shows a warning in the console if it is different from yours. Your number is always the one shown.

A span with the class tablechart-caption is shown above the badge.

Apples per tree
each
2021 74
2022 80
2023 91
2024 102
2025 116
A year+12%
HTML
<figure data-chart="column">
	<figcaption><b>Apples per tree</b><br><span>each</span></figcaption>
	<table>
		<tbody>
			<tr><th>2021</th><td>74</td></tr>
			<tr><th>2022</th><td>80</td></tr>
			<tr><th>2023</th><td>91</td></tr>
			<tr><th>2024</th><td>102</td></tr>
			<tr><th>2025</th><td>116</td></tr>
		</tbody>
	</table>
	<div class="chart-annotations"><span data-annotation="trend" data-years="4" data-at="0.46"><span class="tablechart-caption">A year</span><span>+12%</span></span></div>
</figure>

Reference line

A reference line marks a value, such as a target or the mean. If you want to put it on the value axis, add data-value. The line then goes across a column, line or area chart, and up a bar chart. data-value is a number, mean or median. The mean and the median are of the values in the table.

Apples picked
Spring 58
Summer 72
Autumn 70
Winter 41
Target
HTML
<figure data-chart="column">
	<figcaption><b>Apples picked</b></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>
	<div class="chart-annotations"><span data-annotation="reference" data-value="60">Target</span></div>
</figure>

If the names of the rows are numbers, add data-name to put the line among them, as if the names were a scale. Here each row is a number of apples on a branch, and its value is how many branches have that many. If you use mean or median, each name counts as often as its value: the mean is the mean number of apples on a branch.

Branches by number of apples
2 3
3 8
4 12
5 9
6 5
7 2
Mean 4.3Median 4
HTML
<figure data-chart="column">
	<figcaption><b>Branches by number of apples</b></figcaption>
	<table>
		<tbody>
			<tr><th>2</th><td>3</td></tr>
			<tr><th>3</th><td>8</td></tr>
			<tr><th>4</th><td>12</td></tr>
			<tr><th>5</th><td>9</td></tr>
			<tr><th>6</th><td>5</td></tr>
			<tr><th>7</th><td>2</td></tr>
		</tbody>
	</table>
	<div class="chart-annotations"><span data-annotation="reference" data-name="mean">Mean 4.3</span><span data-annotation="reference" data-name="median" data-line="dotted">Median 4</span></div>
</figure>

On a scatter chart, data-value is a value on the axis across, so the line goes up. If you want to put the line across, at a value on the axis up, add data-axis="y". The mean and the median are then of the column of that axis.

Harvest and price per variety
Variety Harvest per tree (kg) Price per kg (€)
Elstar 62 1.20
Jonagold 75 1.05
Braeburn 48 1.45
Gala 55 1.30
Cox 35 1.85
Discovery 30 1.75
€1.50
HTML
<figure data-chart="scatter">
	<figcaption><b>Harvest and price per variety</b></figcaption>
	<table>
		<thead>
			<tr><th>Variety</th><th>Harvest per tree (kg)</th><th>Price per kg (€)</th></tr>
		</thead>
		<tbody>
			<tr><th>Elstar</th><td>62</td><td>1.20</td></tr>
			<tr><th>Jonagold</th><td>75</td><td>1.05</td></tr>
			<tr><th>Braeburn</th><td>48</td><td>1.45</td></tr>
			<tr><th>Gala</th><td>55</td><td>1.30</td></tr>
			<tr><th>Cox</th><td>35</td><td>1.85</td></tr>
			<tr><th>Discovery</th><td>30</td><td>1.75</td></tr>
		</tbody>
	</table>
	<div class="chart-annotations"><span data-annotation="reference" data-value="1.5" data-axis="y">€1.50</span></div>
</figure>

The line is dashed. If you add data-line="dotted", it is dotted. The text of the annotation is the label, on the line. If two labels would cover each other, the second one moves beside its line, or one line lower. If the annotation has no text, there is only the line. Where the line crosses a number or a name on the chart, it stops a little before it and goes on after it.

If the label has a number and the line uses mean or median, Tablechart checks it, to the decimals you wrote, and shows a warning in the console if they differ. Your text is always the one shown.

Quadrant

A quadrant divides a scatter chart in four, with a line up and a line across, and names each part in its outer corner. The lines are not in the middle unless you want them there: data-x and data-y say where they are, as a number, mean or median. Each name has data-corner: top left, top right, bottom left or bottom right. The quadrant comes with the scatter chart type, so it works once you add scatter.

Varieties at the market
Variety Share of sales (%) Growth (%)
Elstar 24 1.2
Jonagold 18 -0.8
Braeburn 12 2.9
Gala 9 4.1
Kanzi 6 6.3
Granny Smith 4 -1.5
Wellant 3 3.4
Santana 2 0.4
Cox 7 -2.2
Boskoop 11 -0.3
RisingStarsFadingSteady
HTML
<figure data-chart="scatter" data-chart-grid>
	<figcaption><b>Varieties at the market</b></figcaption>
	<table>
		<thead>
			<tr><th>Variety</th><th>Share of sales (%)</th><th>Growth (%)</th></tr>
		</thead>
		<tbody>
			<tr><th>Elstar</th><td>24</td><td>1.2</td></tr>
			<tr><th>Jonagold</th><td>18</td><td>-0.8</td></tr>
			<tr><th>Braeburn</th><td>12</td><td>2.9</td></tr>
			<tr><th>Gala</th><td>9</td><td>4.1</td></tr>
			<tr><th>Kanzi</th><td>6</td><td>6.3</td></tr>
			<tr><th>Granny Smith</th><td>4</td><td>-1.5</td></tr>
			<tr><th>Wellant</th><td>3</td><td>3.4</td></tr>
			<tr><th>Santana</th><td>2</td><td>0.4</td></tr>
			<tr><th>Cox</th><td>7</td><td>-2.2</td></tr>
			<tr><th>Boskoop</th><td>11</td><td>-0.3</td></tr>
		</tbody>
	</table>
	<div class="chart-annotations"><span data-annotation="quadrant" data-x="10" data-y="1"><span data-corner="top left">Rising</span><span data-corner="top right">Stars</span><span data-corner="bottom left">Fading</span><span data-corner="bottom right">Steady</span></span></div>
</figure>

The quadrant is there from the start, before the dots. Its lines are whole until the name of a dot arrives over them; then the line makes room for the name. If the name of a dot would cover a corner name, the chart has to omit the name of the dot. The tooltip of the dot still shows it. Screen readers read the names of the corners with the annotations, under the table.

With data-fragment on the figure, the axes and the quadrant are shown first, and all dots arrive on the next step. Then you can explain the quadrants before the data comes in. See Step by step.

The lines are dashed by default. If you want to change them, set the --tablechart-quadrant- variables: see CSS variables.

Notes

A note says what happened at a row, such as a “Share issue” or a “New apple press”. A note is not an annotation you write under the table, but a column in the table: a column whose header has data-note. Each cell with text is a note at its row. The chart has a line at that row, with the note at the top.

Apple juice sold
thousands of litres
Quarter Litres Note
Q1 2024 58
Q2 2024 61
Q3 2024 84 New apple press
Q4 2024 90
Q1 2025 88
HTML
<figure data-chart="column">
	<figcaption><b>Apple juice sold</b><br><span>thousands of litres</span></figcaption>
	<table>
		<thead>
			<tr><th>Quarter</th><th>Litres</th><th data-note>Note</th></tr>
		</thead>
		<tbody>
			<tr><th>Q1 2024</th><td>58</td><td></td></tr>
			<tr><th>Q2 2024</th><td>61</td><td></td></tr>
			<tr><th>Q3 2024</th><td>84</td><td>New apple press</td></tr>
			<tr><th>Q4 2024</th><td>90</td><td></td></tr>
			<tr><th>Q1 2025</th><td>88</td><td></td></tr>
		</tbody>
	</table>
</figure>

The note is in the table, so a screen reader reads it with its row, a printed table has it, and a translation script translates it like any other cell. If you hover over the line of the note (or tap it on a touch device), the tooltip shows the note too. A row without a note has an empty cell.

A note works on a chart with its rows across: a column, line, area or waterfall chart. In a summary, data-each="notes" lists them: see Summary. From a JSON file, a row has its note in note: see Data from a file or API.

Break the scale

A break in the scale is not an annotation, but it is added the same way. See Scale break.

Annotations on several lines

On a chart with several lines, data-series sets which line an annotation uses. The first line is 1, and is used if data-series is not set.

HTML
<span data-annotation="trend" data-series="2" data-years="9">+8%</span>