Home Looping through array of objects within multiple objects and accessing values in D3 using underscore
Reply: 0

Looping through array of objects within multiple objects and accessing values in D3 using underscore

user9100
1#
user9100 Published in September 20, 2018, 10:22 pm

In D3d.js, I'm trying to append rectangles for each object in the array, so the height of the rectangle is determined by the value. Also, I'm trying to make it so only the first object in each array shows first, and then when you click a button it cycles through the 2nd and 3rd object.

However I'm having issues looping through the data because not sure how to do it with this JSON structure--

  var data= {
    "Object_one":[
        {"date":"1/4/2010",
         "value":"50",},
        {"date":"6/22/2010",
         "value":"44",},
        {"date":"9/18/2010",
         "value":"42",},
    ],
    "Object_two":[
        {"date":"1/4/2010",
         "value":"54",},
        {"date":"6/22/2010",
         "value":"41",},
        {"date":"2012",
         "value":"42",},
    ],
    "Object_three":[
        {"date":"1/4/2010",
         "value":"55",},
        {"date":"6/22/2010",
         "value":"43",},
        {"date":"9/18/2010",
         "value":"65",},
    ]
}

I have a loop set up using underscore.js to loop through the data, but it's only taking in all the objects of the first array, as opposed to the first object in each array for each Object X.

https://jsfiddle.net/vw88/6Ljekv45/

(see line 55 of the js for the part that appends the rectangles with values)

share|improve this question
  • 1
    What is the structure goal ? Could you provide an example of what you expect ? – trichetriche Feb 13 at 8:12
  • Thanks for replying, I'll post another fiddle shortly to show how it should look visually – vw88 Feb 13 at 8:19
  • That's not what I meant, I wanted to know what exactly you need to do with this data. I have never used d3.js, so you need to tell me if you want to change your data structure, or make some function calls. – trichetriche Feb 13 at 8:22
  • I need to make function calls with the existing data structure. I've just edited the question and fiddle to hopefully clarify. – vw88 Feb 13 at 8:28

1 Answer 1

active oldest votes
up vote 1 down vote accepted
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.33598 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO