chartjs-plugin-datalabels icon indicating copy to clipboard operation
chartjs-plugin-datalabels copied to clipboard

Click listener calls chart onClick function

Open vasyl-shumskyi opened this issue 4 years ago • 2 comments

Click listener invokes two onclick events:

  1. one for data label
  2. and the next one for chart onClick function.

Does anyone know how to prevent chart onClick event if data-label has been clicked? For now, they are just called both.

I have added event.stopPropagation() to data-labels click function but it didn't work

Data Labels plugin config:

        listeners: {
            click: context => {
                event.stopPropagation()
                var name = context.chart.data.labels[context.dataIndex]
                alert(name)
            }
          }

Chart configuration

options: {
            onClick: click_chart 
}

vasyl-shumskyi avatar Feb 05 '21 21:02 vasyl-shumskyi

@vasyl-shumskyi can you create a codepen that reproduces this behavior so it's easier for us to debug?

simonbrunel avatar Feb 06 '21 15:02 simonbrunel

Can be reproduced here: https://jsfiddle.net/simonbrunel/rws67nkp/9/

simonbrunel avatar Aug 03 '22 07:08 simonbrunel