Reputation: 677
I am using react-plotly.js library to plot histogram. I need to download the graph as a png file. I saw a document on how to do it in plotly.js library. Can someone help me to figure out how to do it in react-plotly.js library. Thanks in advance :)
Upvotes: 2
Views: 2349
Reputation: 41
if you have list of plotly charts in react inside an element, having id as "chart-container", then use the following code to download the graph as png, which can be called on any button click event.
let ele = document.getElementById('chart-container').getElementsByClassName('modebar');
for (var i = 0; i < ele.length; i++) {
ele[i].getElementsByClassName('modebar-btn')[0].click();
}
Upvotes: 0
Reputation: 1209
just use this method to save png file
downloadGraph(fileName) {
if(this.graphPlotted) {
Plotly.downloadImage(this.graphPlotted, {format: 'png', filename: fileName})
}
}
Upvotes: 3