[Answer]-Django jquery flot chart multiple series


You can encode your data in json:

from django.utils import simplejson as json

data_all_days = [
   {'label': 'Day 1',
    'data': [[1, 4], [1,8], [9, 8]],
    'color': '#000',
   {'label': 'Day 2',
    'color': ...,
render_to_response( ... {'charts': json.dumps(data_all_days)})

and in the template just use the json as javascript code:

var chart_data = {{ charts|safe }};

$.plot($('#site_statistics'), chart_data);

You’ll have the structure of data_all_days in your js code and will parse it with a cycle.
Read on jquery.each.

While running this code, open it in Chrome or FireFox and open developer tools (Ctrl+I or F12) and see the debug console, it will show if there are errors in the JavaScript.

|safe is a template filter to prevent code from being html-quoted.

Leave a comment