react-chartjs icon indicating copy to clipboard operation
react-chartjs copied to clipboard

Get points on event returns empty array.

Open selimovicz opened this issue 8 years ago • 2 comments

handleOnClick(event) { console.log(this.refs.lineChart.getPointsAtEvent(event)); }

As title states, this console log always returns empty array even though graph is showing a lot of data.

selimovicz avatar Oct 27 '16 14:10 selimovicz

are you extending the class ? my this.refs only has { canvass: ... } I am not sure how you are able to do this otherwise.

It would help to debug it if you post more code.

Jareechang avatar Oct 28 '16 18:10 Jareechang

You can make use of extensions to get a reference to this canvas.

const Chart = require('react-chartjs');

class YourChart extends Chart.Line {
    constructor(props) {
        super(props);        
    }   
    componentDidMount() {
        this.initializeChart(this.props);
        const chart = this;
        this.refs.canvass.onclick = function(e) {
            console.log(chart.getPointsAtEvent(e));
        }
    }   
};

Jareechang avatar Oct 28 '16 18:10 Jareechang