最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - appending d3.js canvas to div - Stack Overflow

programmeradmin3浏览0评论

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);

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);
Share Improve this question asked Jul 2, 2012 at 19:37 ApolloApollo 9,06433 gold badges110 silver badges193 bronze badges 2
  • 5 var canvas = d3.select("#chart"). Does this work? – abhshkdz Commented Jul 2, 2012 at 19:40
  • I tried that before without the #, hence it didn't work. Thanks a lot. – Apollo Commented Jul 2, 2012 at 20:01
Add a comment  | 

1 Answer 1

Reset to default 18

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 :)

发布评论

评论列表(0)

  1. 暂无评论