How to hide values that are false ? ( 0, null or undefined)
I have tried to do something like
new Chart(this.barCanvas.nativeElement, {
...
data: {
datasets: [{
data: [
value < 1 ? null : value,
value2 < 1 ? null : value2,
valueX < 1 ? null : valueX,
],
}],
},
options: {
skipNull: true,
}
...
}
But it doesn't work.
I've found some similar post on SOF with no answers or working solution
Inspired on LeeLenalee answer and zhulien comment I have created a variable chartData
that I filter before passing it.
But passing the variable chartData
make a type error on data
(to copy past the object of chartData
and passing it directly does not make a type error, but the view of the graph does not load)
indexToRemove
is an array of index based on data that are to 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)
...
}