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 8256547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:53:28+00:00 2026-06-08T01:53:28+00:00

I successfully mapped y values, but I’m having trouble mapping an x value to

  • 0

I successfully mapped y values, but I’m having trouble mapping an x value to an arbitrary field on my values when creating a stacked bar graph using the stack layout. I’m not really familiar with Javascript and d3; so I’m probably missing something basic here.

A value in my array of data looks like { "xInit": 0, "yInit": 91 }. I want to map xInit to x in the graph and yInit to y.

This works (suggested by Bryan Clark):

var st = d3.layout
           .stack()
           .values(function (d) { return d.values; })
           .y(function (v, i) { return v.yInit; })
           .out(function (d, y0, y) { d.x = d.xInit; d.y0 = y0; d.y = y; });

This works, the x coords are taken from value.xInit

And this doesn’t:

var st = d3.layout.stack()
           .values(function (d) { return d.values; })
           .y(function (v, i) { return v.yInit; })
           .x(function (v, i) { return v.xInit; });

Fail! value.x returns NaN

It gives the following warnings:

Unexpected value translate(NaN,0) parsing transform attribute.
Unexpected value NaN parsing x attribute.

Am I using stack.x([accessor]) incorrectly here? How should I use it then?

Details

A complete example showing my problem is available as a block based on this gist. I would like to create a stacked bar graph based on the following data:

initialData = [ {
          "name": "apples",
          "values": [{ "xInit": 0, "yInit": 91 }, { "xInit": 1, "yInit": 290 }, { "xInit": 2, "yInit": 120 }]
      },{
          "name": "oranges",
          "values": [{ "xInit": 0, "yInit": 9 }, { "xInit": 1, "yInit": 49 }, { "xInit": 2, "yInit": 37 }]
      }];
  • 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-08T01:53:29+00:00Added an answer on June 8, 2026 at 1:53 am

    I’m not entirely clear what you’re trying to do here so this isn’t a full solution but I’ll help you get going.

    You can manipulate the outgoing data with the out() function to get the x coordinate you’re looking for and thus make your graph happen.

    var st = d3.layout.stack()
            .values(function(d) { return d.values; })
            .out(function(d, y0, y) {d.x = d.xInit; d.y0 = y0; d.y = y; })
            .y(function (v, i) { return v.yInit; });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I successfully mapped an image on a square in OpenGL ES...but its rotated 90
I successfully mapped an image on a square in OpenGL ES...but its rotated 90
My proxy generator is having trouble generating proxies for internal mapped Nhibernate classes. I
Has anyone successfully mapped a numeric array in PostgreSQL to a numeric array in
I created a google app engine project. I just successfully mapped it to a
I have successfully migrated all my databases from 2008 to 2012 and mapped the
Successfully used jquery-infinite-carousel in the past but for my current project I need it
I've successfully mapped an Entity Framework Code-First data model with an existing Sql Server
I have been using automapper pretty successfully lately but i have come across a
From this guide , I have successfully run the sample exercise. But on running

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.