Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8788007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:02:38+00:00 2026-06-13T22:02:38+00:00

I’m trying to create a stacked bar chart with d3 from data in a

  • 0

I’m trying to create a stacked bar chart with d3 from data in a JSON file. Each bar would have ties, losses, and wins for a particular month.

JSON file:

{
    "name": "FHS",
    "points": 3000,
    "ties": 3,
    "losses": 19,
    "wins": 50,
    "games": {
        "2010-09": { "ties": 1, "losses": 2, "wins": 16 },
        "2010-10": { "ties": 2, "losses": 5, "wins": 13 },
        "2010-11": { "ties": 0, "losses": 12, "wins": 21 }
    }
}

I’ve already used some of the data just fine using the d3.json functionality. For example:

d3.json("data.json",function(error,data)
    {
        alert(data.name);
        alert(data.points);
        // etc.
    });

But here’s where it gets interesting (fyi, I’m using the underscore library to grab each property of “games”…perhaps this is where I’m going wrong?). If I try the following:

_.keys(data.games).forEach(function(d)
    {
        alert(d);
    });

I get 2010-09, 2010-10, 2010-11 in three different alert boxes…perfect! BUT, if I try the following:

_.keys(data.games).forEach(function(d)
    {
        alert(d.ties);
    });

I get undefined :/ In fact, another problem that I see arising is that

alert(data.games.2010-09.ties);

should work (if the property names didn’t begin with integers or have hyphens…), but won’t because of the format of the literal (“2010-09”)…so, my main question is how to dynamically access nested object properties in such a manner that would make generating a chart simple. I’ve tried to include enough context, but please let me know if you would like any more information. Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T22:02:40+00:00Added an answer on June 13, 2026 at 10:02 pm

    You get undefined in the alert box because d, inside this function, is a string – “2010-09”, “2010-10”, “2010-11”, etc – since you’re iterating over the array of strings returned by _.keys(data.games).

    So, alert(d.ties) is like calling alert("2010-09".ties), which is expectedly undefined.

    But, building on what Lars explained,

    _.keys(data.games).forEach(function(d)
    {
        alert(data.games[d].ties);
    });
    

    is how you’d get at the data.

    P.S. console.log(data.games[d].ties) is the more robust way (and hence usually the preferred way) to debug javascript.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
I am trying to render a haml file in a javascript response like so:
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
I have a view passing on information from a database: def serve_article(request, id): served_article
I have a reasonable size flat file database of text documents mostly saved in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.