You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
In line chart when interaction mode is dataset, fade animation is missing when legend item is clicked #10882
In a line chart, when legend item is clicked, respective line should fade in/out.
Current behavior
In a specific scenario (mentioned in below section), when legend item is clicked, respective line does not fade but suddenly disappears. This happens when interaction mode is set to dataset with intersect set to false.
Below interaction setting was used to achieve drill-down mechanism in line chart i.e. when user clicks on/near the line data will be switched to show another line chart.
changed the title [-]In line chart, fade animation is missing when legend item is clicked and `interaction` mode is `dataset`[/-][+]In line chart when `interaction` mode is `dataset`, fade animation is missing when legend item is clicked[/+]on Nov 17, 2022
// Let user control the active elements outside chartArea. Eg. using Legend.
returnlastActive;
}
When event is out of chart area (when you hover the legend), the previous active elements are returned.
It seems something is working as designed (see comment).
I'm experiencing the same thing with an HTML legend. If I change the dataset visibility with setDatasetVisibility, there's no fade animation for the line, it just blinks in/out. However the other existing lines do animate their position.
// no animationchart.setDatasetVisibility(item.datasetIndex,!chart.isDatasetVisible(item.datasetIndex));chart.update();
Working code:
if(chart.isDatasetVisible(item.datasetIndex)){chart.hide(item.datasetIndex);// has animation}else{chart.show(item.datasetIndex);// has animation}// chart.update() called by hide()/show()
Found the solution by browsing the default legend plugin code:
Activity
[-]In line chart, fade animation is missing when legend item is clicked and `interaction` mode is `dataset`[/-][+]In line chart when `interaction` mode is `dataset`, fade animation is missing when legend item is clicked[/+]stockiNail commentedon Jan 16, 2023
@pratheekbhandary as you outlined, this is also happening in version 4.
What is generating this behavior is in the following code:
Chart.js/src/plugins/plugin.tooltip.js
Lines 1183 to 1186 in 97bc329
When event is out of chart area (when you hover the legend), the previous active elements are returned.
It seems something is working as designed (see comment).
guanzo commentedon Dec 29, 2023
I'm experiencing the same thing with an HTML legend. If I change the dataset visibility with
setDatasetVisibility, there's no fade animation for the line, it just blinks in/out. However the other existing lines do animate their position.Found a solution:
Broken code from HTML legend example:
Working code:
Found the solution by browsing the default legend plugin code:
Chart.js/src/plugins/plugin.legend.js
Lines 645 to 655 in dff4482
It appears that explicitly setting
legendItem.hidden = true/falseis redundant, asshow()/hide()eventually setshidden.test: hidden data is not active (failing)
fix: hidden data is not active, so a hovered dataset fades out when h…
test: hidden data is not active (failing)
fix: hidden data is not active, so a hovered dataset fades out when h…
fix: hidden data is not active, so a hovered dataset fades out when h…