chart = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width + 100, height]);
svg.append("text")
.attr("text-anchor", "middle")
.attr("x", width / 2)
.attr("y", height + margin.bottom - 10)
.text("X Axis Label");
svg.append("text")
.attr("text-anchor", "middle")
.attr("transform", "rotate(-90)")
.attr("x", -height / 2)
.attr("y", -margin.left + 10)
.text("Y Axis Label");
const movies = svg
.append("g")
.selectAll("circle")
.data(movieData, (d) => d.index)
.join("circle")
.attr("cx", d => x(d.release_year))
.attr("cy", d => y(d.imdb_score))
.attr("r", 4)
.style("fill", d => color(d.age_certification));
svg.append('g').call(xAxis);
svg.append('g').call(yAxis);
svg.append("text")
.attr("class", "x label")
.attr("text-anchor", "end")
.attr("x", width / 2)
.attr("y", height)
.text("Release Year");
svg.append("text")
.attr("class", "y label")
.attr("text-anchor", "end")
.attr("y", 6)
.attr("x", - height / 3)
.attr("dy", ".3em")
.attr("transform", "rotate(-90)")
.text("IMDB Rating");
movies
.append("title")
.text(d => `Title: ${d.title}
Genre(s): ${d.genres.replaceAll("'", "")}
Age Rating: ${d.age_certification}
IMDB Rating: ${d.imdb_score}
Runtime: ${d.runtime} minutes
Year Released: ${d.release_year}`);
movies
.on('mouseover', function() {
d3.select(this).attr('stroke', '#000').attr('stroke-width', 1.5);
})
.on('mouseout', function() {
d3.select(this).attr('stroke', null);
});
svg
.append("g")
.attr("transform", `translate(${width - 25}, 10)`)
.call((d) => colorLegend(d))
return svg.node()
}