vue3中关于echars的使用

今天介绍一个好用的插件echars,一个可视化插件Apache ECharts

一、使用步骤

1、安装

npm install echarts --save

2、导入

import * as echarts from 'echarts'

3、正式使用

echars的使用非常的简单,直接点击官网有现成的代码的可用

代码示例

<template>
	<div ref="chart1Ref" :style="{ width: '430px', height: '600px' }"></div>
</template>

<script setup lang="ts">
import * as echarts from 'echarts'
import { reactive, ref, onMounted } from 'vue'

onMounted(() => {
	init()
})
const chart1Ref = ref()

const init = () => {
	useEcharApi().then(res => {
		var myChart = echarts.init(chart1Ref.value)
		var option = {
			legend: {
				top: 'bottom'
			},
//用于提供一些常用的功能按钮,方便用户进行交互和操作
			toolbox: {
				show: true,
				feature: {
					mark: { show: true },
					dataView: { show: true, readOnly: false },
					restore: { show: true },
					saveAsImage: { show: true }
				}
			},
//用于定义图表的数据系列
			series: [
				{
					name: 'xxx',
					type: 'pie',
					radius: [25, 125],
					data: [
						{ value: res.data[1], name: 'xxx' },
						{ value: res.data[2], name: 'xxxx' },
						{ value: res.data[3], name: 'xxxx' }
					],
					center: ['50%', '50%'],
					roseType: 'area',
					itemStyle: {
						borderRadius: 8
					}
				}
			]
		}
//使图表根据新的 option 配置进行重新渲染,从而呈现出最新的图表效果
		option && myChart.setOption(option)
	})
}

</script>

上述代码后端穿入的为一个map集合的三条记录,最终的数据依据自己想要展示的不同进行改变。

相关推荐

  1. Vue3 ts使用echarts

    2023-12-11 06:58:05       38 阅读
  2. vue3 学习笔记17 -- echarts使用

    2023-12-11 06:58:05       28 阅读
  3. Vue项目使用echarts教程

    2023-12-11 06:58:05       38 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2023-12-11 06:58:05       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2023-12-11 06:58:05       100 阅读
  3. 在Django里面运行非项目文件

    2023-12-11 06:58:05       82 阅读
  4. Python语言-面向对象

    2023-12-11 06:58:05       91 阅读

热门阅读

  1. Linux数据库Mysql增删改查

    2023-12-11 06:58:05       60 阅读
  2. esp32服务器与android客户端的tcp通讯

    2023-12-11 06:58:05       59 阅读
  3. rust宏(macro)详解

    2023-12-11 06:58:05       67 阅读
  4. MYSQL数据类型详解

    2023-12-11 06:58:05       61 阅读
  5. 数组 注意事项

    2023-12-11 06:58:05       49 阅读
  6. GraphSAGE

    GraphSAGE

    2023-12-11 06:58:05      51 阅读
  7. C/C++语言的安全编码规范

    2023-12-11 06:58:05       53 阅读
  8. 计算机视觉-机器学习-人工智能顶会 会议地址

    2023-12-11 06:58:05       49 阅读
  9. 【求职】外企德科-网易游戏测试面试记录

    2023-12-11 06:58:05       55 阅读
  10. git commit语义规范

    2023-12-11 06:58:05       54 阅读