通过研究“图表”组件,我能够解决我的问题。图表在包装器下呈现为SVG,因此我要做的就是正确转换以保存为HTML或SVG
// Exports the graph as embedded JS or PNGexportChart(asSVG) { // A Recharts component is rendered as a div that contains namely an SVG // which holds the chart. We can access this SVG by calling upon the first child/ let chartSVG = ReactDOM.findDOMNode(this.currentChart).children[0]; if (asSVG) { let svgURL = new XMLSerializer().serializeToString(chartSVG); let svgBlob = new Blob([svgURL], {type: "image/svg+xml;charset=utf-8"}); FileSaver.saveAs(svgBlob, this.state.uuid + ".svg"); } else { let svgBlob = new Blob([chartSVG.outerHTML], {type: "text/html;charset=utf-8"}); FileSaver.saveAs(svgBlob, this.state.uuid + ".html"); }}
我正在使用FileSaver.js作为保存提示。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)