Apollo
Apollo

Reputation: 9054

appending d3.js canvas to div

I'm attempting to add a legend to a graph, and I want to append it to my chart div. Right now I'm using the following code, which appends the legend to the "body". I would like to instead append it to my "chart" div, so that I can create a footer after my legend. Right now the HTML page is processed first, and then my d3 javascript file gets run and therefore the legend gets placed below my footer. Thank you in advance.

 // Create the svg drawing canvas...
      var canvas = d3.select("body")
        .append("svg:svg")
          .attr("width", 300)//canvasWidth)
          .attr("height", 300);//canvasHeight);

Upvotes: 7

Views: 14598

Answers (1)

abhshkdz
abhshkdz

Reputation: 6365

The following works, like I pointed out in the comment.

var canvas = d3.select("#chart")
    .append("svg:svg")
      .attr("width", 300)//canvasWidth)
      .attr("height", 300);//canvasHeight);

Cheers :)

Upvotes: 18

Related Questions