Columns and a line

If you want to show a value column as a line over the columns, add data-chart="line" to its header. The line uses the same scale as the columns, unless it has a value axis of its own. Each point is in the middle of its column, and arrives with it.

Budget and spend
thousands of euros
Month Budget Spent
Jan 40 36
Feb 42 45
Mar 45 41
Apr 45 52
May 50 47
Jun 52 58
HTML
<figure data-chart="column">
	<figcaption><b>Budget and spend</b><br><span>thousands of euros</span></figcaption>
	<table>
		<thead>
			<tr><th>Month</th><th>Budget</th><th data-chart="line">Spent</th></tr>
		</thead>
		<tbody>
			<tr><th>Jan</th><td>40</td><td>36</td></tr>
			<tr><th>Feb</th><td>42</td><td>45</td></tr>
			<tr><th>Mar</th><td>45</td><td>41</td></tr>
			<tr><th>Apr</th><td>45</td><td>52</td></tr>
			<tr><th>May</th><td>50</td><td>47</td></tr>
			<tr><th>Jun</th><td>52</td><td>58</td></tr>
		</tbody>
	</table>
</figure>

A line suits values that have an order, such as months or years. The legend shows a box for the columns and a line for the line.

The line and its points have an edge in the background colour, so they stand out from a column of a similar colour. A number of the line that is fully inside a column gets the colour of the numbers of the columns. A number that is partly over a column, or touches the line inside a column, gets the edge. --tablechart-halo-width sets how wide that edge is. The numbers of the columns are inside the columns if they fit. If the line or one of its points would cover a number inside a column, that number moves to the foot of its column. If the line covers it there too, or a number has no room, the chart has to omit it. If you hover over a column (or tap it on a touch device), a tooltip shows all numbers at that place.

Several columns and a line

With more than one value column without data-chart="line", each row is a group of columns, and the line goes through the middle of each group. Several columns can have data-chart="line", and each one is a line.

Apples sold
thousands
Month Farm shop Market Target
Jan 34 41 70
Feb 38 45 75
Mar 42 53 85
Apr 51 49 95
HTML
<figure data-chart="column">
	<figcaption><b>Apples sold</b><br><span>thousands</span></figcaption>
	<table>
		<thead>
			<tr><th>Month</th><th>Farm shop</th><th>Market</th><th data-chart="line">Target</th></tr>
		</thead>
		<tbody>
			<tr><th>Jan</th><td>34</td><td>41</td><td>70</td></tr>
			<tr><th>Feb</th><td>38</td><td>45</td><td>75</td></tr>
			<tr><th>Mar</th><td>42</td><td>53</td><td>85</td></tr>
			<tr><th>Apr</th><td>51</td><td>49</td><td>95</td></tr>
		</tbody>
	</table>
</figure>

Two value axes

If two columns have different units, such as rainfall and temperature, one scale does not fit both. If a column header has data-axis="right", that column gets a value axis of its own, on the right. The other columns keep the axis on the left.

Climate at the orchard
per month
Month Rainfall (mm) Temperature (°C)
Jan 67 3.4
Feb 56 3.8
Mar 53 6.6
Apr 41 9.9
May 58 13.4
Jun 65 16.1
Jul 74 18.3
Aug 80 18.0
Sep 76 15.0
Oct 85 11.0
Nov 82 7.1
Dec 79 4.2
HTML
<figure data-chart="column" data-chart-grid>
	<figcaption><b>Climate at the orchard</b><br><span>per month</span></figcaption>
	<table>
		<thead>
			<tr><th>Month</th><th>Rainfall (mm)</th><th data-chart="line" data-axis="right">Temperature (°C)</th></tr>
		</thead>
		<tbody>
			<tr><th>Jan</th><td>67</td><td>3.4</td></tr>
			<tr><th>Feb</th><td>56</td><td>3.8</td></tr>
			<tr><th>Mar</th><td>53</td><td>6.6</td></tr>
			<tr><th>Apr</th><td>41</td><td>9.9</td></tr>
			<tr><th>May</th><td>58</td><td>13.4</td></tr>
			<tr><th>Jun</th><td>65</td><td>16.1</td></tr>
			<tr><th>Jul</th><td>74</td><td>18.3</td></tr>
			<tr><th>Aug</th><td>80</td><td>18.0</td></tr>
			<tr><th>Sep</th><td>76</td><td>15.0</td></tr>
			<tr><th>Oct</th><td>85</td><td>11.0</td></tr>
			<tr><th>Nov</th><td>82</td><td>7.1</td></tr>
			<tr><th>Dec</th><td>79</td><td>4.2</td></tr>
		</tbody>
	</table>
</figure>

Both axes show their numbers, and each axis has the names of its columns as its title. Zero is at the same height on both axes, and so is every number, so one set of gridlines fits both. If the chart gets narrower or wider, both axes keep their ends, so the lines keep their places against each other. Only the number of gridlines changes. If a column on the right has values below zero and the left has none, the left axis shows no numbers below zero.

Each column keeps its own decimal places.

Columns on both axes

A column on the right can also be columns rather than a line. Then each row is a group, and each column of the group has the scale of its own axis.

Rain and visitors
per month
Month Rainfall (mm) Visitors
Jan 67 120
Feb 56 140
Mar 53 180
Apr 41 210
May 58 260
Jun 65 300
HTML
<figure data-chart="column" data-chart-grid>
	<figcaption><b>Rain and visitors</b><br><span>per month</span></figcaption>
	<table>
		<thead>
			<tr><th>Month</th><th>Rainfall (mm)</th><th data-axis="right">Visitors</th></tr>
		</thead>
		<tbody>
			<tr><th>Jan</th><td>67</td><td>120</td></tr>
			<tr><th>Feb</th><td>56</td><td>140</td></tr>
			<tr><th>Mar</th><td>53</td><td>180</td></tr>
			<tr><th>Apr</th><td>41</td><td>210</td></tr>
			<tr><th>May</th><td>58</td><td>260</td></tr>
			<tr><th>Jun</th><td>65</td><td>300</td></tr>
		</tbody>
	</table>
</figure>

Two lines or two areas

On a line chart or an area chart, data-axis="right" works the same: that line or area gets the scale on the right. The names of the lines are in a legend under the chart, not at the ends of the lines, so both axes are at the edges of the chart. If you want the names at the ends, add data-chart-legend="false".

Climate at the orchard
per month
Month Rainfall (mm) Temperature (°C)
Jul 74 18.3
Aug 80 18.0
Sep 76 15.0
Oct 85 11.0
Nov 82 7.1
Dec 79 4.2
HTML
<figure data-chart="line" data-chart-grid>
	<figcaption><b>Climate at the orchard</b><br><span>per month</span></figcaption>
	<table>
		<thead>
			<tr><th>Month</th><th>Rainfall (mm)</th><th data-axis="right">Temperature (°C)</th></tr>
		</thead>
		<tbody>
			<tr><th>Jul</th><td>74</td><td>18.3</td></tr>
			<tr><th>Aug</th><td>80</td><td>18.0</td></tr>
			<tr><th>Sep</th><td>76</td><td>15.0</td></tr>
			<tr><th>Oct</th><td>85</td><td>11.0</td></tr>
			<tr><th>Nov</th><td>82</td><td>7.1</td></tr>
			<tr><th>Dec</th><td>79</td><td>4.2</td></tr>
		</tbody>
	</table>
</figure>

What does not combine

  • data-chart="line" on a header works on a column chart only. On a bar, area or waterfall chart, the chart shows that column like the others, and a message in the console shows this.
  • A chart with a line, or with two value axes, cannot be stacked.
  • A chart with two value axes cannot have a break in its scale.
  • If every value column has data-axis="right", the chart has one axis. If you want that axis on the right, add data-chart-axis="right" to the figure.

Next

If you want to change the edge around the line and its numbers, see --tablechart-halo-width in CSS variables.