1๐
โ
You can check if val exists using if statements
datalabels: {
formatter: (val, context) => {
if(val) return `${val}%`
return;
},
}, //
1๐
If you just want to show 0 in case of undefined (or any falsy statement) you can use the ||
operator.
datalabels: {
formatter: (val, context) => `${val || 0}%`,
}
1๐
The problem seems to be this line: return ((value / this.max) * 100).toFixed(0) + "%";
Something in there, probably the value
is undefined
or so. You can display nothing conditionally with e.g. return value ? ((value / this.max) * 100).toFixed(0) + "%" : null;
Source:stackexchange.com