React-chartjs-2: Retrieve Canvas object

Created on 8 Sep 2016  路  4Comments  路  Source: reactchartjs/react-chartjs-2

With react-chartjs it was possible to retrieve the canvas by using _refs_ like this:

Component:

<Line ref="linegraph" data={chartData} options={chartOptions} />

Code:

const canvas = this.refs.linegraph.getCanvas();

For some reason I cannot do the same with react-charjs-2, what would be the correct way to do that?

Most helpful comment

@RamonBeast Inspecting chart_instance there is no .getCanvas() function but you can get it from chart_instance.chart.ctx

All 4 comments

Hey @RamonBeast ,

Thanks for reporting.
It works as https://github.com/gor181/react-chartjs-2#chart-instance

So in your case it would be:

this.refs.linegraph.chart_instance

Please try and let me know.

Thank you,
Goran

Thank you very much @gor181, I have no idea how I missed that in the home page :/.
I still can't access the canvas anyway. Shouldn't getCanvas() be accessible directly through the chart instance? Like this I:

this.refs.linegraph.chart_instance.getCanvas()

I keep getting:

TypeError: this.refs.linegraph.chart_instance.getCanvas is not a function

Thank you again for helping!

@RamonBeast Inspecting chart_instance there is no .getCanvas() function but you can get it from chart_instance.chart.ctx

Thanks @jiayihu, you are right.

image

@RamonBeast, please check as @jiayihu instructed.
You may also check the image I have just uploaded.

In case you have further questions feel free to reopen the issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

davidcalhoun picture davidcalhoun  路  5Comments

n1c01a5 picture n1c01a5  路  4Comments

alphakennyn picture alphakennyn  路  3Comments

selimovicz picture selimovicz  路  6Comments

alexchoiweb picture alexchoiweb  路  3Comments