Chartjs-How to use a string returned from php by ajax as data for a chart.js chart?

0👍

try

data: val.dataset.data 

rather than

data: val

It appears you’re just popping the entire json into the val field, rather than isolating the data portion needed for plotting

0👍

The problem was that the response from php was actually a string. Chart() requires data to be an object, so constructing an array in php with relevant data and using json_encode() allowed the data property to be filled with values from the server.

Leave a comment