Chart.js: How to change doughnut segment color on click?

Created on 30 Nov 2016  路  2Comments  路  Source: chartjs/Chart.js

Hello!

I need change dougnut segment color on click. I try to use onClick event for this purpose. But settting of new backgroundColor has no effect on chart. I'm not sure, that my way is correct. But I guess, there is no such feature in chart.js.

There is my event handler:

options: {
    onClick: function(evt, elements) {
        if (elements && elements.length) {
            console.log(elements[0]._model.backgroundColor);
            //elements[0]._model.backgroundColor = "#ff9933" - it doesn't work
            }
    }
}

Here is my plunk for convenience.

Thanks!

support

Most helpful comment

@greatromul here's how to do it: http://plnkr.co/edit/ESLfihjIYRNLFjFpk5Jd?p=preview

All 2 comments

@greatromul here's how to do it: http://plnkr.co/edit/ESLfihjIYRNLFjFpk5Jd?p=preview

@etimberg Great Job, with it!!
But there is some issue, unable to remove label from legends which works fine otherwise

Was this page helpful?
0 / 5 - 0 ratings