如何隐藏错误的值? (0、空或未定义)
我尝试过做类似的事情
new Chart(this.barCanvas.nativeElement, {
...
data: {
datasets: [{
data: [
value < 1 ? null : value,
value2 < 1 ? null : value2,
valueX < 1 ? null : valueX,
],
}],
},
options: {
skipNull: true,
}
...
}
但这不起作用。
我在 SOF 上发现了一些类似的帖子,但没有答案或工作解决方案
受 LeeLenalee 答案和 Zhulien 评论的启发,我创建了一个变量chartData
我在通过之前进行过滤。
但是传递变量chartData
出现类型错误data
(复制过去的对象chartData
并且直接传递它不会产生类型错误,但图形的视图不会加载)
indexToRemove
是一个基于0的数据的索引数组
var chartData = {
labels: ['Batterie faible', 'Maintenance', 'HS', 'Place libre', 'Place occupée'].filter((v, i) => indexToRemove.includes(i)),
datasets: [{
label: '',
data: data.filter((v, i) => indexToRemove.includes(i)),
backgroundColor: [
'#F6741A',
'#dc2625',
'#B91C1B',
'#22c55e',
'#FACC14'
].filter((v, i) => indexToRemove.includes(i)),
borderRadius: 4,
borderSkipped: false,
}]
}
new Chart(this.barCanvas.nativeElement, {
type: 'bar',
data: chartData, // <- Type error (But replacing by the object correct the type error but still does not work as said above)
...
}