I'm working on a project with a chart.js pie. The final idea is to make the pie keep the hover animation to show that this part is activated for a search on a table until the search is reset via a button.
The pie normally shows the animation when hover and hide when mouse leave. I would like to know how to make the hover animation stay on if mouse click on when hovering over a part of the pie. I'm trying to highlight a "selected" slice as being hovered.
I manage to get the information about the click, but for the animation, I don't manage to make the “hovering” animation stay on.
const foods = [
{ value: 60, label: 'Orange' },
{ value: 40, label: 'Banana' },
{ value: 20, label: 'Strawberry' },
];
const data = {
labels: foods.map(food => food.label),
datasets: [
{
label: 'Foods',
data: foods.map(food => food.value),
backgroundColor: [
'rgba(255, 99, 132, 0.2)',
'rgba(54, 162, 235, 0.2)',
'rgba(255, 206, 86, 0.2)',
],
hoverBackgroundColor: [
'rgba(255, 99, 132, 1)',
'rgba(54, 162, 235, 1)',
'rgba(255, 206, 86, 1)',
],
borderWidth: 0,
hoverOffset: 4
},
],
};
const ctx = document.getElementById('myChart').getContext('2d');
new Chart(ctx, {
type: 'pie',
data
});
.myChartDiv {
max-width: 600px;
max-height: 400px;
}
<script src="https://npmcdn.com/chart.js@latest/dist/chart.umd.js"></script>
<div class="myChartDiv">
<canvas id="myChart" width="600" height="400"></canvas>
</div>
If anybody already made the hover display stay on, I would love to know how.