app/Http/Controllers/Admin/Charts/ProductsChartController.php
/**
     * Respond to AJAX calls with all the chart data points.
     *
     * @return json
     */
Respond to AJAX calls with all the chart data points.
@return json
Respond to AJAX calls with all the chart data points . @return json
public function data()
    {
        $number = array();
        $count = 0;
        $names = DB::table('products')->select('name')->get();
        for ($i=0; $i < count($names); $i++) { 
            $number[] = $names[$i]->name;
        }
        $number = array_count_values($number);
        $num = array();
        foreach ($number as $key => $value) {
            $num[] = $value;
        }
         $this->chart->dataset('Products', 'pie', $num)
            ->color('rgba(215, 32, 28, 12)')
            ->backgroundColor('rgba(205, 32, 31, 0.4)');
    }
public function data ( ) { $ number = array ( ) ; $ count = 0 ; $ names = DB :: table ( 'products' ) -> select ( 'name' ) -> get ( ) ; for ( $ i = 0 ; $ i < count ( $ names ) ; $ i ++ ) { $ number [ ] = $ names [ $ i ] -> name ; } $ number = array_count_values ( $ number ) ; $ num = array ( ) ; foreach ( $ number as $ key => $ value ) { $ num [ ] = $ value ; } $ this -> chart -> dataset ( 'Products' , 'pie' , $ num ) -> color ( 'rgba(215, 32, 28, 12)' ) -> backgroundColor ( 'rgba(205, 32, 31, 0.4)' ) ; }
Respond to AJAX calls with all the chart data points.
Respond to AJAX calls with all the chart data points .
// $names = DB::table('products')->distinct('name')->count('name');