MichaelVoelkel / ChartJs2QML

QML adaptor for Chart.js 2.x that supports startup animations and tooltips
MIT License
98 stars 20 forks source link

parameter pass from event is undefined #2

Closed eswizardry closed 4 years ago

eswizardry commented 4 years ago

I would like to get element data when clicking on the point. I have a handler to get the data in the option like below:

chartOptions: {
    return {
        maintainAspectRatio: false,
        responsive: true,
        hoverMode: 'nearest',
        intersect: true,
        title: { display: false},
        onClick: function(evt) {
               console.debug("Click"); // <-- the function is call and print 'click' when I click on the point
                jsChart.getElementsAtEvent(evt); // <-- not success due to 'evt' is undefined
               console.debug(evt);  // <-- 'evt' is undefined
          }
     }
}

Do you have any suggestions on how to get index or data when clicking on the point?

eswizardry commented 4 years ago

Sorry just look the code in Chart.qml and found event is injected by bindEvents. So I can get the index of the point when click by below code

        onClicked: {
            var element = jsChart.getElementsAtEvent(event.mouseEvent)
            console.debug(element[0]._index)
        }

Sorry for make noise here :)

MichaelVoelkel commented 4 years ago

No worries, make all the noise you want :) You were faster in getting the solution that I was in answering, though. Hope, you get some nice results with our adaptor! Cheers, Michael