小伙伴们,你们好,我是老寇,跟我一起学习uniapp怎么基础echart图表
安装软件
导入Echarts
echart推荐使用lime-echart
安装echarts
npm install echarts --save
npm install echarts-stat --save
导入lime-echart插件
例子展示
创建page/pie.vue【vue3写法】
<template>
<view style="height: 750rpx">
<lEchart ref="chartRef"></lEchart>
</view>
</template>
<script setup>
import { ref, onMounted } from 'vue';
import * as echarts from 'echarts';
import lEchart from '@/uni_modules/lime-echart/components/l-echart/l-echart.vue';
const chartRef = ref(null);
onMounted(() => {
// 确保组件已经挂载后再初始化
if (chartRef.value) {
chartRef.value.init(echarts, (chart) => {
const option = {
title: {
text: '某站点用户访问来源',
subtext: '纯属虚构',
left: 'center'
},
tooltip: {
trigger: 'item'
},
legend: {
orient: 'vertical',
left: 'left',
},
series: [
{
name: '访问来源',
type: 'pie',
radius: '50%',
data: [
{ value: 1048, name: '搜索引擎' },
{ value: 735, name: '直接访问' },
{ value: 580, name: '邮件营销' },
{ value: 484, name: '联盟广告' },
{ value: 300, name: '视频广告' }
],
emphasis: {
itemStyle: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: 'rgba(0, 0, 0, 0.5)'
}
}
}
]
};
chart.setOption(option);
});
}
});
</script>
配置page.json
{
"path": "pages/index/pie",
"style": {
"navigationBarTitleText": "饼图"
}
}
运行效果
更多例子
我是老寇,我们下次再见啦!