Chartjs-How to foreach datasets in chartjs laravel

0👍

You can do it by using a @foreach ... @endforeach in blade.

...
datasets: [
    @foreach ($contacts as $contact)
    {
        label: {{ json_encode($contact->name) }},
        data: {{ json_encode($contact->data) }}
    }
    @endforeach
],
...

$contact->name should be a string like 'FirstName'.
$contact->data should be an array like [1,2,3,4].

Leave a comment