echarts可视化图表五步搞定

1.导入echarts:也可以改为导入js文件

import echarts from 'echarts'

2.为图表准备盒子,设置id

 <div id="main" style="width:600px;height:400px;"></div>

3.初始化echart实例

 var myChart = echarts.init(document.getElementById('main'))

4.设置配置项

 // eslint-disable-next-line no-unused-vars
    var option = {
      title: {
        text: 'ECharts 入门示例'
      },
      tooltip: {},
      legend: {
        data: ['销量']
      },
      xAxis: {
        data: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子']
      },
      yAxis: {},
      series: [
        {
          name: '销量',
          type: 'bar',
          data: [5, 20, 36, 10, 10, 20]
        }
      ]
    }

5.展示数据

  myChart.setOption(option)
  刷新你的页面 图表就出来了

猜你喜欢

转载自blog.csdn.net/qq_41792374/article/details/106918296