0

I need your help. I want to change this graph: http://bl.ocks.org/mbostock/3885211 to read from a json file instead of tsv. That is the format of my Json file.

{
  "name":"chrome" ,

  "values": [   
      { "time" : 1232323 , "value:" :  12}, 
      { "time" : 12323323 , "value:" : 19   
   ]},

{   
  "counter":"Mozilla" ,

  "values": [   
    { "time" : 1232sd3 , "value:" : 18}, 
    { "time" : 11232323 , "value:" : 20}   
  ]},

{    
  "name":"IE" ,

  "values": [   
    {"time" : 12387823 ,"value:" :  100},
    {"time" : 12323 ,"value:" : 123123}
  ]}

]

I have tried a lot but it does not work with Json file.

Really appreciate your help :(

4
  • 1
    Is there a missing [ at the beginning of the file? Commented Jul 4, 2013 at 4:40
  • 2
    Call JSON.parse() and it will turn the JSON into a Javascript object, then you can do whatever you like with it. Commented Jul 4, 2013 at 4:41
  • maybe this ? github.com/mbostock/d3/wiki/Requests#wiki-d3_json Commented Jul 4, 2013 at 4:42
  • Your JSON is also incorrect. it's missing a [ at the beginning and the time value for Mozilla 1232sd3 is incorrect. It'll raise a parse error. Otherwise, try using JSON.parse(). Look into javascript libraries and frameworks like YUI and jQuery if you need more tools. Commented Jul 4, 2013 at 4:45

1 Answer 1

1

OK. So I decided to spend some time and help you solve the problem. The conversion to JSON was poorly done (for the code that is written on the page).

A quick way to get json from the data would be to use vim to retab the data file before running it through a script like this one https://github.com/turian/common-scripts/blob/master/tsv-to-json.py

I created had to manually reformat the data (since I was just trying to set up an example) but you might want to change the code so that it writes into an array first before producing json (you may also need to change the common.json to json).

The complete example is hosted here http://jsfiddle.net/dvqFj/1/

Good luck

Sign up to request clarification or add additional context in comments.

1 Comment

I have 3 data points in the json and decoupled the function. Check jsfiddle.net/dvqFj/3 for comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.