vue3使用Echarts

首先安装Echarts

npm install echarts

 在需要使用的页面引入Echarts

import * as echarts from 'echarts';

设置一个容器

<div ref="chart" style="height: 400px;width: 100%;"></div>

使用echarts

const chart = ref()
const data33 = ref([150, 230, 224, 218, 135, 147, 360])

const init = () => {
  const myChart = echarts.init(chart.value);

  window.addEventListener('resize', function () {
    myChart.resize();
  });//动态设置echarts的大小

  let option = {
    xAxis: {
      type: 'category',
      data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
    },
    yAxis: {
      type: 'value'
    },
    series: [
      {
        data: data33.value,
        type: 'line'
      }
    ]
  };
  myChart.setOption(option,);

}

onMounted(() => {
  init() //调用
})

猜你喜欢

转载自blog.csdn.net/qq_43319351/article/details/131510904