Attempting to troubleshoot a basic example of django-graphos using the provided code. However, I'm encountering an error message in Chrome Inspector saying 'Uncaught ReferenceError $ is not defined', with a red dot indicating the issue right after $(function () { - and no graph is displayed. Despite this, it appears that the template is being generated correctly, as indicated in the inspector output below.
Chrome Inspector Output:
<html>
<h1>- Django-graphos Chart 1 - </h1>
<head>
<script type = "text/javascript" src = "js/jquery-1.11.2.js"></script>
<script src = "js/flot/jquery.flot.js"></script>
<div id="xlZGoSiTTr" style="width:800px;height:400px;"></div>
<script type="text/javascript">
$(function () {
$.plot(
$("#xlZGoSiTTr"),
[{"data": [["2004", 1000], ["2005", 1170], ["2006", 660], ["2007", 1030]], "label": "Sales"}, {"data": [["2004", 400], ["2005", 460], ["2006", 1120], ["2007", 540]], "label": "Expenses"}],
{"series": {"lines": {"show": "true"}}, "legend": {"position": "ne"}, "title": "Chart"}
);
});
</script>
</head>
<body>
<div id="container"></div>
</body>
</html>
views.py:
from django.shortcuts import render
from django.http import HttpResponse
from django.template import RequestContext, loader
from graphos.sources.simple import SimpleDataSource
from graphos.renderers import flot
from django.shortcuts import render_to_response
def do_graph(request):
# get data
data = [
['Year', 'Sales', 'Expenses'],
['2004', 1000, 400],
['2005', 1170, 460],
['2006', 660, 1120],
['2007', 1030, 540]
]
chart = flot.LineChart(SimpleDataSource(data=data))
#context = RequestContext( request, `enter code here`{'chart':chart.as_html(),'data':data})
#template = loader.get_template('chart.html')
#return HttpResponse(template.render(context))
#return render(request, 'chart.html')
return render_to_response('chart.html', {'chart': chart})
chart.html:
<html>
<h1>- Django-graphos Chart 1 - </h1>
<head>
<script type = "text/javascript" src = "{{ STATIC_URL }}js/jquery-1.11.2.js"></script>
<script type = "text/javascript" src = "{{ STATIC_URL }}js/flot/jquery.flot.js"></script>
{{chart.as_html}}
</head>
<body>
<div id="container"></div>
</body>
</html>
The two JS files appear to be loading successfully with a status 200 response from the Django server. Any suggestions for resolving this issue with django-graphos would be highly appreciated. Thank you, Ron.