Column Chart 📊
PicoSPA provides a CSS-only way to render <table> data into a column chart.
Just enhance your table with the class like so <table class="picospa-chart column".
As a teaser let me put a bit more styled column chart here, to get you hooked.
| 15 | |
| 20 | |
| 25 | |
| 35 | |
| 49 | |
| 60 | |
| 77 |
If this style does not fit your taste, no problem follow along for the core that you get for free, and in the end get to the style above or any of your liking.
How To Use
Add the script to your page:
<link href="https://cdn.jsdelivr.net/npm/@pic0/spa@2026.1.12/_dist/chart.css" rel="stylesheet">
<table class="picospa-chart column">
<tbody style="height: 10em;">
<tr>
<th>The 1st column</th>
<td style="--percent: 42%;">42</td>
</tr>
<tr>
<th>The 2nd column</th>
<td style="--percent: 100%;">100</td>
</tr>
...
</tbody>
</table>
The pure table and the table with the classes "picospa-chart" and "column" added as you can see in the code snippet above, will render like this:
| The 1st column | 42 |
|---|---|
| The 2nd column | 100 |
| A 3rd column | 75 |
| Column #4 | 44 |
| The 1st column | 42 |
|---|---|
| The 2nd column | 100 |
| A 3rd column | 75 |
| Column #4 | 44 |
class="picospa-chart column"Inspect the column chart on the right with your devtools, and you will see it is just the css class that makes the difference, if you remove it you get the table just like on the left.
The Data – in tbody
In the code snippet above you can see the simplest set which will render a column chart.
Inside <tbody> you can define any number of <tr>s that have a label <th>
and the value is inside <td>.
<tbody>
<tr>
<th>Column #4</th>
<td style="--percent: 44%;">44</td>
</tr>
...
</tbody>
The style="--percent: 44%;" is the important part here.
This value determines the height of the column. The value should be between 0 and 100%.
Mostly this value is calculated by the server and put right in the data.
This also allows the column chart to not need any extra rendering cycle for running any JS or alike.
The value inside the <td>...</td> is currently not used, for accessibility reasons it is a good idea
to put it there.
The <th>Column #4</th> is used as the label, which renders on top of the column.
It is flipped around by 90 degrees, to be readable from top to bottom.
The Y-Axis – in tfoot (optionally)
Add a y-axis left of the columns.
We do this using the <tfoot> element.
This is optional, if you do not provide <tfoot> the chart will work just fine.
<tfoot>
<tr>
<th>min</th>
<td>0</td>
</tr>
<tr>
<th>middle</th>
<td>10</td>
</tr>
<tr>
<th>max</th>
<td>20</td>
</tr>
</tfoot>
It is the same mechanism, <th> is the label which we do not show on the y-axis, it exists mainly for screen readers, etc. to have
useful table data.
The cell <td> is the value, which we will see as y-axis label.
How many you add is up to you, the CSS is just spreading them across the entire height of the chart,
so it is a good idea, to also choose the values evenly distributed. The distribution of the values
is "only" done inside the <tfoot> which is a flex-box layout using justify-content: space-between.
| One | 1 |
|---|---|
| Two | 2 |
| Three | 3 |
| Four | 4 |
| Five | 5 |
| Six | 6 |
| Seven | 7 |
| Eight | 8 |
| Nine | 9 |
| Ten | 10 |
| 0 | |
| 5 | |
| 10 |
| Ten | 10 |
|---|---|
| Nine | 9 |
| Eight | 8 |
| Seven | 7 |
| Six | 6 |
| One | 1 |
| Two | 2 |
| Three | 3 |
| Four | 4 |
| Five | 5 |
| 0 | |
| 2.5 | |
| 5 | |
| 7.5 | |
| 10 |
The Caption – in caption (optionally)
Add a <caption> at the top of the table to describe the table.
<table>
<caption>This is the CAPTION tag</caption>
...
</table>
| Ten | 10 |
|---|---|
| Nine | 9 |
| Eight | 8 |
| Seven | 7 |
| Six | 6 |
| One | 1 |
| Two | 2 |
| Three | 3 |
| Four | 4 |
| Five | 5 |
| 0 | |
| 2.5 | |
| 5 | |
| 7.5 | |
| 10 |
Grouping Columns – using multiple tbody (optionally)
You can use any number of <tbody> tags inside the table, which might be useful for
styling e.g. the color of the columns.
<table>
<tbody style="--picochart-color: blue; height: 10em;">
<tr><th>Ten</th><td style="--percent: 100%">10</td></tr>
...
</tbody>
<tbody style="--picochart-color: red;">
...
</tbody>
</table>
| Ten | 10 |
|---|---|
| Nine | 9 |
| Eight | 8 |
| Seven | 7 |
| Six | 6 |
| One | 1 |
| Two | 2 |
| Three | 3 |
| Four | 4 |
| Five | 5 |
| 0 | |
| 2.5 | |
| 5 | |
| 7.5 | |
| 10 |
No idea why there is a gap after the first tbody :(
Give it Some Style
As seen above, the column charts can look very simple. Let's give them a bit of shininess and make them look a bit more appealing. This is just the beginning, I am sure you can come up with many more enhancements to make the column chart look (even more) amazing.
| 15 | |
| 20 | |
| 25 | |
| 35 | |
| 49 | |
| 60 | |
| 77 |
What is special?
- the highest value is 77 and i leave it also at 77%, so one can see the "gap" to the 100%
- I set individual colors for each column using CSS var
--picochart-color: red; --percent: 15%values are on the surrounding<tr>, they just "bubble" into the children