Chartjs-How I can use a list of a string array in JavaScript into blade view?

0👍

It looks like you’re wrapping the labels json in an extra set of brackets [].

Assuming dates2 is a normal array of strings, the @json template directive will output something that looks like this:

["2020-07-04","2020-07-05","2020-07-05","2020-07-01"]

Which means you should change your labels to:

labels:  @json($dates2, JSON_PRETTY_PRINT),

You can verify this by looking at the actual HTML source code of your page. The output should look like this:

labels: ["2020-07-04","2020-07-05","2020-07-05","2020-07-01"]

Leave a comment