First time poster, long time reader. I\'ve spend quite awhile looking for an answer to this, which makes me think its something fundamental I\'m missing.
I\'m tryin
I finally got my plotting working. I found this approach here. Thanks to Harrison for posting his method!
My new views.py based on the above approach:
def plot(request, chartID = 'chart_ID', chart_type = 'line', chart_height = 500):
data = ChartData.check_valve_data()
chart = {"renderTo": chartID, "type": chart_type, "height": chart_height,}
title = {"text": 'Check Valve Data'}
xAxis = {"title": {"text": 'Serial Number'}, "categories": data['serial numbers']}
yAxis = {"title": {"text": 'Data'}}
series = [
{"name": 'Mass (kg)', "data": data['mass']},
{"name": 'Pressure Drop (psid)', "data": data['pressure drop']},
{"name": 'Cracking Pressure (psid)', "data": data['cracking pressure']}
]
return render(request, 'unit/data_plot.html', {'chartID': chartID, 'chart': chart,
'series': series, 'title': title,
'xAxis': xAxis, 'yAxis': yAxis})
Quick function for pulling database objects and passing the data:
class ChartData(object):
def check_valve_data():
data = {'serial numbers': [], 'mass': [],
'pressure drop': [], 'cracking pressure': [], 'reseat pressure': []}
valves = CheckValve.objects.all()
for unit in valves:
data['serial numbers'].append(unit.serial_number)
data['mass'].append(unit.mass)
data['cracking pressure'].append(unit.cracking_pressure)
data['pressure drop'].append(unit.pressure_drop)
data['reseat pressure'].append(unit.reseat_pressure)
return data
The key to Harrison's method is a mapping script to translate the Highcharts js to Python template variables:
{% extends "base.html" %}
{% block extrahead %}
{% endblock %}
{% block heading %}
Analysis
{% endblock %}
{% block content %}
{% endblock %}
{% block overwrite %}
{% endblock %}
{% block extrajs %}
{% endblock %}
Everything works and displays correctly now!