对于 nvd3 / d3 中动态添加的 svg,图表不显示(仅显示文本)

chart does not show (only text shows up) for dynamic added svg in nvd3 / d3

我正在尝试为 nvd3

中的 svg 元素添加饼图

当元素在 html 中时有效,但在 jquery 中添加时无效。

比较workingnot working

根据 this bug,这似乎是 css 冲突。

在这种情况下,可以通过使用 D3 插入 SVG 而不是 jQuery 来解决问题。本质上,D3 可以完成 jQuery 所做的大部分事情,因此没有必要使用它。

将您的 jQuery 代码替换为:

d3.select('#container').append('svg').attr('id', 'svg2');