data-chart

Attributes

All configuration is done via HTML data attributes. No JavaScript config objects needed.

Required

AttributeValuesDescription
data-chartbar | line | area | pie | donutChart type (required)

Layout

AttributeTypeDefaultDescription
data-chart-heightnumber220Chart height in px. Width follows parent.
data-chart-horizontalbooleanHorizontal bar chart. bar only.
data-chart-stackedbooleanStacked bar chart. bar only.

Styling

AttributeTypeDefaultDescription
data-chart-colorscomma-separated hexauto paletteCustom series colors. e.g. "#2d5be3,#1a8c5a"
data-chart-gridy | x | both | noneyGrid line direction
data-chart-legendtop | bottom | noneautoLegend position. Auto: top if 2+ series, none if 1.
data-chart-radiusnumber3Bar corner radius in px

Animation

AttributeTypeDefaultDescription
data-chart-animatebooleanEnable entrance animations
data-chart-animate-durationnumber (ms)600Animation duration per element
data-chart-animate-staggernumber (ms)60Delay between elements

Examples

Minimal

<table data-chart="bar">...</table>

Full options

<table
  data-chart="bar"
  data-chart-height="300"
  data-chart-colors="#e05898,#4a90d9,#1a8c5a"
  data-chart-grid="both"
  data-chart-legend="bottom"
  data-chart-radius="6"
  data-chart-stacked
  data-chart-animate
  data-chart-animate-duration="800"
  data-chart-animate-stagger="100"
>
  ...
</table>

CSS Custom Properties

data-chart injects a minimal stylesheet with one custom property:

:root {
  --dc-font-family: system-ui, -apple-system, sans-serif;
}

Override it to change the font used in axis labels, legends, and toggle buttons.

CSS Classes

ClassElementDescription
.data-chart-container<div>Wrapper around table + SVG
.data-chart-svg<svg>The chart SVG element
.data-chart-rendered<table>Applied to converted tables
.data-chart-grid<g>Grid lines group
.data-chart-axis<g>Axis labels group
.data-chart-series<g>Series data group
.data-chart-legend<g>Legend group
.data-chart-bar<rect>Individual bar
.data-chart-line<path>Line path
.data-chart-area<path>Area fill path
.data-chart-dot<circle>Data point dot
.data-chart-slice<path>Pie/donut slice