gpt4 book ai didi

javascript - 图表中的 nvd3 数据漏洞

转载 作者:行者123 更新时间:2023-12-03 04:45:15 24 4
gpt4 key购买 nike

我正在显示一个图表,其中过去的数据由条形图(观察值)表示, future 的数据由线条(预测)表示。这是两组独立的数据。

x 轴使用日期,y 轴使用浮点值。

我的问题是,例如,过去的预测线有一个漏洞。第一个观测数据是 5 天前。因此,从今天到现在,我没有预测值。如果我什么都不做,线条将延伸到整个图表。

我通过迭代所有观测数据并仅将数据推送到预测来手动添加一些数据。

.push({ date: observations.date })

我的问题是,我仍然看到带有 NaN 的数据的工具提示

chart

这是图表的选项

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;
}

但是我也有同样的问题

最佳答案

只需使用工具提示 valueFormatter 来处理 NaN 值。例如这就是我在类似情况下所做的事情。

  multiChart.interactiveLayer.tooltip.valueFormatter((value, i, datum) => {
if (
datum.key === keyForActualGreaterThanPredicted ||
datum.key === keyForActualLessThanPredicted
) {
const diff = Math.abs(datum.data.y0 - datum.data.y1);
if (diff === 0) {
return '-';
}
return diff;
}
return value;
});

关于javascript - 图表中的 nvd3 数据漏洞,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42898347/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com