React-chartjs-2: getDatasetAtEvent(e)

Created on 9 Nov 2016  路  6Comments  路  Source: reactchartjs/react-chartjs-2

I need to fetch data when clicked on specific point on Line chart. This has been implemented on chart.js by this function getDatasetAtEvent(e). Any hint or help will be most appreciate?

Most helpful comment

Hey @selimovicz ,

This should be solved in 1.5.1. Just get it from npm.
Usage:

<Bar
  data={data}
  width={100}
  height={50}
  getDatasetAtEvent={dataset => console.log(dataset)}
  options={{
    maintainAspectRatio: false
  }}
/>

Let me know how it goes.

Edit: And reopen the task if needed 馃槃

All 6 comments

hey @selimovicz ,

Will try to implement it this week.

thanks for patience.

@gor181 great, I appreciate that.

Hey @selimovicz ,

This should be solved in 1.5.1. Just get it from npm.
Usage:

<Bar
  data={data}
  width={100}
  height={50}
  getDatasetAtEvent={dataset => console.log(dataset)}
  options={{
    maintainAspectRatio: false
  }}
/>

Let me know how it goes.

Edit: And reopen the task if needed 馃槃

Zdravo @gor181 , prvo hvala na brzom odgovoru :)

I found much more useful the following function: getElementAtEvent(), by using it I got single ChartElement with a bunch of object properties that are not my concern at the moment. But I couldn't find the way how to get X and Y value on that point, like it has been explained here: http://stackoverflow.com/questions/25514802/how-to-add-an-on-click-event-to-my-line-chart-using-chart-js.

I found the answer here: http://stackoverflow.com/a/37123117/1452505.

Thanks anyway.
Hvala.

This should _really_ be in the documentation! If I put together a PR, can it get added?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

LuizMoreira picture LuizMoreira  路  3Comments

flavz27 picture flavz27  路  5Comments

alexchoiweb picture alexchoiweb  路  3Comments

nealoke picture nealoke  路  5Comments

jbbae picture jbbae  路  5Comments