reactjs / react-chartjs

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

v2: support getElementAtEvent and getElementsAtEvent #120

Open ledsun opened 8 years ago

ledsun commented 8 years ago

I want to get elements by click events.

I can get elements:

const App = React.createClass({
  handleClick(e) {
    const chart = this.Bar.getChart()
    chart.getElementAtEvent(e)
  },
  render() {
    return (<Bar data={chartData} options={chartOption} onClick={this.handleClick} ref={(ref) => this.Bar = ref}/>)
  }
})

But I want like getBarsAtEvent at v1:

const App = React.createClass({
  handleClick(e) {
    const chart = this.Bar.getElementAtEvent(e)
  },
  render() {
    return (<Bar data={chartData} options={chartOption} onClick={this.handleClick} ref={(ref) => this.Bar = ref}/>)
  }
})

Please refer the Prototype Methods section in the Chart.js document.

kncs commented 7 years ago

As far as I understand your point, bar.js need to be updated to :

var vars = require('./core');

module.exports = vars.createClass('Bar', ['getElementAtEvent']);

I think that should do the job :)