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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:13:36+00:00 2026-05-30T15:13:36+00:00

I have the following JQuery: $(document).ready(function() { var names = [‘item1’, ‘item2’]; var series1

  • 0

I have the following JQuery:

$(document).ready(function() {
    var names = ['item1', 'item2'];
    var series1 = [{ name: '', data: []}];
    var series2 = [{ name: '', data: []}];
    var seriesCounter = 0;
    ....
    renderCharts(url, otherUrl);

    function renderCharts(url, otherUrl) {
        if (otherUrl != '') {
            $.each(names, function (i, name) {

                $.getJSON('somurl', function (items) {
                    series1[i].name = name;

                    $.each(items.somedata, function (j, item) {
                        series1[i].data.push({
                            x: Date.parse(item.key),
                            y: item.value
                        })
                    });

                    seriesCounter++;

                    if (seriesCounter == names.length) {
                        ... render chart once all data has been downloaded
                    }
                });
            });
        }

        $.getJSON(url, function (items) {
            $.each(items.otherData, function (i, item) {
                series2[0].data.push({
                    x: Date.parse(item.Key),
                    y: item.Value
                })
            });

            // render other chart
        });
    }
}

I can’t get this to work. Every time I run this I never enter the following condition:

if (seriesCounter == names.length) {
    ... render chart once all data has been downloaded
}

If I only have one item in the names array, it works just fine. The moment I add two, the condition never becomes true and therefore my charts never renders.

What am I missing?

  • 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-05-30T15:13:37+00:00Added an answer on May 30, 2026 at 3:13 pm

    Your series1 variable is defined as an array with exactly one element (an object) in it, but within the $.each(names, function (i, name) { loop you are treating it as if it had more elements and trying to access series1[i] for values of i that are greater than 0. When i is 1 you are trying to do series1[1].name but series1[1] is undefined and has no name property.

    Your script would be stopping at that point, so the line if (seriesCounter == names.length) { isn’t reached.

    I suggest you declare series1 as an empty array and then within the loop add a new item as needed:

    ...
    var series1 = [];
    ...
    $.each(names, function (i, name) {
        $.getJSON('somurl', function (items) {
            // create new object
            series1[i] = { name: name, data: []};
            ...
    

    (You don’t have the same problem with series2 because although you’ve declared it as an array too you only ever access array element 0.)

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

Sidebar

Related Questions

I have the following jQuery: $(document).ready(function () { $(.element).draggable(); $(.element).droppable({ drop: function () {
I have the following jQuery which I need adapting: $(document).ready(function(){ $(.rss-popup a).hover(function() { $(this).next(em).stop(true,
I have the following jquery function > <script type=text/javascript> > > $(document).ready(function() { >
I have the following code: $(document).ready(function() { // Manage sidebar category display jQuery(#categories >
Never ran into this problem with jQuery before. I have the following: $(document).ready(function() {
I have the following jquery code: $(document).ready(function() { $(#build_table, a.coursename, .Start Date, .Book Title,
I have the following jquery code $(document).ready(function() { //Default Action $(#playerList).verticaltabs({speed: 500,slideShow: false,activeIndex: <?=$tab;?>});
I have the following and in this order: <script type=text/javascript> $(document).ready(function(){ var overwrite =
I have 3 checkboxes with the following jQuery and it works great. $(document).ready(function() {
i have the following javascript file named coupon.js - jQuery(document).ready(function(){ jQuery('.appnitro').submit( function() { $.ajax({

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.