0👍
The best way to do this is to change the color of the section clicked.
In your markup:
<canvas ...chart-colors="$scope.colors" chart-click="$scope.clickFn"...> </canvas>
In your controller:
$scope.clickFn = function(points, event) {
if (!points || !points.length || !points.length > 0) { return; }
var indexClicked = points[0]._index;
$scope.colors[indexClicked] = '#9a9a9a' //your clicked color code
}
This way, the next time your scope digest occurs, the chart will be re-drawn with your clicked portion with your new highlighted color.
You can do other things with this too, like color everything NOT clicked, disable the animation so it isn’t bouncy on color change, etc. But the above will solve your problem.
- [Chartjs]-How to make react-chartjs-2 responsive on mobile?
- [Chartjs]-How to stop resizing chart.js in case hovered and out of boundaries?
Source:stackexchange.com