-1

After lot of help from stackoverflow folks,finally resolved my json and now its looking good.

luck.json--->

 {
        "PERFECT_JSON_object":
        {
            "51b59c1bbae1c":
                    [
                        { "id": "parties", "float_1": "0.006" , "float_2": "0.9"},
                        { "id": "royal-challenge",  "float_1": "0.02" , "float_2": "0.333" },
                        { "id": "star-speak","float_1": "0.02","float_2":"0.1" }
                    ],
            "51b59c1bbae3c":
                    [
                        { "id": "parties","float_1": "0.006" , "float_2": "0.9"},
                        { "id": "star-speak","float_1": "0.02", "float_2": "0.009" }
                    ],
            "51b59c1bbae5c":
                    [
                        { "id": "parties","float_1": "0.006" , "float_2": "0.9"}
                    ]
        }
    }

I have been trying to get my head around d3js with json,and I must say I have progressed quite a bit.But I am still not able to get the output with json data.

I went through these link`s but dint help.

  1. https://github.com/mbostock/d3/wiki/Requests
  2. d3.js & json - simple sample code?
  3. Access / process (nested) objects, arrays or JSON

MyFIDDLE with json(no output,something wrong in here)

same fiddle with some static values( without Json)-- This is the result that I want.

I know that d3.json method requires json file to be on server.For temporary basis,as the json file is small can we include it directly in a variable in our d3 script?? I think I am messing up with json data in a wrong way.Can somebody help me with it

Community
  • 1
  • 1
HIRA THAKUR
  • 17,189
  • 14
  • 56
  • 87
  • I'm at work and I can't actually see your JSFiddle, but can you paste here the code portion where you call the `d3.json` function? Are you passing a filename to it in JSFiddle? – Joum Jul 04 '13 at 11:31

1 Answers1

1

Yes, you can just add the JSON in a variable and run it this way. See here for the updated jsfiddle. You basically just add your JSON after var data =.

Lars Kotthoff
  • 107,425
  • 16
  • 204
  • 204
  • this is your code Lars.(the gradient one if you remember!!).I am having problem with it when rest of the part is not coming up..watch the link without json – HIRA THAKUR Jul 04 '13 at 13:28
  • :accesing json is a major problem for me right now!!! d.value[2] is not the proper way to go..i think!!! – HIRA THAKUR Jul 04 '13 at 13:30
  • Well, it certainly works for the moment. Yes, in the long term you might want to change that, but that will require quite a number of changes to your JSON and code. I suggest you have a look at some of the excellent D3 tutorials to get a feel for what the data looks like and how to work with it. – Lars Kotthoff Jul 04 '13 at 13:34
  • I agree lars,but i am not that good with json.I am asking what replacement is to be done for d.value[2],d.value so that it renders the output just like http://jsfiddle.net/ddfsb/4/ – HIRA THAKUR Jul 04 '13 at 13:38
  • 2
    In that jsfiddle, you're using `d.value[2]` as well. I guess my point is that there is little benefit for you if I just refactor your code for you to do it "properly". The next time you do something like this, you will struggle again. You need to start at the beginning and understand what you're doing and why. – Lars Kotthoff Jul 04 '13 at 13:42
  • Careful @LarsKotthoff, he might acuse you of warning him about _running before walking_! – Joum Jul 04 '13 at 13:45
  • 2
    I'm not hurt, don't worry. I'm just glad you finally got the help you needed. Hope you also learned something from it - like understanding when people are actually helping you. – Joum Jul 04 '13 at 13:59