uniapp小程序使用echarts

1、引入插件

在Dcloud插件市场下载echarts插件:插件地址

2、页面使用简单示例:

javascript 复制代码
<template>
	<view class="pie-view flex-center">
		<view style="width: 100%; height: 600rpx">
			<l-echart ref="chartRef" @finished="init"></l-echart>
		</view>
	</view>
</template>

<script>
import * as echarts from '@/uni_modules/lime-echart/static/echarts.min';
export default {
	components: {
	},
	data() {
		return {
			option: {
				color: ['#93beff', '#507afc', '#fac858'],
				tooltip: {
					trigger: 'item',
					formatter: '{a} {b}: {c} ({d}%)'
				},
				legend: {
					left: 'center',
					top: '0%',
				},
				series: [
					{
						type: 'pie',
						radius: '40%',
						avoidLabelOverlap: false,
						itemStyle: {
							normal: {
								label: {
									show: true,
									formatter: function (params) {
										const { name, value, percent } = params;
										return `${name}:\n\n${value} (${percent}%)`;
									}
								},
							}
						},
						labelLine: {
							show: true,
							length: 10,
							length2: 10
						},
						data: [
							{ value: 1, name: '已验收' },
							{ value: 2, name: '已整改' },
							{ value: 3, name: '未整改' },
							{ value: 4, name: '延期' },
							{ value: 5, name: '超期' }
						]
					}
				]
			},
		}
	},
	onLoad() {
		this.init();
	},
	mounted() {
	},
	methods: {
		async init() {
			// chart 图表实例不能存在data里
			const chart = await this.$refs.chartRef.init(echarts);
			chart.setOption(this.option);
		},
	}
}
</script>

<style scoped lang="scss">
.flex-center {
	display: flex;
	align-items: center;
}
.pie-view {
	padding-top: 30rpx;
	width: 100%;
	height: 640rpx;
	border-radius: 16rpx;
	background: #FFFFFF;
	box-shadow: 0px 4rpx 12rpx 0px rgba(0, 0, 0, 0.3);
	justify-content: center;
}
</style>
  1. 完整教程可以直接看lime-echart: 百度图表 echarts,uniapp、taro 使用 echarts 图表,全面兼容各平台小程序、H5、APP、Nvue
相关推荐
博、、1 分钟前
智慧场馆解决方案小程序系统:从架构设计到部署实践
小程序
circuitsosk4 分钟前
任务规划器的三种范式对比:ReAct、Plan-and-Execute 与 Tree-of-Thought 在真实业务中的取舍
前端·javascript·python·react.js·llm·ai agent
hzxpaipai1 小时前
企业官网技术架构拆解:前端、后台、数据库、服务器如何协同
前端·数据库·架构
深念Y3 小时前
Lenovo XiaoXinAir 14 — 性能模式切换
前端·网络
计算机魔术师4 小时前
Meta突然杀进第一梯队:一个新模型,把AI推理成本打下来8倍
前端
lhldsg4 小时前
智慧场馆解决方案小程序开发实战:从架构设计到部署指南
java·小程序·uni-app
IT_陈寒4 小时前
Redis缓存雪崩把我坑惨了,这次长记性了
前端·人工智能·后端
维双云4 小时前
配送小程序怎么做?从下单到配送全流程功能拆解。
小程序
风骏时光牛马4 小时前
提示词工程:大模型效能挖掘与指令设计实战
前端