Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

remove series by name or id in highcharts

Is there anyway to remove a series by name or id? I mean it is possible to remove series by this.remove()

or

var seriesLength = chart.series.length;
for(var i = seriesLength - 1; i > -1; i--) {
    chart.series[i].remove();
}

but by name say, series_name.remove() is it possible?

like image 628
Poles Avatar asked Feb 24 '14 05:02

Poles


People also ask

How do I delete a series in Highcharts?

You could probably just iterate through the series and check the . name against your "passed in name" instead of scanning the document for "series_name". There really should be a chart. remove(series) (not just index, because the indices remap after you remove one).

How do I hide the Highchart watermark?

Highchart by default puts a credits label in the lower right corner of the chart. This can be removed using credits option in your chart settings. will remove the highcharts.com logo.

What is legend in Highcharts?

The legend displays the series in a chart with a predefined symbol and the name of the series. Series can be disabled and enabled from the legend.


4 Answers

Well, I don't know if at the time it was possible, but now you have a get function in the chart object to which you can pass an id and retrieve an element within the chart.

For example:

var chart = new Highcharts.Chart({    
    chart: { renderTo: 'container' },
    series: [
      {
        id: 'series-1', 
        data: [1,2,3,4,5,6,7,8,9]
      },
      {
        id: 'series-2',
        data: [9,8,7,6,5,4,3,2,1]
      }
    ]
});

//Remove the 'series-2'
chart.get('series-2').remove();

Working example in jsfiddle

like image 98
lcguida Avatar answered Oct 22 '22 08:10

lcguida


Ok, I found it myself. I send the series name in a hidden field of a div and when I click the delete button I'm checking if the name matches among the series and if match found I delete it.

var chart = $('#container').highcharts();
                var seriesLength = chart.series.length;
                for(var i = seriesLength - 1; i > -1; i--)
                {
                    //chart.series[i].remove();
                    if(chart.series[i].name ==document.getElementById("series_name").value)
                        chart.series[i].remove();
                }
like image 30
Poles Avatar answered Oct 22 '22 07:10

Poles


These two simple solutions work for me.

UPDATE : I realized I misunderstood the question. These solutions remove all the ledends.

Hide it using jQuery

$(function () {
  // Build the chart.
  $('#volume_pie_chart').highcharts({
      // Some configuration code...
    })

    // Hide the legend.
    $('.highcharts-legend').hide()
});

Position the legend so that we do not see it

...
},
legend: {
    x: 9999, // Make the legend invisible.
    y: 9999
},
...
like image 36
mnishiguchi Avatar answered Oct 22 '22 09:10

mnishiguchi


This needs more visibility, because this is fairly janky. You could probably just iterate through the series and check the .name against your "passed in name" instead of scanning the document for "series_name".

There really should be a chart.remove(series) (not just index, because the indices remap after you remove one).

like image 1
Joejoe Avatar answered Oct 22 '22 09:10

Joejoe