本文介绍了无法选择 <linearGradient>在 Chrome 中使用 D3.js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Chrome 不会使用 D3.js 选择 .在下面的代码中,所有选择都是空的.
Chrome doesn't select <linearGradient>
with D3.js. In the following code all selections are empty.
var defs = d3.select("body").append("svg").append("defs");
defs.append("linearGradient");
defs.append("linearGradient");
console.log(defs.selectAll("linearGradient")); // empty
console.log(defs.selectAll("lineargradient")); // empty
console.log(d3.selectAll("linearGradient")); // empty
如果你用 替换
就可以了.
If you replace <linearGradient>
with say <mask>
it's all right.
var defs = d3.select("body").append("svg").append("defs");
defs.append("mask");
defs.append("mask");
console.log(defs.selectAll("mask")); // 2 elements selected
Firefox 对两者都适用.我正在使用 Chrome 28.0.1500.95.请提出一种选择渐变的方法.
Firefox works fine for both. I'm using Chrome 28.0.1500.95. Please suggest a way to select the gradients.
推荐答案
这是 webkit 中的一个错误 -- 请参阅 错误报告.简短的回答是因为它刚刚坏了.您可以通过保留对需要修改的渐变的显式引用来解决此问题,例如
This is a bug in webkit -- see the bug report. The short answer is that for it's just broken. You may be able to work around this by keeping explicit references to the gradients you need to modify, e.g.
var grad1 = defs.append("linearGradient");
这篇关于无法选择 <linearGradient>在 Chrome 中使用 D3.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!