Blog / Development
How to build charts in React without a chart library
Most dashboard charts are a scale, a shape and a few labels. React already renders SVG, so you can draw them yourself in a few dozen lines, without a chart package. Here is how, and when you should still reach for a library.
By Abdullah NomanNovember 30, 20263 min read

Short answer: render an <svg> with a fixed viewBox, map your data to coordinates with a linear scale, draw the marks with <path>, <rect> or <circle>, and add tick labels as <text>. Let the SVG scale with CSS. This covers line, area, bar, column, donut and most KPI charts with no dependency at all.
What is the smallest working chart?
const W = 320, H = 200, pad = 24
const lin = (d0, d1, r0, r1) => (v) => r0 + ((v - d0) / (d1 - d0)) * (r1 - r0)
export function Line({ values }: { values: number[] }) {
const x = lin(0, values.length - 1, pad, W - pad)
const y = lin(0, Math.max(...values), H - pad, pad)
const d = values.map((v, i) => (i ? "L" : "M") + x(i) + "," + y(v)).join(" ")
return (
<svg viewBox={`0 0 ${W} ${H}`} style={{ width: "100%", height: "auto" }} role="img" aria-label="Revenue by month">
<path d={d} fill="none" stroke="currentColor" strokeWidth={2} />
</svg>
)
}
That is the whole idea. Everything else, axes, gradients, tooltips, is more of the same.
Which building blocks do you need?
| Piece | What it does | Typical size |
|---|---|---|
| Linear scale | Maps a value to a pixel position | One line |
| Band scale | Gives each bar a slot and a width | A few lines |
| "Nice" ticks | Picks round axis values like 0, 25, 50 | About ten lines |
| Path builders | Straight, stepped or smooth lines, areas, arcs | A few lines each |
| Tooltip | Shows the value under the pointer | A small component |
How do you make it responsive?
Draw in a fixed coordinate system (say 320 by 200) and let the browser scale the SVG with width: 100%; height: auto. Text scales with it, so keep labels short. For very different layouts on phones, render fewer ticks or switch a horizontal bar chart for a vertical one rather than squeezing.
How do you add tooltips?
Put onPointerMove on each mark, read the pointer position relative to the chart container, and render an absolutely positioned div over the SVG. Pointer events cover mouse, pen and touch in one handler. Hide it on onPointerLeave.
When should you still use a chart library?
- Huge data: tens of thousands of points or live streaming data. Canvas or WebGL renderers handle that better than SVG.
- Exploration tools: zoom, brush, pan and linked views across many charts.
- Geographic maps and projections.
For a product dashboard with a dozen charts of a few hundred points, plain SVG is usually lighter, easier to style and easier to keep.
Is there a shortcut?
Liniqo Charts is this approach, finished: 528 charts in 67 types built from the same small helpers, with tooltips, hover dimming, animations, light and dark themes. Download the folder once and copy what you need.
Questions
Is SVG fast enough for React charts?
For dashboard-sized data, yes: a few hundred to a few thousand marks render smoothly. For tens of thousands of points, use canvas.
Do I need D3 to make charts in React?
No. D3 helps with scales and layouts, but the scales most dashboards need are a few lines of plain TypeScript, and React renders the SVG.
How do I make an SVG chart responsive?
Give the SVG a viewBox and set width to 100% and height to auto, so it scales with its container.
How do I add tooltips to an SVG chart in React?
Listen for pointer events on each mark, compute the pointer position inside the chart container, and render an absolutely positioned element there.


