首页 > 其他 > 详细

React中使用echarts

时间:2018-08-25 13:43:24      阅读:407      评论:0      收藏:0      [点我收藏+]

1.安装相关的依赖:

cnpm i react-for-echarts -S

cnpm i echarts -S

2.使用方法:

页面引入:

import ReactEcharts from ‘echarts-for-react‘;

1).使用组件方式

class EchartsTest extends Component{

  render(){

        const option = {
            xAxis: {
                type: ‘category‘,
                data: [‘Mon‘, ‘Tue‘, ‘Wed‘, ‘Thu‘, ‘Fri‘, ‘Sat‘, ‘Sun‘]
            },
            yAxis: {
                type: ‘value‘
            },
            series: [{
                data: [820, 932, 901, 934, 1290, 1330, 1320],
                type: ‘line‘
            }]
        };
    return(
      <ReactEcharts  option={option} style={{height:‘200px‘,width:‘100%‘}}/>
    )
  }
}

2).echarts相关的配置项目

const option = {
  xAxis: {
    type: ‘category‘,
    data: [‘Mon‘, ‘Tue‘, ‘Wed‘, ‘Thu‘, ‘Fri‘, ‘Sat‘, ‘Sun‘]
  },
  yAxis: {
    type: ‘value‘
  },
  series: [{
    data: [820, 932, 901, 934, 1290, 1330, 1320],
    type: ‘line‘
  }]
};
const EchartsTest =()=>(
    <ReactEcharts
        option={option}
        style={{height:‘220px‘,width:‘100%‘}}
    ></ReactEcharts>
);

最后导出

export default EchartsTest;

 

React中使用echarts

原文:https://www.cnblogs.com/fangyinghua/p/9533330.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!