Get started
How to install Tablechart, write the markup and start it.
Install
Installing Tablechart
npm install @martinomagnifico/tablechart
Using Tablechart
Installing Tablechart
Download the ZIP from the releases page, unzip, and place the files somewhere your HTML can reach.
Using Tablechart
Installing Tablechart
No download needed. Files are served directly from jsDelivr.
https://cdn.jsdelivr.net/npm/@martinomagnifico/tablechart@latest/dist/
Using Tablechart
Additional types
The column, bar, line, area, waterfall, donut and pie charts are in the main script. If you use an additional type, such as the scatter or the candlestick chart, load it as well, before the charts are made.
If you use a build tool, import the type and add it with addType():
import { addType, init } from '@martinomagnifico/tablechart';
import { scatter } from '@martinomagnifico/tablechart/additional-types';
import '@martinomagnifico/tablechart/style.css';
addType('scatter', scatter);
init();
If you use a script tag, load tablechart-additional-types.js after tablechart.js. It adds all the additional types.
<link rel="stylesheet" href="tablechart.css">
<script src="tablechart.js"></script>
<script src="tablechart-additional-types.js"></script>
<script>
Tablechart.init();
</script>
See Additional types.
Markup
A chart is a figure with data-chart and a table in it. Its figcaption is the title. The first cell of a row is the label, the second the value.
| Spring | 58 |
|---|---|
| Summer | 72 |
| Autumn | 70 |
See below how it is just a table.
<figure data-chart="column">
<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>
</tbody>
</table>
</figure>
data-chart sets the chart type: column, bar, line, area, waterfall, donut or pie, or an additional type such as scatter or candlestick.
Start it
init() needs to run once the page has loaded. It makes a chart of every figure with data-chart.
import { init } from '@martinomagnifico/tablechart';
import '@martinomagnifico/tablechart/style.css';
init();
If you want to change when a chart builds, pass options. See Options.
init({
threshold: 0.5, // How much of a chart must be in view
replay: false // Build again when it scrolls back into view
});
Next
- Data in the page: a table in your HTML, or from Markdown
- Data from a file or API: a table from JSON, also from an API
- Chart types
- Styling