- 🚀 Zero dependencies
- 🎨 SVG rendering
- 📈 Multiple datasets
- 📉 Straight or smooth curves
- 💡 Interactive value tooltips
- 🎯 Custom point styling
- 🎭 Shadow DOM isolation
- ✨ Clip-path area fills
- ⚡ Responsive (ResizeObserver)
- 🪶 Lightweight (6.6kb)
Simply include the script.
<script src="SVGChart.js"></script><div id="chart"></div>
<script>
const chart = Chart(
document.getElementById("chart"),
[
"Jan",
"Feb",
"Mar",
"Apr",
"May"
]
);
chart.add({
list: [20,35,18,42,28],
line:{
color:"#5B8DEF",
width:3,
curve:.6
}
});
</script>const chart = Chart(element, labels, options);| Name | Type | Description |
|---|---|---|
| element | HTMLElement | Target container |
| labels | Array | X-axis labels |
| options | Object | Global chart options |
{
style:"",
hide:"",
range:function(value){}
}Inject custom CSS into the chart Shadow DOM.
style:`
.chartp{
--pointer:#ff0000;
}
`Always display the tooltip for a specific point.
Example
hide:"(3)"Customize values shown on the left axis.
range(value){
return "$"+value;
}chart.add(options)Example
chart.add({
list:[10,30,20,50,35],
line:{
color:"#00AAFF",
width:3,
curve:.6
}
});Required
list:[]Numeric values.
Length must equal label count.
Configures the SVG line.
line:{
color:"#4A8FFF",
width:3,
curve:.5,
style:""
}Stroke color.
Line thickness.
Smoothness.
0 = straight
0.3 = soft
0.6 = smooth
1 = very smooth
Extra CSS.
Example
style:`
filter:drop-shadow(0 0 8px #4A8FFF);
`Creates a clipping path for area fills.
clip:trueor
clip:-1Style applied to clipped area.
Example
clip_style:`
background:
linear-gradient(
to top,
rgba(0,120,255,.35),
transparent
);
`Customize tooltip values.
value_show(value,label){
return label+": $"+value;
}Every point can be customized.
pointer:`
height:80%;
`pointer_hover:`
height:90%;
`Tooltip style.
value:`
background:#333;
color:white;
`Tooltip while hovering.
The point indicator.
spot:`
background:red;
padding:7px;
`Hovered point indicator.
chart.add({
list:[10,20,30,25,40],
line:{
color:"#4A8FFF"
}
});
chart.add({
list:[15,10,40,35,45],
line:{
color:"#FF5C5C"
}
});Remove last dataset
chart.remove();Remove dataset by index
chart.remove(0);Re-render the chart.
chart.refresh();SVGChart exposes CSS variables.
.chartp{
--pointer:#4A8FFF;
--line:rgba(0,0,0,.08);
--bakcground-value:#222;
--color-value:#fff;
}fully free to use and change

