31 lines
No EOL
654 B
JavaScript
31 lines
No EOL
654 B
JavaScript
// Basic D3 Script
|
|
|
|
// Create an SVG container
|
|
const svg = d3.select("body")
|
|
.append("svg")
|
|
.attr("width", 500)
|
|
.attr("height", 500);
|
|
|
|
// Add a circle to the SVG
|
|
svg.append("circle")
|
|
.attr("cx", 250)
|
|
.attr("cy", 250)
|
|
.attr("r", 50)
|
|
.attr("fill", "blue");
|
|
|
|
// Add a rectangle to the SVG
|
|
svg.append("rect")
|
|
.attr("x", 200)
|
|
.attr("y", 300)
|
|
.attr("width", 100)
|
|
.attr("height", 50)
|
|
.attr("fill", "green");
|
|
|
|
// Add some text to the SVG
|
|
svg.append("text")
|
|
.attr("x", 250)
|
|
.attr("y", 100)
|
|
.attr("text-anchor", "middle")
|
|
.attr("font-size", "20px")
|
|
.attr("fill", "black")
|
|
.text("Hello, D3!"); |