在我的开发工作中,我遇到一个非常奇怪的问题,请帮助我
输入是非常简单的数组,但是d3无法识别数据
环境是:Chrome 74 win64,d3-5.9.2
let tmpData = [[15.5, 4.8, 0.0, 1.0], [10.18, 4.8, 0.0, 1.0], [1.8, 8.9, 0.0, 1.0], [0, 15, 0.0, 1.0], [0, 22, 0.0, 1.0]]
console.log(typeof tmpData[0][1]) // you can see it's number
let lineGenerator = d3.line()
.x((d) => (d[0]))
.y((d) => (d[1]))
.curve(d3.curveLinear)
let tmp = lineGenerator(tmpData)
console.log(tmp)
最终输出是
Error: <path> attribute d: Expected number, "MNaN,NaNLNaN,NaNL…".
但是我想要的是
M15.5,4.8L10.18,4.8L ...
然后我可以将其绑定到SVG元素的“ d”属性