D3.js Online Compiler / Playground
Write, test, and instantly preview D3.js data visualizations and SVG graphics online with our free Online D3.js Compiler / Playground. Experiment with data binding, DOM selections, scales, axes, charts, and dynamic SVG elements without installing packages or manually adding D3.js CDN links.
How to Use This D3.js Compiler
- Write or paste your D3.js code
Enter HTML and JavaScript in the Code Editor. You can use D3 selections, datasets, SVG elements, scales, axes, transitions, and other supported D3.js APIs. - Click the Run button
Select Run to execute your code using the pre-loaded D3.js environment. Edit your data or visualization logic and run it again to test changes quickly. - View the Output preview
Check your rendered chart, SVG, or data-driven interface in the Output preview screen. Use the available copy, download, or delete controls while experimenting with different visualizations.
Key Features
- Pre-Loaded D3.js Library: Start writing supported D3.js code without manually adding a CDN script.
- Zero Installation: No Node.js, npm, bundler, or local D3.js setup required for supported examples.
- SVG Rendering: Create circles, rectangles, lines, paths, text, and other SVG elements dynamically.
- Data Binding: Practice D3’s
data(),join(), and data-driven DOM manipulation. - Scales & Axes: Experiment with linear, band, time, and other supported scales.
- Interactive Visualizations: Test events, transitions, hover effects, and dynamic updates.
- DOM Selections: Use
d3.select()andd3.selectAll()to manipulate page elements. - Custom HTML & CSS: Combine D3.js visualizations with regular HTML and your own styling.
- Dark & Light Mode: Switch the Code Editor theme for comfortable development.
- Instant Visual Preview: Click Run and immediately inspect the generated visualization.
1. How do I create a bar chart or SVG elements using D3.js here?
Start with an HTML container:
Then create an SVG and bind data to rectangle elements:
const data = [40, 80, 55, 100, 70];
const width = 500;
const height = 250;
const svg = d3
.select("#chart")
.append("svg")
.attr("width", width)
.attr("height", height);
svg
.selectAll("rect")
.data(data)
.join("rect")
.attr("x", (d, i) => i * 90)
.attr("y", d => height - d * 2)
.attr("width", 60)
.attr("height", d => d * 2)
.attr("fill", "steelblue");
Click Run and the generated SVG bar chart will appear in the Output preview.
You can also create a basic SVG circle:
const svg = d3
.select("#chart")
.append("svg")
.attr("width", 300)
.attr("height", 200);
svg
.append("circle")
.attr("cx", 150)
.attr("cy", 100)
.attr("r", 60)
.attr("fill", "tomato");
2. Do I need to link the D3.js CDN manually in this compiler?
No. The playground is configured with D3.js library support, so supported D3 methods can be used without manually adding a CDN <script> tag.
For example:
d3
.select("#message")
.append("h2")
.text("Hello from D3.js!");
For production projects, you should still install or load the D3.js version required by your actual application.
3. Is this online compiler suitable for testing data-driven documents and selections?
Yes. It is useful for learning and testing D3’s core concept of binding data to DOM or SVG elements.
const languages = [
"JavaScript",
"Python",
"D3.js",
"React"
];
d3
.select("#languages")
.selectAll("li")
.data(languages)
.join("li")
.text(d => d);
D3 binds each array value to an <li> element and generates the list dynamically.
You can also update existing elements based on data:
const scores = [70, 85, 92];
d3
.select("#chart")
.selectAll("p")
.data(scores)
.join("p")
.text((d, i) => `Student ${i + 1}: ${d}`);
4. Can I bind data and manipulate DOM elements dynamically?
Yes. Data binding and dynamic DOM manipulation are central features of D3.js.
const products = [
{ name: "Product A", sales: 80 },
{ name: "Product B", sales: 120 },
{ name: "Product C", sales: 65 }
];
d3
.select("#chart")
.selectAll(".product")
.data(products)
.join("div")
.attr("class", "product")
.html(d => `
${d.name}
Sales: ${d.sales}
`);
You can also combine D3 with scales for data visualization:
const values = [10, 30, 50, 80, 100];
const scale = d3
.scaleLinear()
.domain([0, 100])
.range([0, 400]);
console.log(scale(50));
The Online D3.js Compiler / Playground is useful for frontend developers, data visualization engineers, analysts, and students who want to practice D3 selections, data binding, SVG graphics, scales, charts, and interactive visualizations without setting up a complete local project.