add percentage to y-axis tooltip

This commit is contained in:
hackerESQ
2024-08-06 23:30:11 -05:00
parent af66d83f9b
commit 6d12912dd0
@@ -69,6 +69,7 @@
'legend' => [
'show' => false,
],
], $seriesData);
$seriesData = json_encode($seriesData)
@endphp
@@ -89,6 +90,18 @@
}
}
this.data.tooltip = {
enabled: true,
y: {
formatter: (value, { series, seriesIndex, dataPointIndex, w }) => {
const firstDataPoint = this.data.series[seriesIndex].data[1][1]
const percentageChange = ((value - firstDataPoint) / firstDataPoint) * 100;
return `${value} (${percentageChange.toFixed(2)}%)`;
}
},
}
var chart = new ApexCharts(document.querySelector('#chart-{{ $name }}'), this.data);
chart.render();