react引入echart图表 超简单 一看就会~~

1 npm install echarts --save

2 按需导入柱状图

 // echars

import echarts from 'echarts/lib/echarts';

// 柱状图

import 'echarts/lib/chart/bar';

import 'echarts/lib/component/tooltip';

import 'echarts/lib/component/title';

import 'echarts/lib/component/legend';

import 'echarts/lib/component/toolbox';

import 'echarts/lib/component/markPoint';

import 'echarts/lib/component/markLine';

3、export default class index extends Component {

componentDidMount() {

    // 实例化

    var myChart = echarts.init(this.refs.main);


    myChart.setOption(this.getOption());


  }

// echarts数据

  getOption=()=>{

   let option = {

      title: {

          text: 'ECharts 入门示例'

      },

      tooltip: {},

      legend: {

          data:['销量']

      },

      xAxis: {

          data: ["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"]

      },

      yAxis: {},

      series: [{

          name: '销量',

          type: 'bar',

          data: [5, 20, 36, 10, 10, 20]

      }]


  };

    return option  

  }

render(){

 <div ref="main" style={{ width: '100%', height: 500 }}></div>

}


}

这样一个简单的图表就出来了~~~

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。