I am using the apexcharts to generate a "donut". If I move the cursor over an element it will sho me the value of this element:
My code for this:
plotOptions: {
pie: {
donut: {
labels: {
show: true,
value: {
formatter: function (val) {
return val;
}
}
}
}
}
}
But how can I show the percent value of the element instead of the "normal value"?
I think the only way is to calculate percentages yourself
formatter: function (val,chart) {
if(val){
let valPercent = val/chart.config.series.reduce((a, b) => a + b, 0)*100;
return `${valPercent.toFixed(1)}%`; // or round with Math
}
return ''
}
Actualy there is array with percentage values chart.globals.seriesPercent
but no seriesIndex
is provided