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

  • Home
  • SEARCH
  • 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 8632441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:21:14+00:00 2026-06-12T09:21:14+00:00

I am a total beginner to d3.js so please be kind :) considering this

  • 0

I am a total beginner to d3.js so please be kind 🙂

considering this jsbin example

I have the following dataset:

      var dataset = [
                      [d3.time.hour.utc.offset(now, -5), 1, 10], 
                      [d3.time.hour.utc.offset(now, -4), 2, 20], 
                      [d3.time.hour.utc.offset(now, -3), 3, 30], 
                      [d3.time.hour.utc.offset(now, -2), 4, 40], 
                      [d3.time.hour.utc.offset(now, -1), 5, 50], 
                      [now, 6, 60],
                    ];

Two questions.

  1. Does d3 provide a better approach to finding the max value for my y-axis data (all columns but the 0th, the 0th column is x-axis (time)) in my dataset array? Currently I am just looping through the entire dataset array and making a second array, excluding the first column. Perhaps there is a better datastructure other than an array I should be using for this entirely?

        var data_arr = [];
    
        for (row in dataset){
            for (col=1;col < dataset[row].length; col++){
                data_arr.push(dataset[row][col]);
            }
        }
    
        var yScale = d3.scale.linear()
                             .domain([0, d3.max(data_arr)])
                             .range([h - padding, padding]);
    
  2. Once thats resolved, I still need to determine how to graph multiple y-axis values in general! This worked fine before I needed multiple y-axis values:

        svg.selectAll("circle")
           .data(dataset)
           .enter()
           .append("circle")
           .attr("cx", function(d) {
                return xScale(d[0]);
           })
           .attr("cy", function(d) {
                return yScale(d[1]);
           })
           .attr("r", 2);
    

Please take a look at the graph w/ code here now for full context: http://jsbin.com/edatol/1/edit
Any help is appreciated!

  • 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-12T09:21:15+00:00Added an answer on June 12, 2026 at 9:21 am

    I’ve made a couple of changes to your example and you can see the results at http://jsbin.com/edatol/2/edit.

    First, I modified your data a little bit. This is mostly just a style thing, but I find it’s easier to work with objects instead of arrays:

            //Static dataset
            var dataset = [
              {x: d3.time.hour.utc.offset(now, -5), y1: 1, y2: 10}, 
              {x: d3.time.hour.utc.offset(now, -4), y1: 2, y2: 20},
              {x: d3.time.hour.utc.offset(now, -3), y1: 3, y2: 30},
              {x: d3.time.hour.utc.offset(now, -2), y1: 4, y2: 40},
              {x: d3.time.hour.utc.offset(now, -1), y1: 5, y2: 50},
              {x: now, y1: 6, y2: 60},
            ];
    

    Then you can find your domains and ranges like this:

    var xDomain = d3.extent(dataset, function(i) { return i.x; });
    var maxY = d3.max(dataset, function(i) { return Math.max(i.y1, i.y2); });  
    

    Then to add multiple y-values, you just have to append an additional circle with the appropriate values. I gave them different classes so that you can use that to select them if you want to do transitions or updates later on.

            //Create circles
            svg.selectAll(".y1")
               .data(dataset)
               .enter()
               .append("circle")
               .attr("cx", function(d) { return xScale(d.x); })
               .attr("cy", function(d) { return yScale(d.y1); })
               .attr("class", "y1")
               .attr("r", 2);
    
            //Create circles
            svg.selectAll(".y2")
               .data(dataset)
               .enter()
               .append("circle")
               .attr("cx", function(d) { return xScale(d.x); })
               .attr("cy", function(d) { return yScale(d.y2); })
               .attr("class", "y2")
               .attr("r", 2);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a total beginner so I apologize if this question is elementary. I have
This is a total beginner question, I've spent the past hour searching both stackoverflow
I'm a total beginner in C programming so please bear with me. I have
I am a total beginner in JS/XML. I have this simple code that needs
Please understand: I am a total beginner at Actionscript and anything like Actionscript, and
I'm a total beginner with OpenCL and I'm trying to make the following kernel
I'm pretty new to Java and am following the Eclipse Total Beginner's Tutorials .
Ok. So I am a total beginner at Java. But why does this loop
Let me preface this post with a single caution. I am a total beginner
Total beginner question about jQuery: I have a Form that contains several TextBoxes (input

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.