q3 = {
const width = 400;
const height = 100;
const svg = d3
.create("svg")
.attr("width", width)
.attr("height", height)
.attr("viewBox", [0, 0, width, height]);
const rects = svg.selectAll("rect").data(dataset).join("rect");
rects.attr("x", (d, i) => i * 50).attr("width", 40);
if (fruit == "apple") {
rects
.attr("height", (d) => d.apple)
.attr("y", (d) => height - d.apple)
.attr("fill", "red");
} else if (fruit == "orange") {
rects
.attr("height", (d) => d.orange)
.attr("y", (d) => height - d.orange)
.attr("fill", "orange");
}
return svg.node();
}