umair
how to add percentage % in pie chart
@Bezhan #pie-chart-table-column
$totalOrders = DB::table('orders')
->whereNotNull('order_source')
->count();
$ordersBySource = DB::table('orders')
->select('order_source', DB::raw('COUNT(*) as count'))
->whereNotNull('order_source')
->groupBy('order_source')
->pluck('count', 'order_source')
->toArray();
$ordersWithPercentage = [];
foreach ($ordersBySource as $source => $count) {
$percentage = ($count / $totalOrders) * 100;
$ordersWithPercentage[$source] = $percentage;
}
return [
'datasets' => [
[
'label' => 'Order Sources',
'data' => array_values($ordersWithPercentage),
'backgroundColor' => [
'rgb(255, 99, 132)',
'rgb(54, 162, 235)',
'rgb(255, 205, 86)'
],
],
],
'labels' => array_keys($ordersWithPercentage),
];
here i also tried to attached percentage symbol but code i not working
1 replies