Chart.js: Bar Chart Click Events

前端 未结 8 942
梦如初夏
梦如初夏 2020-12-07 18:56

I\'ve just started working with Chart.js, and I am getting very frustrated very quickly. I have my stacked bar chart working, but I can\'t get the click \"events\" to work.<

8条回答
  •  再見小時候
    2020-12-07 19:42

    Well done! This seems to return the data value being charted though, which in many cases might be possible to appear more than once, thus making it unclear what was clicked on.

    This will return the actual data label of the bar being clicked on. I found this more useful when drilling down into a category.

    chart_config.data.labels[activeElement[0]._index]
    

提交回复
热议问题