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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:11:33+00:00 2026-06-04T10:11:33+00:00

I am using jQuery to bring in a string of comma-delimited numbers for plotting

  • 0

I am using jQuery to bring in a string of comma-delimited numbers for plotting purposes in D3. I’m trying to get the max of this array but it is not going well.

var x_data = $('.CostImport').text().split(',');
var y_data = $('.PriceImport').text().split(',');
var r_data = $('.SalesImport').text().split(',');
var c_data = $('.ZoneImport').text().split(',');


 for (i = 0; i < x_data.length; i++) {
   data.push({ "x": x_data[i], "y": y_data[i], "c": c_data[i], "r": r_data[i] });
   }

alert(d3.max(r_data));
alert(d3.max(data, function (d) { return d.r }));

Both of these alert pass me the same number, which is incorrect. The actual max is 928870 but I am getting back 9975. Plotting everything works fine (scatter plot, with r determining size and c color), so I’m a bit flummoxed why I can’t pull the maximum number.

Any ideas?

  • 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-04T10:11:35+00:00Added an answer on June 4, 2026 at 10:11 am

    It sounds like the values are being treated as strings. You will need to use parseInt or parseFloat (depending on the precision of the values) to convert them to integers for the max function to work as you are expecting.

    Here’s a quick function to convert a string array to int. This would be better prototyped, but for a quick and dirty example this will work:

    function toIntArray(arr) {
        for (var i = 0; i < arr.length; i++) { 
            arr[i] = +arr[i]; 
        } 
        return arr;
    }
    

    Keep your code as is, but amend these lines:

    r_data = toIntArray(r_data);
    data = toIntArray(data);
    
    alert(d3.max(r_data));
    alert(d3.max(data, function (d) { return d.r }));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using jQuery I am trying to set focus for (CSS purposes) to a particular
I have a text string i'm trying to select the spans from using jQuery.
Using JQuery it possible to clone a Div like this and change add a
I'm trying to send data from a client application using jQuery to a REST
I have this jQuery get request: $.get($(this).attr(href), { searchExpression: schroders }, function (result) {
I'm trying out PhoneGap 1.4 on Windows Phone 7.5 using jQuery mobile (1.0.1.). Basic
I'm using jQuery's $.post call and it's returning a string with quotes around it.
I'm using a jQuery datepicker to select an applicant's date of birth, but the
I'm using jQuery (1.6.4) and using a slightly modified version of this method to
This is my second attempt at a php contact form using Jquery and php

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.