Chartjs-ChartJS or/and php print_r not working together

0๐Ÿ‘

โœ…

You can simply use implode() function to print your array data,

 labels : [ 
       {{implode(",", $action_names)}}
    ]

&

 data : [
      {{implode(",", $action_count)}}
    ]

0๐Ÿ‘

you canโ€™t to put a php function like this

labels  : {{print_r($action_names, true)}}
...
data: {{print_r($action_count,true)}}

try to isolate in a var

labels  : { {$action_names} }
...
data: { {$action_count} }

0๐Ÿ‘

When you want to use the data in a script or something like that, you have to escape it, basically donโ€™t use {{something}} but use {!!something!!}

0๐Ÿ‘

Define new javascript array from existing php array using following syntax:

var labelValues = [<?php echo '"'.implode('","', $php_array).'"' ?>];

Leave a comment