我使用 nvd3 有用的预打包图表制作了一个堆积折线图。
我的图表可以很好地完成大部分功能,但每当我单击特定系列时,都会出现错误“未捕获类型错误:无法读取未定义的属性“y””,并且图表不会调整大小以仅显示该系列.
有关正确功能的示例:http://nvd3.org/examples/stackedArea.html
我检查了最常见的错误,包括不同大小的系列,但都不是。
我用来生成图表的代码是:
function stackedChart(data) {
nv.addGraph(function() {
var chart = nv.models.stackedAreaChart()
.margin({right: 100})
.x(function(d) { return d[0] })
.y(function(d) { return d[1] })
.useInteractiveGuideline(true)
.duration(500)
.showControls(true)
.clipEdge(true);
chart.xAxis
.tickFormat(d3.format(',.0f'));
chart.yAxis
.tickFormat(d3.format(',.2f'));
d3.select('#stackedChart svg')
.datum(data)
.transition().duration(500).call(chart);
nv.utils.windowResize(chart.update);
return chart;
});
}
stackedChart(a);
使用 jsfiddle 中找到的数据以及错误的实时示例:https://jsfiddle.net/0yxr15ut/5/
最佳答案
此问题已在此处得到解决: https://github.com/novus/nvd3/issues/1093 尽管不确定副作用,但可以解决此问题。 在 nv.d3.js 的 scatter y 函数中添加以下检查
.y(function(d) {
if (d.display !== undefined) { return d.display.y + d.display.y0; }
else return 0
})
我已经创建了一个 for 存储库,其中包含您可以使用的更改。 https://github.com/nishantk92/nvd3.git
关于javascript - 未捕获的类型错误 : Cannot read property 'y' of undefined in NV D3 StackedLine,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32076356/