I am trying to export the graph to png programmatically, and as part of the standard plotly.js there is the toImage function referenced here: https://plot.ly/javascript/plotlyjs-function-reference/#plotlytoimage
I am importing import Plot from "react-plotly.js"
and I am using it like so.
<Plot
data={[
{
x: this.state.data.x,
y: this.state.data.y,
type: "scatter",
size: 1,
mode: "markers",
marker: { color: "red" }
}
]}
layout={{
showlegend: false,
autosize: true,
margin: { t: 0, r: 0, b: 0, l: 0 }
}}
style={{ width: "100%", height: "100%", maxHeight: "30vh" }}
/>
My question is how can I call the toImage function from a react component like this? I read about const Plot = createPlotlyComponent(Plotly);
which suggests that I can create a custom Plot object, but that doesn’t seem to expose a toImage
function (and in that case, i’m not sure where Plotly
should come from.
Any help greatly appreciated.
I know this is against general forum rules, so apologies for asking multiple questions in advance, if I also want to programmatically add more plots, I think I need to append to the data
object array, but again, I cant find how to do that programmatically either?