vue3 echars图表(饼状图)

简介: vue3 echars图表(饼状图)
<script lang="ts" setup>
import { ref, onMounted } from "vue";
import * as echarts from "echarts";
const main = ref(); // 使用ref创建虚拟DOM引用,使用时用main.value
onMounted(() => {
  init();
});
function init() {
  // 基于准备好的dom,初始化echarts实例
  const myChart = echarts.init(main.value);
  const schoolData = [
    {
      name:'张三',
      value:4253
    },
    {
      name:'李四',
      value:5691
    },
    {
      name:'王五',
      value:4536
    },
    {
      name:'赵六',
      value:4369
    },
    {
      name:'周七',
      value:5124
    }]
  // 指定图表的配置项和数据
  const option = {
    title: {
      text: '个人存款',
      left: 'center'
    },
    tooltip: {
      trigger: 'item',
      formatter: '<br/>{b} : {c} ({d}%)'
    },
    legend: {
      orient: 'vertical',
      left: 'left',
      data: []
    },
    series: [
      {
        type: 'pie',
        radius: '55%',
        center: ['50%', '60%'],
        data: [{ value: 335, name: '' }]
      }
    ]
  };
// 赋值
  option.series = [
  {
    type: 'pie',
    radius: '55%',
    center: ['50%', '60%'],
    // data: res.data.map((v) => {
    //   return { name: v.name, value: v.value }
    // })
    data: schoolData,
  }
]
// 赋值
// option.legend = [
//   {
//    data: schoolData.map((a) => a.name)
//   }
// ]
// 赋值
option.legend.data = schoolData.map((a) => a.name)
  // 使用刚指定的配置项和数据显示图表。
  myChart.setOption(option);
}
</script>
<template>
  <div ref="main" style="width: 100%; height: 400px"></div>
</template>
相关文章
|
3天前
|
JavaScript 定位技术 API
在 vue3 中使用高德地图
在 vue3 中使用高德地图
9 0
|
3天前
vue3 键盘事件 回车发送消息,ctrl+回车 内容换行
const textarea = textInput.value.textarea; //获取输入框元素
13 3
|
6天前
|
JavaScript 前端开发 CDN
vue3速览
vue3速览
18 0
|
6天前
|
设计模式 JavaScript 前端开发
Vue3报错Property “xxx“ was accessed during render but is not defined on instance
Vue3报错Property “xxx“ was accessed during render but is not defined on instance
|
6天前
|
JavaScript 前端开发 安全
Vue3官方文档速通(下)
Vue3官方文档速通(下)
16 0
|
6天前
|
JavaScript API
Vue3 官方文档速通(中)
Vue3 官方文档速通(中)
22 0
|
6天前
|
缓存 JavaScript 前端开发
Vue3 官方文档速通(上)
Vue3 官方文档速通(上)
32 0
|
6天前
Vue3+Vite+Pinia+Naive后台管理系统搭建之五:Pinia 状态管理
Vue3+Vite+Pinia+Naive后台管理系统搭建之五:Pinia 状态管理
10 1
|
6天前
Vue3+Vite+Pinia+Naive后台管理系统搭建之三:vue-router 的安装和使用
Vue3+Vite+Pinia+Naive后台管理系统搭建之三:vue-router 的安装和使用
13 0
|
6天前
Vue3+Vite+Pinia+Naive后台管理系统搭建之二:scss 的安装和使用
Vue3+Vite+Pinia+Naive后台管理系统搭建之二:scss 的安装和使用
11 0