Note that there are some explanatory texts on larger screens.

plurals
  1. POCreate pie chart with HighCharts in Django error - Blank page
    primarykey
    data
    text
    <p>I'm trying to create a pie chart with highcharts with Django (with Mac Maverick), but I just get a blank page. Is there some error in my code below? My data consists of a dictionary with 2 keys (body and id__count), the loop inside it works perfectly in body tag. But it's not working in script tag.</p> <pre><code>&lt;script&gt; function numberWithCommas(x) { var parts = x.toString().split("."); parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ","); return parts.join("."); } $(function () { var chart; $(document).ready(function() { chart = new Highcharts.Chart({ chart: { renderTo: 'categoryPieChart' },title: { text: 'Category' },tooltip: { formatter: function() { return '&lt;b&gt;'+ this.point.name +'&lt;/b&gt;: '+ numberWithCommas(this.y.toFixed(2)); } },exporting: { enabled: false },plotOptions: { pie: { dataLabels: { enabled: true, formatter: function() { return '&lt;b&gt;'+ this.point.name +'&lt;/b&gt;: '+ Math.round(this.percentage) +' %'; } } } },series: [{ type: 'pie', data: [ {% for cat in responses_pie %} [ '{{ cat.body }}', {% if cat.id__count &gt; 0 %} {{ cat.id__count }} {% else %} 0 {% endif %} ], {% endfor %} ] }] }); }); }); }); &lt;/script&gt; </code></pre> <p>This is the view source on Chrome in the script tag:</p> <pre><code>function numberWithCommas(x) { var parts = x.toString().split("."); parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ","); return parts.join("."); } $(function () { var chart; $(document).ready(function() { chart = new Highcharts.Chart({ chart: { renderTo: 'categoryPieChart' },title: { text: 'Category' },tooltip: { formatter: function() { return '&lt;b&gt;'+ this.point.name +'&lt;/b&gt;: '+ numberWithCommas(this.y.toFixed(2)); } },exporting: { enabled: false },plotOptions: { pie: { dataLabels: { enabled: true, formatter: function() { return '&lt;b&gt;'+ this.point.name +'&lt;/b&gt;: '+ Math.round(this.percentage) +' %'; } } } },series: [{ type: 'pie', data: [ [ 'apple', 2 ], ] }] }); }); }); }); </code></pre> <p>And my view (views.py)</p> <pre><code>def piechart(request): responses_pie = AnswerRadio.objects.values("body").annotate(Count("id")) return render(request, 'chart_code_v2.html', {'responses_pie': responses_pie}) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload