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)
js json() Function. The d3. json() function is used to fetch the JSON file. If this function got an init parameter, then this is called along with the fetch operation.
JSON Array However, unlike JavaScript objects, JSON data cannot contain functions as values.
JSON Syntax RulesData is in name/value pairs. Data is separated by commas. Curly braces hold objects. Square brackets hold arrays.
JSON cannot be an object. JSON is a string format. The data is only JSON when it is in a string format. When it is converted to a JavaScript variable, it becomes a JavaScript object.
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; })
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With