【发布时间】:2017-03-27 08:41:41
【问题描述】:
我正在显示一个图表,其中过去的数据由条形(观察)表示,未来的数据由一条线(预测)表示。这些是 2 组独立的数据。
x 轴使用日期,y 轴使用浮点值。
我的问题是,例如,过去的预测线有一个洞。观察的第一个数据是 5 天前。因此,从这个日期到现在,我没有预测值。如果我什么都不做,线条将延伸到整个图表。
我通过迭代所有观察数据并仅将数据推送到预测来手动添加了一些假数据。
.push({ date: observations.date })
我的问题是我仍然看到带有NaN 的这些数据的工具提示
这是图表的选项
chart: {
type: "linePlusBarChart",
focusEnable: false,
margin: {
top: 50,
right: 50,
bottom: 30,
left: 70
},
xAxis: {
staggerLabels: true,
tickFormat: function(d) {
return dateFormat(new Date(d));
},
showMaxMin: false
},
y1Axis: {
tickFormat: function(d) {
return d3.format('.02f')(d);
}
},
y2Axis: {
tickFormat: function(d) {
return d3.format('.02f')(d);
}
},
bars: {
forceY: [0]
},
lines: {
forceY: [0]
},
x: function(d) {
return d.date.millis;
},
y: function(d) {
return d.value;
},
duration: 500
}
如何隐藏这些工具提示?还有其他方法可以填补这些数据漏洞吗?
编辑
我也尝试添加{ date: observations.date, value : null },但它会在底部显示带有0 值的行。
编辑 2
我也试过改y函数
y: function(d) {
if(d.value === undefined) return null;
return d.value;
}
但我有同样的问题
【问题讨论】:
标签: javascript d3.js nvd3.js angular-nvd3