The following code (built from the answer of a related question) changes the line color in a Highcharts line chart when hovering the series without using the heavier series.update method, but the code line which should change also the datalabels text color is broken. How can I achieve the desidered result?

Highcharts.chart('container', {
    plotOptions: {
        series: {
            dataLabels: {
                enabled: true
            },
            states: {
                hover: {
                    enabled: false
                },
                inactive: {
                    enabled: false
                }
            },
            pointStart: 2010,
            events: {
                mouseOver: function() {
                    this.graph.attr({
                        stroke: "rgb(255,0,0)"
                    });
                    this.points.forEach(p => {
                            p.graphic.attr({
                                fill: "rgb(255,0,0)"
                            });

                            p.dataLabel.options.color="rgb(255,0,0)" 
                            //the above line is broken
                        }
                    );
                },
                mouseOut: function() {
                    this.graph.attr({
                        stroke: this.color
                    });
                    this.points.forEach(p => p.graphic.attr({
                        fill: this.color
                    }));
                }
            }
        },
    },

    series: [{
        name: 'Installation',
        data: [43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175]
    }, {
        name: 'Manufacturing',
        data: [24916, 24064, 29742, 29851, 32490, 30282, 38121, 40434]
    }, {
        name: 'Sales & Distribution',
        data: [11744, 17722, 16005, 19771, 20185, 24377, 32147, 39387]
    }, {
        name: 'Other',
        data: [12908, 5948, 8105, 11248, 8989, 11816, 18274, 18111]
    }],

});

on JSfiddle

1 Answers

1
Wojciech Chmiel On Best Solutions

To change data label color you have to set a new fill style for the label text element using css() method.

Code:

point.dataLabel.text.css({ fill: "rgb(255,0,0)" });

Demo:

API reference: