Home / Content and Data / SVG Charts Kit

SVG Charts Kit in JavaScript, Free with Live Demo

Free SVG charts in plain JavaScript. Line, bar and donut charts that scale to any width, with tooltips, keyboard focus, series toggles, animation and an accessible data table.

Open live demoDownload HTML fileView code on GitHub
SVG Charts Kit JavaScript project: line, bar and donut charts drawn with plain SVG, with tooltips and a data table

Runs on: SVG and path math. Works in all modern browsers.

What is the SVG Charts Kit?

A small dashboard with three hand-made SVG charts: monthly revenue as a line chart with two series, orders by weekday as bars, and sales by channel as a donut.

Hover or tab to any point for a tooltip, switch series on and off, shuffle the data to see the charts redraw with animation, and open the data as a plain table.

Good for

  • Admin dashboards
  • Reports and landing page stats
  • Small apps that do not want a chart library
  • Learning how charts are drawn

What this project does

How it works

  1. Scale data to pixelsEach chart maps values to a viewBox with two tiny functions, x(i) and y(v). The viewBox makes the chart scale to any width.
  2. Draw with pathsThe line is one path of M and L commands. Bars are rects. The donut uses circles with stroke-dasharray slices.
  3. Tooltips for mouse and keyboardEvery point is a focusable group with a label. Hover or focus shows the same tooltip, and screen readers read the label.

The key JavaScript

This is the heart of the project. The full file has the rest, including the screen layout and error handling.

const x = (i) => pad + i * (width - pad * 2) / (values.length - 1);
const y = (v) => height - pad - (v / max) * (height - pad * 2);
const d = values.map((v, i) => (i ? "L" : "M") + x(i) + " " + y(v)).join(" ");
svg.innerHTML = `<path d="${d}" fill="none" stroke="#7C3AED" stroke-width="3"/>`;

// donut slice
const len = (value / total) * 2 * Math.PI * r;
circle.setAttribute("stroke-dasharray", `${len} ${circumference - len}`);

How to use it

  1. Click Download HTML file above.
  2. Open the file in a code editor, like VS Code.
  3. Run it from a local server with npx serve . so the camera, microphone and AI features are allowed.
  4. Change the text and colors, then upload it to GitHub Pages, Netlify or your own site. It is one file with no build step.

Questions people ask

When should I use a chart library instead?

For zooming, huge datasets or many chart types. For a few simple charts, plain SVG is lighter and easier to style.

Are SVG charts accessible?

They can be. Here every point has a label, points are focusable and the data is also available as a table.

How do I use my own data?

Replace the generated arrays with numbers from your API and call the draw functions again.

More Content and Data projects