Click events on Pie Charts in Chart.js

后端 未结 10 2112
失恋的感觉
失恋的感觉 2020-11-28 03:29

I\'ve got a question regard Chart.js.

I\'ve drawn multiple piecharts using the documentation provided. I was wondering if on click of a certain slice of one of the

10条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-28 03:53

    Chart.js 2.0 has made this even easier.

    You can find it under common chart configuration in the documentation. Should work on more then pie graphs.

    options:{
        onClick: graphClickEvent
    }
    
    function graphClickEvent(event, array){
        if(array[0]){
            foo.bar; 
        }
    }
    

    It triggers on the entire chart, but if you click on a pie the model of that pie including index which can be used to get the value.

提交回复
热议问题