javascript 将 d3.js 画布附加到 div
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11300059/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
appending d3.js canvas to div
提问by Apollo
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.
我正在尝试向图表添加图例,并且想将其附加到图表 div 中。现在我正在使用以下代码,它将图例附加到“正文”。我想将它附加到我的“图表”div,以便我可以在我的图例之后创建一个页脚。现在首先处理 HTML 页面,然后运行我的 d3 javascript 文件,因此图例被放置在我的页脚下方。先感谢您。
// Create the svg drawing canvas...
var canvas = d3.select("body")
.append("svg:svg")
.attr("width", 300)//canvasWidth)
.attr("height", 300);//canvasHeight);
回答by abhshkdz
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 :)
干杯:)