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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T19:39:05+00:00 2026-06-18T19:39:05+00:00

Say we have a y-scale that converts the data domain to rangebands that are

  • 0

Say we have a y-scale that converts the data domain to rangebands that are 20px for each data element.

var y = d3.scale.ordinal()
    .domain(data)
    .rangeBands([0, 20 * data.length]);

I would normally use this scale to determine the y-coordinate of something in this manner:

svg.selectAll("rect")
    .data(data)
    .enter()
    .append("rect")
    .attr("y", y)

But in some tutorials, I’ve seen an alternative syntax.

.attr("y", function(d) { return y(d); })

I’m not sure what’s going on here, and I would like to understand it before I move on with learning D3. I know y is a function, so the d within parenthesis would be an argument of that function. But we already specified the data input in the y function. I would love to read an explanation of what we’re actually doing with y(d). What are the pros and cons of the two alternatives?

  • 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-18T19:39:06+00:00Added an answer on June 18, 2026 at 7:39 pm

    I think that’s a minor difference that’s maybe left over from copying and pasting other attrs that are set with an anonymous function (as in the second case). There should be no reason to wrap y in an anonymous function.

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

Sidebar

Related Questions

Lets say I have a website that sells widgets. I would like to do
Let's say I have the following dataset bodysize=rnorm(20,30,2) bodysize=sort(bodysize) survive=c(0,0,0,0,0,1,0,1,0,0,1,1,0,1,1,1,0,1,1,1) dat=as.data.frame(cbind(bodysize,survive)) I'm aware that
Say I have a dataset, each element has an associated score. eg: Banana -
Say I have a BitmapData of 600x600 and I want to scale it down
I have a UIView which I rotate to certain angle or say scale to
Say I have a select box eg <div data-bind='visible: someProp'> <select class=selectSubWidgets data-bind='options: subWidgets,optionsText:
Say I have a SSI script that uses exec, or a PHP script that
Say I have four sub-classes of 'Car'. One for each color. I want to
Say I have some SVG that looks like the following. #canvas will have some
Let's say I have two animations that work individually, but I want them to

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.