2

What's the most elegant solution in Django to take data from database and pass it into Highcharts? I stumbled across this question, but I keep on getting the following error: JSerror: Invalid property id at var chart_id = {{ chartID|safe }}, if I try to use it in my example.

template looks like this:

<html>
<div id={{ chartID|safe }} class="chart" style="height: 100px; width: 500px"></div>
<script>
var chart_id = {{ chartID|safe }}
var series = {{ series|safe }}
var title = {{ title|safe }}
var xAxis = {{ xAxis|safe }}
var yAxis = {{ yAxis|safe }}
var chart = {{ chart|safe }}
</script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>

In case there are better ways to pass data to highcharts please let me know.

2 Answers 2

3

Maybe you are missing the quotes in your javascript:

var chart_id = "{{ chartID|safe }}";
Sign up to request clarification or add additional context in comments.

Comments

0

You must pass your data as a context to the template, change it to a list in python. Then in your javascript block create a script tag then declare your data variables that you passed ,then pass them to your plotting script.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.