在react中使用echarts表格

我们在使用echarts表格时我们先安装对应的包

npm i echarts --save 

并且引入echarts包中我们所需要的东西

// 引入 ECharts 主模块
import echarts from 'echarts/lib/echarts';
// 引入柱状图 bar代表 柱状图   line 代表线状图  pie 代表饼图
// import  'echarts/lib/chart/bar';
import  'echarts/lib/chart/line';
// 引入提示框和标题组件
import 'echarts/lib/component/tooltip';
import 'echarts/lib/component/title';

然后在render中创建一个div

<div id="main" style={{ width: 400, height: 400 }}></div>

我们最后在ComponentDidMount中放入我们echarts所使用的数据

componentDidMount(){
    // 基于准备好的dom,初始化echarts实例
    var myChart = echarts.init(document.getElementById('main'));
    // 绘制图表
    myChart.setOption({
        // title: { text: 'ECharts 入门示例' },
        // tooltip: {},
        // xAxis: {
        //     data: ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
        // },
        // yAxis: {},
        // series: [{
        //     name: '销量',
        //     type: 'bar',
        //     data: [5, 20, 36, 10, 10, 20]
        // }]
        title:{
          text:'用户骑行订单',
          x:'center'
        },
        tooltip:{
          trigger:'axis',
        },
        xAxis:{
          data:['周一','周二','周三','周四','周五','周六','周日']
        },
        yAxis:{
          type:'value'
        },
        series:[
          {
            name:'OFO订单量',
            type:'line',   //这块要定义type类型,柱形图是bar,饼图是pie
            data:[1000,2000,1500,3000,2000,1200,800]
          }
        ]
    });
  }

猜你喜欢

转载自www.cnblogs.com/xiaoxiaoxiongmao/p/12323623.html