Highcharts: How to rename series
Asked Answered
I

5

10

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!!

Incapacious answered 3/9, 2011 at 18:41 Comment(0)
A
0

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.

Audraaudras answered 5/9, 2011 at 15:41 Comment(1)
Thanks, works pretty well, making the animations run a second time actually looks good, if you take the default settings the color will change, yes, but since you can set the color yourself it's not a problem, either.Incapacious
S
53

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!

Scanty answered 12/4, 2013 at 10:58 Comment(3)
This method works and is recommended over the eolsson's accepted answer.Libava
Seems like adding the false flag doesnt do much though. I took it out and no longer had to call chart.redraw()Christeenchristel
According to the documentation provided by Highcharts, the last flag is provided to indicate whether redraw or not the chart.Tko
D
8

This seems to work :

chart.series[1].name="Renamed";
chart.redraw();
Demmy answered 12/3, 2013 at 22:20 Comment(0)
A
0

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.

Audraaudras answered 5/9, 2011 at 15:41 Comment(1)
Thanks, works pretty well, making the animations run a second time actually looks good, if you take the default settings the color will change, yes, but since you can set the color yourself it's not a problem, either.Incapacious
E
-1

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
        }]
    });
Ecology answered 30/10, 2017 at 5:29 Comment(1)
Sorry for the downvote, but the question was about how to rename a series, not how to set its name when instantiating the chart. Also, most of the code in the example is irrelevant anyway.Emma
T
-1

You can use the following to change the series name:

$(chart.series[0].legendItem.element).children('tspan').text('newLabelName');
Tristram answered 19/8, 2020 at 6:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.