Chartjs-How to show data from views on chartjs in django?

0👍

You should use for loop:

var ctx = document.getElementById('myChart').getContext('2d');
var myChart = new Chart(ctx, {
    type: 'bar',
    data: {
        labels: [
                {% for label in labels %} # Here!
                    "{{ label }}",
                {% endfor %}
                ],
        datasets: [{
            label: '# of Votes',
            data: [
                   {% for item1 in invoice_counter_complete_value5 %} # Here!
                      "{{ item1 }}",
                   {% endfor %}
            ],
            borderWidth: 1
        }]
    },
    options: {
        scales: {
            y: {
                beginAtZero: true
            }
        }
    }
});

Leave a comment