Django show Graphs with ChartJS
<p>I need to do a graph with ChartJs from my Expenses.</p>

<p>This is my view </p>

<pre><code>@login_required
def index(request):
    truncate_month = connection.ops.date_trunc_sql('month', 'date_reg')
    expense = Expense.objects.extra({'month': truncate_month}).values('month').annotate(Sum('total_amount'))
    return render(request, 'home/index.html', {"expense": expense})
</code></pre>

<p>On my template </p>

<pre><code>{{ expense }}
</code></pre>

<p>And It shows the data in the following format:</p>

<pre><code>[{
   'month': '2015-12-01',
   'total_amount__sum': 900.0
}, {
   'month': '2016-01-01',
   'total_amount__sum': 19334.0
}] 
</code></pre>

<p>How can I format that data to be compatible with chartjs?</p>

<p>ChartJs Example:</p>

<pre><code>labels: ["January", "February", "March", "April", "May", "June", "July"], //Here the month
datasets: [{
        label: "My First dataset",
        fillColor: "rgba(220,220,220,0.2)",
        strokeColor: "rgba(220,220,220,1)",
        pointColor: "rgba(220,220,220,1)",
        pointStrokeColor: "#fff",
        pointHighlightFill: "#fff",
        pointHighlightStroke: "rgba(220,220,220,1)",
        data: [65, 59, 80, 81, 56, 55, 40] //here 'total_amount__sum'
    },
    ...
</code></pre>