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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:55:47+00:00 2026-05-26T20:55:47+00:00

Not really sure what’s going on with my code but I’m having trouble removing

  • 0

Not really sure what’s going on with my code but I’m having trouble removing all of the series in highcharts after I drilldown. When I call the resetChart function it only ever removes 2 out of the 4 series, I set up a temporary alert to tell display what its deleting and it only alerts for 2 series.

However when I remove the line chart.series[i].remove(); all 4 of the alerts work.
I’ve tried a few ways of looping the array, even put it in reverse but it makes no difference.

if you copy the below code into jsfiddle you will see what I mean

HTML

<div id="container" style="height: 400px; min-width: 600px"></div>
<script type="text/javascript" src="http://www.highcharts.com/js/testing-stock.js"></script>
<script type="text/javascript" src="http://www.highcharts.com/samples/data/usdeur.js"></script>

JQuery

$(function() {
var chart;

var colors = Highcharts.getOptions().colors,
    categories = ['October', 'November'],
    name = 'Monthly',
    data = [{
        y: 22,
        drilldown:[{
            name: 'Income',
            data: [12, 0],
            categories: ['Income', 'Expenses']
        }, {
            name: 'Expenses',
            data: [0, 5]
        }, {
            name: 'Employee',
            data: [0, 3]
        }, {
            name: 'Tax Office',
            data: [0, 1]
        }]
    }, {
        y: 21
    }];
function setChart(drilldown) {
    $.each(chart.series, function(i, val) {
        val.remove();
    });
    if(drilldown) {
        chart.xAxis[0].setCategories(drilldown[0].categories);
        $.each(drilldown, function(i, val) {
            chart.addSeries({
                 name: val.name,
                 data: val.data
            }, false);
        });
    }

    chart.redraw();
}
function resetChart() {
    //chart.toolbar.remove('RESET');
    $.each(chart.series.reverse(), function(i) {
        alert('removing :' + chart.series[i].name);

        // IF I REMOVE THE BELOW LINE, ALL ALERTS DISPLAY CORRECTLY
        chart.series[i].remove();
    });

     chart.xAxis[0].setCategories(categories);
     chart.addSeries({
          name: name,
          data: data
     });
     chart.redraw();
}

chart = new Highcharts.Chart({
    chart: {
        spacingLeft: 5,
        spacingRight: 5,
        spacingBottom: 5,
        renderTo: 'container',
        type: 'column'
    },
    title: false,
    xAxis: {
        categories: categories
    },
    yAxis: {
        title: false,
        labels: {
            formatter: function() {
                str = '$' + this.value + '';
                return str.replace('$-', '-$');
            }
        },
    },
    legend: {
        enabled: false
    },
    plotOptions: {
        column: {
            cursor: 'pointer',
            stacking: 'normal',
            point: {
                events: {
                    click: function () {
                        var drilldown = this.drilldown;
                        if (drilldown) { // drill down;
                            setChart(drilldown);
                        }
                    }
                }
            }
        }
    },
    tooltip: {
        formatter: function() {
           var point = this.point,
              s = '<b>$' + this.y +'</b>';
              s = s.replace('$-', '-$');
           if (point.drilldown) {
              s += ': Click to view '+ point.category +'';
           }
           return s;
         }
    },
    series: [{
        name: name,
        data: data
    }]
});
chart.toolbar.add('RESET', 'Reset', 'chartReset', resetChart);
});
  • 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-26T20:55:48+00:00Added an answer on May 26, 2026 at 8:55 pm

    FIXED

    Instead of using each I used while.
    When series was removed it was removing it from the array, so the array was getting smaller

    each time remove() was called.

    Replaced both instances of each (in setChart and resetChart):

    $.each(chart.series.reverse(), function(i) {
        chart.series[i].remove();
    });
    

    With:

     while(chart.series.length > 0)
     chart.series[0].remove();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So i'm not really sure why this is happening but I'm running through some
I'm not really sure how to title this question but basically I have an
I know this is possible but I'm not really sure where to start. Has
I'm stuck in having to write a simple spam filter I'm not really sure
I feel like there's a simple solution to this, but I'm not really sure
I'm not really sure what's going on here. This is what I have in
I am not really sure how to word the question, but I basically have
I'm not really sure why my code is throwing a EXC_BAD_ACCESS, I have followed
I'm not really sure how to describe what I want to do, but I'm
I'm not really sure how to go about it, but I'd like to have

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.