In data-rich charts with multiple overlapping series it might be difficult to tell one series from another when hovering a series data point or a legend item. To make the hovered series stand out, we can highlight it, while dimming other chart series at the same time.
By default, only item highlighting is activated. Series highlighting, as shown in the sample above, can be activated by modifying the default highlightStyle
.
Each chart series has a highlightStyle
config with the following default values:
highlightStyle: {
// Attributes that apply to individual items within a single series.
// For example, a line series marker nearest to the mouse cursor,
// or a bar segment under a cursor.
item: {
fill: 'yellow',
stroke: undefined,
strokeWidth: undefined,
}
// Attributes that apply to the whole series containing the highlighted item.
series: {
dimOpacity: 1, // series opacity when dimmed (while some other series is hovered)
strokeWidth: undefined
}
}
The highlighted series item can be a bar or column segment, a pie or doughnut sector, or a marker in series with markers such as line, area, or scatter and bubble series.
In order to activate series highlighting, replace the default highlight style shown above with the custom one shown below:
highlightStyle: {
item: {
fill: 'red',
stroke: 'maroon',
strokeWidth: 4
},
series: {
dimOpacity: 0.2,
strokeWidth: 2
}
}
This custom highlightStyle is applied to the column series in the example below. Note the following:
highlightStyle.item
configuration.
Also, the segments belonging to all other stack levels are dimmed, and only segments
from the stack level that the highlighted segment belongs to remain unaffected.strokeWidth
of 2
,
while the currently hovered segment gets a strokeWidth
of 4
.Let's take a look at the pie chart configuration now, which is going to be slightly different. Note the following:
title
config, we will have legend items that are indistinguishable from those of other series,
because each series legend items will be: Coffee
, Tea
, Milk
. This is why in order to make legend items unique we use the name of the quarter
in the series title
config.highlightStyle
of every single series;
in this example we are using the same highlightStyle
for all 4 of them, but they could also be unique.The example above provides a separate highlightStyle
for each pie series config.
The highlight style can be provided in a chart theme just once to be used by all pie series, as illustrated by the example below: