I have a PHP array with this content:
[{"label":"Baden-Wuerttemberg","year":"1998","ins":"243812"}...] (34 entries).
Now I want to plot a chart with Chart.js in JS, but I don't know how to get the values for Labels and dataset.
This is what I have tried:
var jsArray = <?php echo json_encode($jsonArray); ?>;
var chart = new CanvasJS.Chart("chartContainer", {
title: {
text: "My First Chart in CanvasJS"
},
type: 'line',
data: {
datasets: jsArray
},
});
chart.render();
}
I want to plot on the x axis the year Jahr and on the y axis the total number ins.
JSON.parse('<?=$jsonArray;?>? - The example you provided, is alreadyjson encoded, just pass it to js. When you ask a question about an error ALWAYS include the error log. Adderror_reporting(E_ALL); ini_set('display_errors', 1);at the top of yourphpscript, what does it return?JSON.parse('<?=$jsonArray;?>and the error reporting.