Chartjs-Chart.js how to add labels to plot

0👍

The quotation marks within the label declaration are escaped, hence the error message with the ‘&’.
To pass data to JavaScript within jinja I recommend the filter tojson.

<script>
    const data = {
        labels: {{ labels | tojson }},
        datasets: [{
            label: 'My First Dataset',
            data: {{ data | tojson }},
        }],
    };
    const config = {
        type: 'line',
        data: data,
        options: {
            // ...
        }
    };
    const myChart = new Chart(
        document.getElementById('myChart'),
        config
    );
</script>

Leave a comment