I am developing a React app which has ReCharts for creating bargraphs. Besides showing in the screen I want to export the graphic to a file to store in database.
As I saw in other question here, to export a chart I can do:
let chartSVG = ReactDOM.findDOMNode(this.currentChart).children[0];
let svgBlob = new Blob([chartSVG.outerHTML], {type: "text/html;charset=utf-8"});
However I am failing to insert the DOM node name of the chart (this.currentChart). The way the other question uses doesn't work for me:
Uncaught TypeError: Cannot set property 'currentChart' of undefined
I tried the component name inside findDOMNode, but got error:
Uncaught Error: Element appears to be neither ReactComponent nor DOMNode
My graph component is in another file and is declared inside my top level render() function as below:
render () {
return(
<div ...
...
<br />
<MyBarChart
id="currentChart"
ref={(chart) => this.currentChart = chart}
data={this.props.dataGraph}
/>
<br />
...
</div>
);
}
How do I call ReactDOMNode to be able to export the chart?