Echarts的基本使用

' 1.先引入Echarts

npm i echarts

2.导入echarts

import * as echarts from echarts

3.定义一个div

<div class='box' style='width:500px;height:500px'></div>
//定义一个Echarts图表的储存空间要定义样式宽和高


4.在script中获取dom节点

import * as echarts from 'echarts'
import { ref, onMounted } from 'vue'

// 定义图表的配置选项
const option = {
  tooltip: {
    trigger: 'item'
  },
  legend: {
    top: '5%',
    left: 'center'
  },
  series: [
    {
      name: 'Access From',
      type: 'pie',
      radius: ['40%', '70%'],
      avoidLabelOverlap: false,
      itemStyle: {
        borderRadius: 10,
        borderColor: '#fff',
        borderWidth: 2
      },
      label: {
        show: false,
        position: 'center'
      },
      emphasis: {
        label: {
          show: true,
          fontSize: 40,
          fontWeight: 'bold'
        }
      },
      labelLine: {
        show: false
      },
      data: [
        { value: 1048, name: 'Search Engine' },
        { value: 735, name: 'Direct' },
        { value: 580, name: 'Email' },
        { value: 484, name: 'Union Ads' },
        { value: 300, name: 'Video Ads' }
      ]
    }
  ]
}

// 在组件挂载时初始化图表
onMounted(() => {
  // 获取图表容器元素
  const box1 = document.querySelector('.box')
  // 初始化ECharts实例
  const mayCart = echarts.init(box1)
  // 设置图表的配置选项
  mayCart.setOption(option)
})

5.图表就能正常显示了

  • 5
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值