Is d3.json() function can get json object?

[亡魂溺海] 提交于 2020-02-03 04:14:59

问题


I am new to JQuery / d3js world.

I would like to draw a chart from data in json format. I saw i some samples that d3.json(json,f) function can get only file with data in json format. My question: is it possible to call it with json like object or string in json format,for example:

val jsonStr = { "foo" : "bar"}
d3.json(jsonStr ,f)

If not how can I draw a chart with dynamic data (in json format)


回答1:


If you have the data as a Javascript variable, you don't need the d3.json function. Simply use the name of the variable where ever you would use the argument to the second parameter (the callback function) to d3.json.

var data = [1,2,3];   
svg.selectAll("circle")
.data(data)
.enter()
.append("circle")
.‌​attr("cx", function(d) { return d; })
.attr("cy", function(d) { return d; })


来源:https://stackoverflow.com/questions/13799571/is-d3-json-function-can-get-json-object

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!