Javascript Highcharts反应获取图表的Base64 PNG
我希望将一个图表导出传递给一个特别需要PNG或JPG的组件,这样SVG就不能正常工作了 在其他SO答案的帮助下,我能够使用以下代码获得SVG Base64:Javascript Highcharts反应获取图表的Base64 PNG,javascript,reactjs,highcharts,base64,react-pdf,Javascript,Reactjs,Highcharts,Base64,React Pdf,我希望将一个图表导出传递给一个特别需要PNG或JPG的组件,这样SVG就不能正常工作了 在其他SO答案的帮助下,我能够使用以下代码获得SVG Base64: let link = "data:image/svg+xml;base64," + btoa(this.lineChartRef.current.CHART.current.chart.getSVG()); 有没有办法得到PNG base64?或者React中是否有一种有效的方法将此SVG base64转换为PNG 谢谢 多亏@ppota
let link = "data:image/svg+xml;base64," + btoa(this.lineChartRef.current.CHART.current.chart.getSVG());
有没有办法得到PNG base64?或者React中是否有一种有效的方法将此SVG base64转换为PNG
谢谢 多亏@ppotaczek转发了[this SO post][1],我才能够为React创建以下解决方案。希望它能在将来帮助别人
//Start by calling the chart options (using refs) into a variable and JSON stringify
let chartoptions = this.lineChartRef.current.BrokerChart.current.chart.userOptions
chartoptions = JSON.stringify(chartoptions)
//Create a data body with the following parameters
let data = {
options: chartoptions,
filename: 'LineChart',
async: true
}
let url = "https://export.highcharts.com/"
let returnedimageurl = ""
//setState will be called within the Axios return so "This" must
let self = this
axios({
method: 'post',
url: 'https://export.highcharts.com/',
data: data,
})
.then(function (response) {
returnedimageurl= url +response.data
self.setState({
activityChartPng: url
}, self.allowDownload())
})
.catch(function (response) {
//handle error
console.log(response);
});
//The activityChartPvg state can then be passed as props to the React-PDF component
[1]: https://stackoverflow.com/questions/54761784/highcharts-export-multiple-charts-using-jspdf
感谢@ppotaczek转发了[这篇SO帖子][1],我能够为React创建以下解决方案。希望它能在将来帮助别人
//Start by calling the chart options (using refs) into a variable and JSON stringify
let chartoptions = this.lineChartRef.current.BrokerChart.current.chart.userOptions
chartoptions = JSON.stringify(chartoptions)
//Create a data body with the following parameters
let data = {
options: chartoptions,
filename: 'LineChart',
async: true
}
let url = "https://export.highcharts.com/"
let returnedimageurl = ""
//setState will be called within the Axios return so "This" must
let self = this
axios({
method: 'post',
url: 'https://export.highcharts.com/',
data: data,
})
.then(function (response) {
returnedimageurl= url +response.data
self.setState({
activityChartPng: url
}, self.allowDownload())
})
.catch(function (response) {
//handle error
console.log(response);
});
//The activityChartPvg state can then be passed as props to the React-PDF component
[1]: https://stackoverflow.com/questions/54761784/highcharts-export-multiple-charts-using-jspdf
您好@mg2019,请检查这两个线程:并让我知道这是否解决了您的问题。@ppotaczek是的!第一篇帖子确实有用!非常感谢你!您好@mg2019,请检查这两个线程:并让我知道这是否解决了您的问题。@ppotaczek是的!第一篇帖子确实有用!非常感谢你!