admin管理员组文章数量:1277401
It seems all the D3 example graphs take an external .csv or .tsv file as input data. Is there any way to modify the code to take data from a variable in Django. Suppose {{ data }} is in JSON format, how do you implement this in a graph such as or ? I'm trying to avoid always writing a .csv file.
It seems all the D3 example graphs take an external .csv or .tsv file as input data. Is there any way to modify the code to take data from a variable in Django. Suppose {{ data }} is in JSON format, how do you implement this in a graph such as http://bl.ocks/3885304 or http://bl.ocks/3887051 ? I'm trying to avoid always writing a .csv file.
Share Improve this question asked Nov 8, 2012 at 16:23 onoono 3,10410 gold badges45 silver badges88 bronze badges 3- 1 github./mbostock/d3/wiki/Requests#wiki-d3_json – Martin Commented Nov 8, 2012 at 16:34
- If I'm using d3.json, what is the URL and callback? – ono Commented Nov 8, 2012 at 16:40
- I misunderstood your question, I thought you wanted to serve it as json using http. See my answer for details. – Martin Commented Nov 8, 2012 at 17:05
2 Answers
Reset to default 6You can always make a view which will serve dynamic csv file which will be consumed by D3. This way will also allow users to download the data in case they need the raw data instead of a graph.
def foo(request, ...):
model = get_object_or_404(Foo, ...)
data = model.get_data() # should return csv formatted string
return HttpResponse(data, content_type='text/csv')
Instead of loading data asynchronously (ajax-style), you can use correctly formatted JSON in a string passed to your template tag variable and |safe
d.
Check out the working example http://bl.ocks/4040034 which is based on http://bl.ocks/3885304
You should also check out the related questions on SO, there are tons on the subject.
本文标签: javascriptDirect data input from Django for a D3 graphStack Overflow
版权声明:本文标题:javascript - Direct data input from Django for a D3 graph - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741290360a2370513.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论