有没有办法使用 React 执行 SVG 图形的服务器端渲染?



我正在为一个项目使用 Highcharts 和 React,需要支持生成的 SVG 的服务器端渲染。有人可以建议一种方法来做到这一点,以便我获得一个静态渲染的页面,其中包含 png/jpg 的图像?用于查看渲染内容的浏览器不支持 svg。

谢谢。

您可以使用节点模块在 react 中渲染高图表 反应高图表您可以使用以下内容作为官方文档 https://www.npmjs.com/package/react-highcharts

您需要将配置选项传递给反应高图表组件

下面是饼图的示例

_piechartDataLoad() {
return (
{
chart: {
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false,
type: 'pie',
style: {
fontFamily: "-apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Helvetica Neue, Arial, sans-serif",
fontSize: "0.875rem",
fontWeight: "normal",
lineHeight: 1.5,
color: "#263238",
}
},
title: {
text: 'Product with more complaints'
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
format: '<b>{point.name}</b>: {point.percentage:.1f} %',
connectorColor: 'silver'
}
}
},
series: [{
name: 'Brands',
colorByPoint: true,
data: [{
name: 'Chrome',
y: 61.41,
sliced: true,
selected: true
}, {
name: 'Internet Explorer',
y: 11.84
}, {
name: 'Firefox',
y: 10.85
}, {
name: 'Edge',
y: 4.67
}, {
name: 'Safari',
y: 4.18
}, {
name: 'Sogou Explorer',
y: 1.64
}, {
name: 'Opera',
y: 1.6
}, {
name: 'QQ',
y: 1.2
}, {
name: 'Other',
y: 2.61
}]
}]
}
)
}
render(){
return(
<ReactHighcharts config={this._piechartDataLoad} ></ReactHighcharts>
)
}

找到了解决方案。Highcharts有一个现成的解决方案,可以做我想要的事情。它是一个节点/快速服务器,用于使用 PhantomJS 从 highcharts 配置 json 获取 png 响应。https://www.highcharts.com/docs/export-module/setting-up-the-server

最新更新