When a chart has a tooltip

If a chart does not show all its numbers (when it gets too crowded), you need a tooltip. Hovering a row, or tapping it, then shows a tooltip with the name of the row and its values. With several value columns, each value has the name of its column and a sample in its colour, as in the legend. A stack also shows its total.

A chart that shows all its numbers has no tooltip: it would only repeat the number you hover over, and cover it. If the chart gets narrower and has to omit numbers, its tooltip comes on.

This chart has three lines close together, so it has to omit numbers. If you hover over it (or tap it on a touch device), the tooltip shows.

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-legend>
	<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>

How it works

  • The tooltip uses the names and numbers of the chart, so it has the same number format and the same translations.
  • It goes above the row, or below it if there is no room above. It stays inside the window.
  • Pressing any key, tapping somewhere else, or moving the pointer away closes the tooltip. On a touch device, a second tap on the same place closes it too.
  • Only a mouse that moves opens a tooltip. If the page changes under a mouse that rests, for example when a key shows the next slide of a presentation or the page scrolls, no tooltip opens.
  • The text has the size of the chart's text on the screen, also when the chart is scaled.
  • On a chart with steps, a row that has not arrived yet has no tooltip.
  • Screen readers do not read the tooltip. They read the table, which has the same values.

Always or never

If you want a tooltip all the time, also when a chart shows all its numbers, add data-chart-tooltip="true" to the figure. This chart shows all its numbers, and has a tooltip anyway.

Apples picked
Spring 58
Summer 72
Autumn 70
Winter 41
HTML
<figure data-chart="column" data-chart-tooltip="true">
	<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>
</figure>

data-chart-tooltip="false" turns it off. If you want to set it for every chart, use the tooltip option: "auto" by default, true, false or "crosshair".

JS
init({ tooltip: true });

Crosshair

With data-chart-tooltip="crosshair", a line or area chart shows a crosshair instead of a tooltip: a thin line down through the place you hover over, and one across through the point nearest to the pointer. Each line gets a dot, and its value at the side of the value axis, in the colour of its line. The name of the row is under the line down. Values that would touch are pushed apart.

Together with data-chart-values="none" and data-chart-axis, the chart shows clean lines, and exact values only where you hover or tap. This chart has data-chart-axis="right", so the values go over the numbers on the right. See Axes and gridlines.

The price of apples
euro per kilo
Month North South
Jan 2023 1.72 1.52
Feb 2023 1.79 1.62
Mar 2023 1.82 1.60
Apr 2023 1.71 1.54
May 2023 1.67 1.47
Jun 2023 1.53 1.50
Jul 2023 1.52 1.45
Aug 2023 1.54 1.42
Sep 2023 1.52 1.43
Oct 2023 1.64 1.56
Nov 2023 1.68 1.61
Dec 2023 1.82 1.66
Jan 2024 1.94 1.70
Feb 2024 1.92 1.80
Mar 2024 1.94 1.78
Apr 2024 1.83 1.72
May 2024 1.79 1.65
Jun 2024 1.75 1.68
Jul 2024 1.64 1.63
Aug 2024 1.67 1.60
Sep 2024 1.64 1.61
Oct 2024 1.76 1.74
Nov 2024 1.90 1.79
Dec 2024 1.95 1.84
Jan 2025 2.06 1.88
Feb 2025 2.04 1.98
Mar 2025 2.07 1.96
Apr 2025 2.05 1.90
May 2025 1.92 1.83
Jun 2025 1.88 1.86
Jul 2025 1.76 1.81
Aug 2025 1.79 1.78
Sep 2025 1.87 1.79
Oct 2025 1.89 1.92
Nov 2025 2.03 1.97
Dec 2025 2.07 2.02
HTML
<figure data-chart="line" data-chart-tooltip="crosshair" data-chart-values="none" data-chart-axis="right" data-chart-grid data-chart-legend data-chart-scale="1.2 2.2" data-chart-shape="smooth">
	<figcaption><b>The price of apples</b><br><span>euro per kilo</span></figcaption>
	<table>
		<thead>
			<tr><th>Month</th><th>North</th><th data-line="dashed">South</th></tr>
		</thead>
		<tbody>
			<tr><th data-short="2023">Jan 2023</th><td>1.72</td><td>1.52</td></tr>
			<tr><th data-short="2023">Feb 2023</th><td>1.79</td><td>1.62</td></tr>
			<tr><th data-short="2023">Mar 2023</th><td>1.82</td><td>1.60</td></tr>
			<tr><th data-short="2023">Apr 2023</th><td>1.71</td><td>1.54</td></tr>
			<tr><th data-short="2023">May 2023</th><td>1.67</td><td>1.47</td></tr>
			…
			<tr><th data-short="2025">Nov 2025</th><td>2.03</td><td>1.97</td></tr>
			<tr><th data-short="2025">Dec 2025</th><td>2.07</td><td>2.02</td></tr>
		</tbody>
	</table>
</figure>
HTML
<figure data-chart="line" data-chart-tooltip="crosshair" data-chart-values="none" data-chart-axis data-chart-grid data-chart-scale="1.2 2.2">

On other chart types, crosshair gives the normal tooltip. If you want a crosshair on every line and area chart, set the tooltip option to "crosshair".

As the tooltip, the crosshair works with a pointer or a tap, and a second tap on the same place closes it. It is not printed, and screen readers read the table instead.

The line of the crosshair is --tablechart-crosshair-color and --tablechart-crosshair-width, and the size of its text is --tablechart-crosshair-size.

Style it

The background, text, border, corners and shadow of the tooltip are CSS variables. See Styling tooltips, with examples.

Next

See Numbers for how numbers are shown, and CSS variables for all variables.