Getting Started
Installation
CDN
<script src="https://unpkg.com/data-chart" defer></script>
npm
npm install data-chart
import "data-chart";
pnpm / yarn
pnpm add data-chart
# or
yarn add data-chart
Basic Usage
Add a data-chart attribute to any HTML <table>:
<table data-chart="bar">
<thead>
<tr>
<th>Month</th>
<th>Sales</th>
</tr>
</thead>
<tbody>
<tr>
<td>Jan</td>
<td>120</td>
</tr>
<tr>
<td>Feb</td>
<td>150</td>
</tr>
<tr>
<td>Mar</td>
<td>180</td>
</tr>
<tr>
<td>Apr</td>
<td>210</td>
</tr>
</tbody>
</table>
That’s it. data-chart automatically converts the table into an SVG chart on page load.
How It Works
- On
DOMContentLoaded, data-chart finds all<table data-chart>elements - Each table is parsed:
<thead>becomes series names,<tbody>becomes data points - An SVG chart is generated and inserted into a
.data-chart-containerwrapper - The original table is hidden (
display: none+aria-hidden="true") - A
MutationObserverwatches for dynamically added tables (SPA support)
Progressive Enhancement
Without JavaScript, the table displays normally. With JavaScript, it becomes a chart. This is progressive enhancement by design.
<!-- Works with JS disabled (shows table) -->
<!-- Works with JS enabled (shows chart) -->
<table data-chart="line">
...
</table>
Next Steps
- Chart Types — Explore all 6 chart types
- Attributes — Full attribute reference
- Animation — Add entrance animations
- Playground — Try it interactively