开发者

Highcharts: How to rename series

开发者 https://www.devze.com 2023-04-02 11:15 出处:网络
I\'m using highcharts in my web application and开发者_运维技巧 I was wondering if there\'s any way to rename a series after the chart hast been created??

I'm using highcharts in my web application and开发者_运维技巧 I was wondering if there's any way to rename a series after the chart hast been created??

Thanks in advance!!


actually, there's a way now. In highchars 3.0 series added a new api, called update:

chart.series[0].update({name:"name u want to change"}, false);
chart.redraw();

it will not only update the series name below the chart, but the name in tooltip as well.

Cheers!


This seems to work :

chart.series[1].name="Renamed";
chart.redraw();


There is no method for doing this in the API. You could remove the series and add it again with another name, but that will make the animations run a second time and I think it will be colored with a new color as well.


It is not required to Redraw chart again We can include it along with the series option in the Chart declaration as below:

        var chart = new Highcharts.Chart({
        chart: {
            renderTo: 'high_container'
        },title: {
            text: 'IO Signal  Data'
        },subtitle: {
            text: 'Source: GPS Modem'
        },

        yAxis: {
            title: {
                text: 'Value'
            }
        },
        legend: {
            layout: 'vertical',
            align: 'right',
            verticalAlign: 'middle'
        },


        xAxis: {
            type: 'datetime',
            labels: {
                enabled: true,
                formatter: function () { return ddd[this.value][0]; }, //<=== the value to plot chart

            }
        },
        series: [{
            data: ddd,
            name: SeriesName
        }]
    });


You can use the following to change the series name:

$(chart.series[0].legendItem.element).children('tspan').text('newLabelName');
0

精彩评论

暂无评论...
验证码 换一张
取 消