简体   繁体   English

d3; 将多个svg附加到div

[英]d3; attaching multiple svg to div's

Link to the jQuery / d3 code; 链接到jQuery / d3代码; Pastebin Pastebin

The problem is this. 问题是这样的。 I have two separate div's, #temp and #cpu. 我有两个单独的div,即#temp和#cpu。 I want to attach a graph to it with statistical information about the CPU load and about the temperature (it's a graph of the previous 100 hours). 我想给它附上一张图表,其中包含有关CPU负载和温度的统计信息(这是前100小时的图表)。

It should attach one SVG to one div. 它应将一个SVG附加到一格。 What it does now instead is it attaches the CPU thing correctly, but for the temperature, it adds an empty SVG to the #temp div and adds another SVG with the correct information to the CPU div. 现在,它执行的操作是正确地附加了CPU组件,但是对于温度,它向#temp div添加了一个空的SVG,并向CPU div添加了具有正确信息的另一个SVG。

Any help is welcome! 欢迎任何帮助!

You are assigning references to the SVGs to the same variable svga . 您正在将对SVG的引用分配给相同的变量svga After the SVGs have been created, you can only access one of them -- there's no variable for the other one. 创建SVG之后,您只能访问其中一个-另一个则没有变量。

You can solve this either by using different variables (eg svga and svgb ) or referencing the SVGs explicitly each time through something like d3.select("#cpu > svg") . 您可以使用不同的变量(例如svgasvgb )解决问题,也可以通过每次通过类似d3.select("#cpu > svg")类的d3.select("#cpu > svg")显式引用svgb来解决此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM