reactjs / react-chartjs

common react charting components using chart.js
MIT License
2.93k stars 301 forks source link

How to use getBarsAtEvent? #125

Closed n3ssi3 closed 8 years ago

n3ssi3 commented 8 years ago

Hey

I am trying to add an onClick function for my Charts (f.e. BarChart). How can I access functions from BarChart when using BarChart only as a component?

My current code snippet:

onClickFunction: function (e) {
    // let activeBars = (e.type !== 'mouseout') ? this.getBarsAtEvent(e) : [];
},

render: function () {
    return (<BarChart ref="charts1" data={data} options={chartOptions} onClick={this.onClickFunction}/>)
}

Obviously "this" in my onclick function is undefined, but there should be a way to access that, shouldn't it?

Thanks, Vanessa

ledsun commented 8 years ago

You can access the chart by this.refs.chart1.

Like:

onClickFunction: function (e) {
    let activeBars = this.refs.charts1.getBarsAtEvent(e);
},
n3ssi3 commented 8 years ago

Super, thanks