fxcosta / laravel-chartjs

Simple package to facilitate and automate the use of charts in Laravel 5.x using Chartjs v2 library
486 stars 112 forks source link

Is this code wrong ? #69

Open manounou opened 6 years ago

manounou commented 6 years ago

Hi, Im trying to display Nombre of customers by agent in a doughnut but it display me all agent in one doughnut

here is my code please can you show me my mistake ?

`$agent = User::where('role','=','agent')->pluck('username')->toArray(); $agents = implode(', ', $agent);

       $customerbyagent = app()->chartjs
            ->name('CustomerByAgent')
            ->type('doughnut')
            ->labels([$agents])
            ->datasets([
                [
                   'backgroundColor' => ['#ff6384'],
                  'data' => [10,12]
                ]
            ])
            ->options([]);`

In the render Javascript it display this

labels: ["Agent constantine\", \"Agent Alger"],

wells commented 6 years ago

@manounou do not implode your array of agent names (nombres) into a single string.

Instead, pass $agent->toArray() into the labels() function for this library. You'll instead get labels: [ "Agent Constantine", "Agent Alger" ], in the JS frontend.