reactjs / react-chartjs

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

Calling getBarsAtEvent fails #28

Closed sbowman closed 9 years ago

sbowman commented 9 years ago

Whenever I try to call getBarsAtEvent, I get the error: "Uncaught TypeError: Cannot read property 'apply' of undefined".

I've got this JSX:

<ReactChart.Bar ref="placementsGraph" name="test" data={chartData} options={this.chartOptions} className="placements-chart" onClick={this.chartClicked}/>

In my chartClicked method, I call:

chartClicked: function(event) {
  console.log('Clicked!', this.refs.placementsGraph.getBarsAtEvent(event));
}

According to the error, this bit of code in core.js is failing:

function extra(type) {
  classData[type] = function() {
    this.state.chart[name].apply(this.state.chart, arguments);
  };
}

I put a few debug messages in there, and "name" is blank, so this.state.chart[name] is undefined. What exactly is this bit of code trying to do?

sbowman commented 9 years ago

This will work, however:

this.refs.placementsGraph.state.chart.getBarsAtEvent(event)
joshhornby commented 9 years ago

@sbowman That seems the only way to get the function yes.