Tablechart

for Reveal.js: Bar charts

Names beside the bars

In a bar chart, the names are shown to the left of the bars. Use it when the names are long.

Picked by variety
thousands
Bramley seedling 31.4
Cox's orange pippin 27.8
Egremont russet 18.2
<figure class="tablechart" data-chart="bar">
  <figcaption>
    <b>Picked by variety</b><br><span>thousands</span>
  </figcaption>
  <table>
    <tbody>
      <tr><th>Bramley seedling</th><td>31.4</td></tr>
      <tr><th>Cox's orange pippin</th><td>27.8</td></tr>
      …
    </tbody>
  </table>
</figure>

Axis and gridlines

Add data-chart-axis for the numbers along the value axis, and data-chart-grid for a line at each of them. The scale then ends on a number of the axis.

Picked by variety
thousands
Bramley seedling 31.4
Cox's orange pippin 27.8
Egremont russet 18.2
<figure class="tablechart" data-chart="bar" data-chart-axis data-chart-grid>
  <figcaption>
    <b>Picked by variety</b><br><span>thousands</span>
  </figcaption>
  <table>
    <tbody>
      <tr><th>Bramley seedling</th><td>31.4</td></tr>
      <tr><th>Cox's orange pippin</th><td>27.8</td></tr>
      …
    </tbody>
  </table>
</figure>

Numbers

A number is shown after its bar. If you want it inside the bar, add data-chart-labels="inside" to the figure. If a bar is too short for its number, the number is shown after the bar.

Juice pressed by variety
thousands of litres
Bramley seedling 31.4
Cox's orange pippin 27.8
Egremont russet 18.2
Discovery 12.6
Worcester pearmain 9.1
<figure class="tablechart" data-chart="bar" data-chart-labels="inside">
  <figcaption>
    <b>Juice pressed by variety</b><br>
    <span>thousands of litres</span>
  </figcaption>
  <table>
    <tbody>
      <tr><th>Bramley seedling</th><td>31.4</td></tr>
      <tr><th>Cox's orange pippin</th><td>27.8</td></tr>
      …
    </tbody>
  </table>
</figure>

Grouped bars

If the table has more than one value column, each row is a group of bars. The column headers are the names in the legend.

Apples sold by variety
thousands
2022 2026
Elstar 118 131
Jonagold 140 135
Braeburn 109 121
<figure class="tablechart" data-chart="bar">
  <figcaption>
    <b>Apples sold by variety</b><br><span>thousands</span>
  </figcaption>
  <table>
    <thead><tr><th></th><th>2022</th><th>2026</th></tr></thead>
    <tbody>
      <tr><th>Elstar</th><td>118</td><td>131</td></tr>
      <tr><th>Jonagold</th><td>140</td><td>135</td></tr>
      <tr><th>Braeburn</th><td>109</td><td>121</td></tr>
    </tbody>
  </table>
</figure>

Rounded ends

If a chart has --tablechart-corner-radius, the end of each bar that shows the value is rounded. The end at the baseline stays square.

Picked by variety
thousands
Bramley seedling 31.4
Cox's orange pippin 27.8
Egremont russet 18.2
<figure class="tablechart" data-chart="bar" style="--tablechart-corner-radius: 6px;">
  <figcaption>
    <b>Picked by variety</b><br><span>thousands</span>
  </figcaption>
  <table>
    <tbody>
      <tr><th>Bramley seedling</th><td>31.4</td></tr>
      <tr><th>Cox's orange pippin</th><td>27.8</td></tr>
      …
    </tbody>
  </table>
</figure>

Rounded ends in a stack

In a stack, only the outer end of the stack is rounded.

Apples sold
thousands
Farm shop Market
2023 64 38
2024 71 45
2025 69 57
<figure class="tablechart" data-chart="bar" data-chart-stack style="--tablechart-corner-radius: 6px;">
  <figcaption>
    <b>Apples sold</b><br><span>thousands</span>
  </figcaption>
  <table>
    <thead>
      <tr><th></th><th>Farm shop</th><th>Market</th></tr>
    </thead>
    <tbody>
      <tr><th>2023</th><td>64</td><td>38</td></tr>
      <tr><th>2024</th><td>71</td><td>45</td></tr>
      …
    </tbody>
  </table>
</figure>

Step by step

Add data-fragment to the figure to show one bar per step.

Picked by variety
thousands
Bramley seedling 31.4
Cox's orange pippin 27.8
Egremont russet 18.2
<figure class="tablechart" data-chart="bar" data-fragment>
  <figcaption>
    <b>Picked by variety</b><br><span>thousands</span>
  </figcaption>
  <table>
    <tbody>
      <tr><th>Bramley seedling</th><td>31.4</td></tr>
      <tr><th>Cox's orange pippin</th><td>27.8</td></tr>
      <tr><th>Egremont russet</th><td>18.2</td></tr>
    </tbody>
  </table>
</figure>

Grouped, step by step

With data-fragment on the figure, each step adds one group.

Apples sold by variety
thousands
2022 2026
Elstar 118 131
Jonagold 140 135
Braeburn 109 121
<figure class="tablechart" data-chart="bar" data-fragment>
  <figcaption>
    <b>Apples sold by variety</b><br><span>thousands</span>
  </figcaption>
  <table>
    <thead><tr><th></th><th>2022</th><th>2026</th></tr></thead>
    <tbody>
      <tr><th>Elstar</th><td>118</td><td>131</td></tr>
      <tr><th>Jonagold</th><td>140</td><td>135</td></tr>
      …
    </tbody>
  </table>
</figure>

Grouped, series by series

Add data-fragment to a column header to show that series in every group on a step.

Apples sold by variety
thousands
2022 2026
Elstar 118 131
Jonagold 140 135
Braeburn 109 121
<figure class="tablechart" data-chart="bar">
  <figcaption>
    <b>Apples sold by variety</b><br><span>thousands</span>
  </figcaption>
  <table>
    <thead>
      <tr>
        <th></th>
        <th data-fragment>2022</th>
        <th data-fragment>2026</th>
      </tr>
    </thead>
    <tbody>
      <tr><th>Elstar</th><td>118</td><td>131</td></tr>
      <tr><th>Jonagold</th><td>140</td><td>135</td></tr>
      …
    </tbody>
  </table>
</figure>

Grouped, one by one

Add data-fragment to every cell. The steps go down each column of the table: one series bar by bar, then the next.

Apples sold by variety
thousands
2022 2026
Elstar 118 131
Jonagold 140 135
Braeburn 109 121
<figure class="tablechart" data-chart="bar">
  <figcaption>
    <b>Apples sold by variety</b><br><span>thousands</span>
  </figcaption>
  <table>
    <thead><tr><th></th><th>2022</th><th>2026</th></tr></thead>
    <tbody>
      <tr>
        <th>Elstar</th>
        <td data-fragment>118</td>
        <td data-fragment>131</td>
      </tr>
      <tr>
        <th>Jonagold</th>
        <td data-fragment>140</td>
        <td data-fragment>135</td>
      </tr>
      …
    </tbody>
  </table>
</figure>

Stacked, step by step

With data-fragment on the figure, each step adds one stack.

Apples sold
thousands
Farm shop Market
2023 64 38
2024 71 45
2025 69 57
<figure class="tablechart" data-chart="bar" data-chart-stack data-fragment>
  <figcaption>
    <b>Apples sold</b><br><span>thousands</span>
  </figcaption>
  <table>
    <thead>
      <tr><th></th><th>Farm shop</th><th>Market</th></tr>
    </thead>
    <tbody>
      <tr><th>2023</th><td>64</td><td>38</td></tr>
      <tr><th>2024</th><td>71</td><td>45</td></tr>
      …
    </tbody>
  </table>
</figure>

Stacked, layer by layer

Add data-fragment to a column header to show that layer on every stack on a step.

Apples sold
thousands
Farm shop Market
2023 64 38
2024 71 45
2025 69 57
<figure class="tablechart" data-chart="bar" data-chart-stack>
  <figcaption>
    <b>Apples sold</b><br><span>thousands</span>
  </figcaption>
  <table>
    <thead>
      <tr>
        <th></th>
        <th data-fragment>Farm shop</th>
        <th data-fragment>Market</th>
      </tr>
    </thead>
    <tbody>
      <tr><th>2023</th><td>64</td><td>38</td></tr>
      <tr><th>2024</th><td>71</td><td>45</td></tr>
      …
    </tbody>
  </table>
</figure>

Stacked, piece by piece

Add data-fragment to every cell. The steps go down each column of the table: the bottom layer piece by piece, then the next layer on top.

Apples sold
thousands
Farm shop Market
2023 64 38
2024 71 45
2025 69 57
<figure class="tablechart" data-chart="bar" data-chart-stack>
  <figcaption>
    <b>Apples sold</b><br><span>thousands</span>
  </figcaption>
  <table>
    <thead>
      <tr><th></th><th>Farm shop</th><th>Market</th></tr>
    </thead>
    <tbody>
      <tr>
        <th>2023</th>
        <td data-fragment>64</td>
        <td data-fragment>38</td>
      </tr>
      <tr>
        <th>2024</th>
        <td data-fragment>71</td>
        <td data-fragment>45</td>
      </tr>
      …
    </tbody>
  </table>
</figure>