I am trying to style the corresponding legend item when hovering over a slice in the pie chart. I am able to update the style of the entire legend (all legend items) using the following plotOptions:
plotOptions: {
series: {
point: {
events: {
mouseOver: function () {
this.series.chart.legend.update({
itemStyle: {
fontWeight: "bold",
},
});
},
mouseOut: function () {
this.series.chart.legend.update({
itemStyle: {
fontWeight: "normal",
},
});
},
},
},
},
},
So how can I access the CSS of the individual items?
2
Answers
One way to alter one label individually is to use the events to set a user option, which is then used in the label formatting to distinguish it from the other labels.
For example, in the events we set
hovering: true
orhovering: false
. Then in the formatter we apply separate HTML around the label name to distinguish it, like<b>
or you could perhaps use<span>
with style.See this example (or this JSFiddle demonstration):
You can use a reference from a point to the legend item. For example:
this.legendItem.label
Live demo: https://jsfiddle.net/BlackLabel/4tevkco0/
API Reference: https://api.highcharts.com/class-reference/Highcharts.SVGElement#css