[Chartjs]-HTML/Chart JS deserialize JSON from Python Flask

2👍

Apply the tojson filter to object_returned:

var myChart = new Chart(ctx, {
    type: 'line',
    data: "{{ object_returned|tojson|safe }}",
    ...

0👍

The python returned data is class type ‘dict’ instead of making it a json.

Make it a json inside the HTML/Java by:

var myVariable = {{ object_returned | tojson }};

The quotation marks were removed as it makes it a string.

and finally:

var ctx = document.getElementById("myChart").getContext('2d');
var myChart = new Chart(ctx, {
    type: 'line',
    data: myVariable,

Leave a comment