Public
Edited
Jun 5, 2024
Insert cell
Insert cell
Insert cell
chart1 = {
const svg = d3
.create("svg")
.attr("viewBox", [0, 0, width, height])
.style("overflow", "visible");

//Scatter plot with transitions
svg
.append("g")
.selectAll("circle")
.data(data)
.join("circle")
.attr("cx", (d) => scale.x(d.danceability))
.style("fill", (d) => scale.c(d.danceability))
.style("opacity", 0.5)
.attr("r", 0)
.attr("cy", 10)
.transition()
.duration(1)
.delay((d, i) => i * 0.2)
.attr("r", 1.8)
.attr("cy", (d) => scale.y(d[Channel]));

//Call the axes
svg.append("g").call(xAxis);
svg.append("g").call(yAxis);

//Add some general titles to the axes
svg
.append("g")
.attr("transform", `translate(${width / 2}, ${height - 5})`)
.append("text")
.style("text-anchor", "middle")
.text("danceability")
.attr("class", "x_text");

svg
.append("g")
.attr("transform", `translate(${margin.left}, ${height / 2})rotate(-90)`)
.append("text")
.style("text-anchor", "middle")
.text(Channel)
.attr("class", "y_text");

return svg.node();
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more