javascriptd3.js

D3.js: what is 'g' in .append("g") D3.js code?


I am new to D3.js, started learning today only

I looked the the donut example and found this code

var svg = d3.select("body").append("svg")
    .attr("width", width)
    .attr("height", height)
  .append("g")
    .attr("transform", "translate(" + width / 2 + "," + height / 2 + ")");

I searched for documentation, but did not understood what .append("g") is appending

Is it even D3 specific?

Looking for guidance here


Solution

  • It appends a 'g' element to the SVG. g element is used to group SVG shapes together, so no it's not d3 specific.