Need help with D3

I am trying to learn how to use Observable, so I just wanted to create a simple using below code but it is not working.

chart = {
var svg = d3.select(DOM.svg(800,800)).append(“circle”).attr(“r”,20).attr(“cx”,10).attr(“cy”,10).attr(“fill”,“black”);
return svg.node() ;
}

selection.append returns a selection of the appended elements, so you’ve defined svg as a selection of a single circle element rather than an SVG element. Try this:

{
  const svg = d3.select(DOM.svg(800, 800));

  svg.append("circle")
      .attr("r", 20)
      .attr("cx", 10)
      .attr("cy", 10)
      .attr("fill", "black");

  return svg.node();
}
1 Like