[Django]-Django – can't get highchart to display data

3👍

A few issues:

You need quote marks around the chart ID template variable to make it an HTML attribute:

<div id="{{ chartID|safe }}" ...

You’re not passing in a valid JQuery selector: to select the above div you should use $("#chart_ID") (see JQuery selectors), so with your Django template variable for example:

$("#{{ chartID|safe }}")

Also the data appears to need a series key to render (I haven’t used highcharts much but see here – your chart renders when this is added):

https://www.highcharts.com/docs/getting-started/your-first-chart

Also the ChartData class doesn’t belong in your views.py file – only HTTP request/responses belong there. I recommend working through the official Django tutorial if you haven’t already to get an idea of the “Django way” to do things. For example, your ChartData method produces a list of member_nos, but you can do this with a single line of code 🙂

Member.objects.values_list('member_no', flat=True)

Leave a comment