Django Flot e javascript

Django Flot e javascript,javascript,django,flot,Javascript,Django,Flot,我想在django应用程序中绘制一些图形。我用的是Flot。我是javascript方面的新手,我不知道在我的情况下如何传递参数。这是我的代码: view.py data = [] query = tab_data.objects.all() for row in query: data.append([str(row.time), str(row.rate)]) data = json.dumps(data, cls=DjangoJSONEncoder) ... return rend

我想在django应用程序中绘制一些图形。我用的是Flot。我是javascript方面的新手,我不知道在我的情况下如何传递参数。这是我的代码:

view.py

data = []
query = tab_data.objects.all()
for row in query:
    data.append([str(row.time), str(row.rate)])
data = json.dumps(data, cls=DjangoJSONEncoder)
...
return render_to_response('index.html', {'data' : data}, context_instance=RequestContext(request))
index.html

<div class="portlet-body">
       <div id="site_statistics_loading">
           <img src="/static/assets/img/loading.gif" alt="loading" />
       </div>
       <div id="site_statistics_content" class="hide">
            <div id="site_statistics" class="chart"></div>
       </div>
</div>
...
... # at the end of the page I have this
Index.initCharts(); // init index page's custom scripts

如何将数据传递到index.js文件?对不起,这个琐碎的问题,但我不知道怎么办。。。感谢

序列可以是原始数据,也可以是具有属性的对象。生的 数据格式是点的数组:

[[x1,y1],[x2,y2],…]

例如(就你而言)

如果您想要一些更复杂的(例如线条和圆点中的样式),您必须构建基本上构建“option”参数

$.plot(placeholder, data, options);
占位符是将包含图形的div容器。 数据是前面描述的格式的数据。(注意字符串构建) 选项是图形的选项(线、系列、样式、点)


您将在这里找到更多信息

问题是另一个。我不知道如何将{{data}}传递到index.js文件。我要做的是:index.initCharts(“{data}”);我不知道如何在我的index.js中填充变量var data=[];在index.js中,您必须使用Ajax来完成,但您可以在HTML文件中这样做(仅加载一次):数据={%generate your data in the server side here%};
data=   [[1, 3], [2, 14.01], [3.5, 3.14]];   //You can build this string in the html generated and/or add it with jquery/ajax callback function.
$.plot(placeholder, data, options);