Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Highcharts Dynamically Changing Labels?

There is a label at this graphic: http://jsfiddle.net/gh/get/jquery/1.7.2/highslide-software/highcharts.com/tree/master/samples/highcharts/demo/combo/ label is "Total fruit consumption"

After chart created, how can I change that sentence dynamically?

PS: I tries to set labels and redraw graphic but didn't work: http://jsfiddle.net/UXDqL/

Any ideas?

like image 408
kamaci Avatar asked Dec 16 '22 19:12

kamaci


2 Answers

Insted of using labels, you can use renderer text () and then use variable to keep object. If you need update dynamically this text, only what you need is use attr() function and update.

http://jsfiddle.net/6GKCJ/2/

var title = chart.renderer.text('Total fruits consumption', 100, 90)
        .css({
            fontSize: '12px'
        })
        .add();

        $('#btn').click(function(){

            title.attr({
                text:'newText'
            });
        });
like image 121
Sebastian Bochan Avatar answered Dec 18 '22 10:12

Sebastian Bochan


If you want to change it after the plot is drawn, just act on the element itself. Using jquery selectors it's as easy as:

// find me the tspan containing the specified text and change it to...
$("tspan:contains('Total fruit consumption')").text("Something New")
like image 33
Mark Avatar answered Dec 18 '22 09:12

Mark