Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove text which was added via chart.renderer in Highcharts

I have added labels to my graph, instead of a legend (see fiddle here). Once the graph has been drawn, with those series labels attached to it via chart.renderer.text, the user can click on a button in order to add an additional series, which, in turn, suppresses other lines (successfully). However, how can I get rid now of these labels - which stand there in the void now.

Example: this is the full set of lines and labels: enter image description here

And this is when a button has been clicked in order to show an additional line, which suppresses at the same time four other lines: enter image description here

I add the labels like this:

chart.renderer.text('Volcanic', 1170, 360)
  .css({
    fontSize: '13px',
    color: '#7d7d7d'
  })
.add();

Now, these labels are still there - but should go away. Any way I can achieve this? The possibility to add an ID, and then call a chart.renderer.byID(xy).remove() or something similar?

like image 387
luftikus143 Avatar asked Sep 12 '25 20:09

luftikus143


1 Answers

You can remove rendered objects by calling .destroy() on them. All you need to do is assigning the objects to a variable.

var objLabel; // assign the var so it is reachable in your scope

objLabel = $('#container').highcharts().renderer.text('Volcanic', 100, 30)
  .css({
    fontSize: '13px',
    color: '#7d7d7d'
  })
.add();

Here is a fiddle to prove the point: http://jsfiddle.net/jfpq6zcg/

like image 127
teni Avatar answered Sep 14 '25 10:09

teni