Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

jquery

d3.js

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)

like image 520
zohar Avatar asked Dec 10 '12 10:12

zohar


People also ask

What does d3 JSON do?

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.

Can a JSON object contain a function?

JSON Array However, unlike JavaScript objects, JSON data cannot contain functions as values.

What is the syntax to read JSON data in d3?

JSON Syntax RulesData is in name/value pairs. Data is separated by commas. Curly braces hold objects. Square brackets hold arrays.

Can a JSON value be an object?

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.


1 Answers

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; })
like image 150
Lars Kotthoff Avatar answered Sep 28 '22 20:09

Lars Kotthoff