最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Highcharts Dynamically Changing Labels? - Stack Overflow

programmeradmin3浏览0评论

There is a label at this graphic: .7.2/highslide-software/highcharts/tree/master/samples/highcharts/demo/bo/ 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: /

Any ideas?

There is a label at this graphic: http://jsfiddle/gh/get/jquery/1.7.2/highslide-software/highcharts./tree/master/samples/highcharts/demo/bo/ 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/UXDqL/

Any ideas?

Share Improve this question edited Sep 6, 2012 at 5:25 kamaci asked Sep 5, 2012 at 8:42 kamacikamaci 75.2k72 gold badges244 silver badges371 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 9

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/6GKCJ/2/

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

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

            title.attr({
                text:'newText'
            });
        });

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")

Highchart does not provide any method to dynamically update label header as of Highcharts 3.0. Although it does provide a method to update series dynamically: http://api.highcharts./highstock#Series.update()

To update the label header, we need to follow a brute force approach here i.e. to render the chart again after updating chart options. The following code should do the trick :

var mychart = $('#container').highcharts();
    mychart.options.labels.items[0].html= "Changed label header";
    mychart = new Highcharts.Chart(mychart.options);
    mychart.render();

JsFiddle: http://jsfiddle/msjaiswal/ZD4N5/2/

A similar thread : here

发布评论

评论列表(0)

  1. 暂无评论