Removing or Hiding a series in a chart via javascript

I am attempting to remove a series from a chart but can only find examples using a click action. 

I’ve tried using remove() but can’t it won’t recognize the function or the object no matter what I try.

I’ve been able to simply make the series invisible, but I’d love to be able actually remove it.
Here’s the part of my javascript snippet for that.

var blankSeries = {       
        showInLegend : false,
        series: {
            visible: false,
chartObj.series[1] = blankSeries;


When are you trying to run this snippet. If you run a before-render snippet for the chart, you should be able to delete a series.


delete chartObj.series[1];

Thanks for the reply, Matt.

I am running this as a before-render snippet on the chart.

Here’s part of the code where I tried adding in your snippet and the error that is thrown. My javascript skills are strictly amateur, so maybe I’m missing something ‘obvious’.

    var newSeries = {        id: 'Cumulative',
        name: 'Percent of ECN',
        data: cumulative,
        type: 'column',
        yAxis: chartObj.series[0].yAxis,
    // replace first series with new cumulative series
    chartObj.series[0] = newSeries;  delete chartObj.series[1];

 ![]( "Image https//d2r1vs3d9006apcloudfrontnet/s3\_images/1363899/RackMultipart20160212-6580-1ag8w42-error\_inlinejpg1455300884")

A couple quesitons:

  • Does chartObj.series[1] exist? That assumes there are at least two series to start with. the first series you’re replacing with ‘newSeries’ and the second you’re trying to delete?
  • What part of the code is causing the error? (Expand the error to see the call stack and see if you can trace it back to any of your own code.