Gayatri
Gayatri

Reputation: 2253

How to get Series Name Based on Selection in Highcharts

I am trying to get the Series Name based on what is selected in the Highcharts graph but the label does not display the series name.

Here is the link to the code I have been working on: http://jsfiddle.net/ktjno528/

$(function () {
    // create the chart
    $('#container').highcharts({
        chart: {
            events: {
                redraw: function () {
                    var label = this.renderer.label(this.series.name, 100, 120)
                        .attr({
                            fill: Highcharts.getOptions().colors[0],
                            padding: 10,
                            r: 5,
                            zIndex: 8
                        })
                        .css({
                            color: '#FFFFFF'
                        })
                        .add();

                    setTimeout(function () {
                        label.fadeOut();
                    }, 1000);

                }
            }
        },
        xAxis: {
            categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
        },

        series: [{name:'S1',
            data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
        }]
    });


    // activate the button
    $('#button').click(function () {
        var chart = $('#container').highcharts();
        chart.addSeries({name:'S2',
            data: [216.4, 194.1, 95.6, 54.4, 29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5]
        });

        $('#button').unbind('click');
    });
});

Upvotes: 2

Views: 5665

Answers (1)

Kabulan0lak
Kabulan0lak

Reputation: 2136

You are trying to access this.series.name, which returns nothing because this.series is an array of series. So you may want to use this.series[0].name or this.series[1].name depending on which series name you want to display.

See you updated JSFiddle here.

Upvotes: 1

Related Questions