- npm install react-highcharts –save 安装highcharts 或者直接在StackBlitz — Online编辑器的左侧DEPENDENCIES 中添加 highcharts ,StackBlitz会自动添加依赖,
import Highcharts from 'highcharts'引入highcharts - 添加玫瑰图必需的两个文件 data.js和highcharts-more.js
import HighchartMore from 'highcharts/highcharts-more';
import HighchartsData from 'highcharts/modules/data'
// 添加data.js
HighchartsData(Highcharts);
// 添加highcharts-more
HighchartMore(Highcharts);
- 组件中渲染了table和chart的容器之后 在componentDidMount或者componentDidUpdate中获取chart的实例
render() {
return (
<div>
<Hello name={this.state.name} />
{table}
<div ref='chart'></div>
</div>
);
}
componentDidMount(){
// options 是图表的配置
this.chart=new Highcharts['Chart'](this.refs.chart,options)
}
参考
本文介绍了如何在React应用中利用highcharts库创建玫瑰图。首先,通过npm安装react-highcharts,或者在StackBlitz在线编辑器中添加依赖。接着,引入必要的data.js和highcharts-more.js文件。在组件的生命周期方法中,如componentDidMount或componentDidUpdate,获取图表实例以进行渲染。提供了完整的代码链接和相关参考资料。

872

被折叠的 条评论
为什么被折叠?



