Quick answer
For standard charts, use Chart.js. For large datasets and many chart types, use Apache ECharts. For fully custom visualizations, use D3.js. For scientific and 3D charts, use Plotly.js, and in React apps, use Recharts. For network graphs of nodes and edges, use Cytoscape.js, or Sigma.js for very large graphs. This guide to JavaScript graph libraries compares the main options and shows when each one fits.
JavaScript has dozens of libraries for drawing charts and graphs in the browser, and choosing between them can take longer than building the chart. This guide compares the most widely used options, shows a short example for the main ones, and ends with a quick way to decide which one fits your project. Looking for flowchart and node editors instead of charts? See our guide to JavaScript diagram libraries.
One thing to settle first: “graph” means two different things. Most people searching for a graph library want charts: bar charts, line charts, pie charts. But a graph can also mean a network of nodes joined by edges, like a social network or an org chart. Those need different libraries, so this guide covers both.
Canvas vs SVG
Every chart library draws in one of two ways, and it affects what the library is good at.

- SVG draws each bar, line and label as a separate element in the page. It is sharp at any zoom level, easy to style with CSS, and each element can be inspected and made accessible. It slows down once a chart has many thousands of elements.
- Canvas paints pixels onto a single drawing surface. It stays fast with tens of thousands of data points, but individual shapes are not elements on the page, so the library has to handle hovering, clicking and accessibility itself.
As a rule of thumb, SVG suits most dashboards and reports, and Canvas or WebGL suits very large datasets and real-time charts.
Chart libraries

1. Chart.js
Chart.js is the most popular general-purpose chart library, and the easiest place to start. It is open source under the MIT license and draws with Canvas. It includes the common chart types, such as bar, line, area, pie, doughnut, radar, scatter and bubble, and they are responsive and animated by default.
<canvas id="sales"></canvas>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script>
new Chart(document.getElementById("sales"), {
type: "bar",
data: {
labels: ["Jan", "Feb", "Mar", "Apr"],
datasets: [{ label: "Sales", data: [12, 19, 8, 15] }]
},
options: {
indexAxis: "x" // change to "y" for horizontal bars
}
});
</script>
Older tutorials make horizontal bars with type: "horizontalBar". That was removed in Chart.js 3. Use type: "bar" with indexAxis: "y" instead.
Best for: standard charts on websites and admin dashboards, when you want something working in minutes.
2. Apache ECharts
ECharts is an Apache Software Foundation project, licensed under Apache 2.0. It has a very wide range of chart types, including maps, heatmaps, candlesticks, sankey diagrams, treemaps and gauges, and it renders with either Canvas or SVG. It handles large datasets well and has rich built-in interactions such as zooming, brushing and linked charts.
const chart = echarts.init(document.getElementById("traffic"));
chart.setOption({
xAxis: { type: "category", data: ["Mon", "Tue", "Wed", "Thu", "Fri"] },
yAxis: { type: "value" },
tooltip: { trigger: "axis" },
series: [{ type: "line", smooth: true, data: [820, 932, 901, 934, 1290] }]
});
Best for: data-heavy dashboards and any chart type more unusual than bars and lines.
3. D3.js
D3 is less a chart library than a toolkit for building visualizations yourself. It is open source under the ISC license. It binds data to elements on the page, usually SVG, and gives you the building blocks: scales, axes, shapes, layouts, transitions. There is no type: "bar". You draw the bars.
const data = [12, 19, 8, 15];
const width = 320, height = 160;
const x = d3.scaleBand().domain(d3.range(data.length)).range([0, width]).padding(0.2);
const y = d3.scaleLinear().domain([0, d3.max(data)]).range([height, 0]);
d3.select("#chart")
.append("svg")
.attr("width", width)
.attr("height", height)
.selectAll("rect")
.data(data)
.join("rect")
.attr("x", (d, i) => x(i))
.attr("y", d => y(d))
.attr("width", x.bandwidth())
.attr("height", d => height - y(d))
.attr("fill", "steelblue");
Older D3 code uses .enter().append() to create elements for new data. The .join() method shown here, added in D3 5.8, handles adding, updating and removing elements in one call.
Best for: custom, one-of-a-kind visualizations, such as data journalism or bespoke charts no library offers. It is overkill for a standard bar chart.
4. Plotly.js
Plotly.js is open source under the MIT license, built on D3 and WebGL. It is strong on scientific and statistical charts, including 3D charts, contour plots, box plots and histograms, with zooming and panning built in. It is also the engine behind Plotly for Python and R, so it is familiar to data scientists.
Best for: scientific, statistical and 3D charts.
5. Highcharts
Highcharts is polished, well documented and has strong accessibility support, including screen reader and keyboard navigation. It is not free for commercial use: it is free for personal and non-commercial projects, and businesses need a license.
Best for: commercial products that need a supported, accessible library and can pay for it.
6. Chartist
Chartist is a small, open-source library that draws with SVG and is styled entirely with CSS, which designers like. It covers line, bar and pie charts. Development has been much slower than the libraries above, so check its current state before relying on it for a long-lived project.
Best for: simple, lightweight charts styled with your own CSS.
7. Google Charts
Google Charts is free to use and offers a good range of interactive chart types, including geo charts, timelines and gauges. It is not open source, and the library has to be loaded from Google’s servers, so you cannot host it yourself or use it offline.
Best for: quick charts in simple projects where loading code from Google is acceptable.
Chart libraries for React
If your app uses React, a library built for it fits more naturally than wrapping one of the above:
- Recharts: MIT-licensed, built from React components and SVG. The most common choice for React dashboards.
- Visx: from Airbnb, MIT-licensed. Low-level building blocks combining D3’s maths with React rendering, for custom charts.
- Nivo: MIT-licensed, a wide range of good-looking charts rendered in SVG, Canvas or HTML.
Chart.js and ECharts also have popular React wrappers, react-chartjs-2 and echarts-for-react.
Network graph libraries
For graphs in the nodes-and-edges sense, such as social networks, dependency maps or knowledge graphs, you need a library that handles layout: working out where to place each node so the graph is readable.

- Cytoscape.js: MIT-licensed, the most complete option. It includes many layout algorithms and graph analysis functions, such as shortest paths and centrality.
- Sigma.js: MIT-licensed, renders with WebGL, so it stays fast with very large graphs of many thousands of nodes. Usually paired with the graphology library for the data.
- vis-network: part of the community-maintained vis.js family. Easy to set up, with physics-based layouts that make networks spread out naturally.
cytoscape({
container: document.getElementById("network"),
elements: [
{ data: { id: "a", label: "Alice" } },
{ data: { id: "b", label: "Bob" } },
{ data: { id: "c", label: "Chen" } },
{ data: { source: "a", target: "b" } },
{ data: { source: "b", target: "c" } }
],
style: [{ selector: "node", style: { label: "data(label)" } }],
layout: { name: "cose" }
});
A directed graph has edges that point one way, like a one-way street: “A follows B”. An undirected graph has edges that work both ways: “A is friends with B”. All three libraries can draw either. For directed graphs you add arrowheads to the edges.
How to choose
- Standard charts, quickly: Chart.js.
- Large datasets, many chart types, or rich interaction: Apache ECharts.
- A custom visualization nobody else offers: D3.js.
- Scientific, statistical or 3D charts: Plotly.js.
- A React app: Recharts, or Visx for custom work.
- A commercial product needing support and strong accessibility: Highcharts, with a license.
- Networks of nodes and edges: Cytoscape.js, or Sigma.js for very large graphs.
Whichever you pick, check the license against your project before you ship, and remember accessibility: a chart should have a text summary or a data table nearby for people who cannot see it.
Choosing between JavaScript graph libraries
There is no single best JavaScript graph library, only the best fit for the job. Most projects are well served by Chart.js or ECharts, D3 is there when you need to build something truly custom, and network graphs need a dedicated library such as Cytoscape.js. If you are deciding between libraries for a particular project, describe it in the comments and we can help you choose.
Frequently asked questions
What is the best free JavaScript chart library?
For most projects, Chart.js, which is MIT-licensed, is the easiest place to start. Apache ECharts, licensed under Apache 2.0, is the best free option for large datasets and unusual chart types.
Is D3.js a chart library?
Not exactly. D3 is a toolkit for building visualizations yourself: it binds data to page elements and provides scales, axes and layouts, but it has no ready-made chart types.
Which chart library is best for React?
Recharts is the most common choice for React dashboards. Visx suits custom charts, and Chart.js and ECharts also have popular React wrappers.
Should I use Canvas or SVG for charts?
SVG suits most dashboards and is easier to style and make accessible. Canvas, or WebGL, is faster for tens of thousands of data points and for real-time charts.
Is Highcharts free?
Only for personal and non-commercial projects. Commercial use needs a paid license.
Which library should I use for network graphs?
Cytoscape.js is the most complete library for graphs of nodes and edges. Sigma.js is best for very large graphs, and vis-network is the quickest to set up.
Sources and further reading
- Chart.js documentation: including the migration notes for horizontal bars
- Apache ECharts handbook: getting started with ECharts
- D3.js: official D3 documentation and examples
- Plotly.js: Plotly’s JavaScript library
- Cytoscape.js: documentation for network graphs

Leave a Reply