当前位置: 首页 > news >正文

uniapp+vue3 中使用echart 以及echart文件过大需要分包的记录

使用的是插件市场的lime-echart ,地址:插件市场lime-echart

在这里插入图片描述

直接上代码

<template><view class="container"><view class="chart-container"><view style="width: 700rpx; height: 450rpx"><LEchart ref="chartRef" style="width: 100%"></LEchart></view></view></view>
</template>
<script lang="ts" setup>
import { ref, onMounted, nextTick } from 'vue'
//
import { onUnload } from '@dcloudio/uni-app'
import LEchart from '../../uni_modules/lime-echart/components/l-echart/l-echart.vue'
const echarts = require('../../uni_modules/lime-echart/static/echarts.min.js')const chartRef = ref(null)
const myChart = ref(null)const getOptionData = dates => {const option = {// legend: {//   show: true,//   data: ['分数'],// },tooltip: {trigger: 'item',axisPointer: {type: 'shadow',},confine: true,},grid: {left: '1%',right: '10%',top: '15%',bottom: '5%',containLabel: true,},xAxis: {type: 'category',data: dates,axisLabel: {// interval: 0, // 强制显示所有标签// rotate: 45, // 可选:旋转标签避免重叠// inside: true,// color: '#fff'},axisTick: {show: false,},axisLine: {show: true,lineStyle: {color: '#83bff6',},},z: 10,},yAxis: {type: 'value',min: 0, // 设置y轴最小值为0max: 100, // 设置y轴最大值为100axisLine: {show: true,lineStyle: {color: '#83bff6',},},axisTick: {show: false,},// axisLabel: {//   color: '#999'// },splitLine: {show: true,lineStyle: {type: 'dashed',color: '#83bff6',},},},series: [{markLine: {data: [{ yAxis: 70, name: '及格线' }],lineStyle: {type: 'dashed', // 虚线},label: {show: true,position: 'insideStartTop',formatter: '及格线',},},data: [13, 40, 80, 70, 60, 50, 11, 13, 14, 55],type: 'bar',name: '平均分数',label: {show: true,position: 'top', // 展示在柱子的上方color: '#333',},itemStyle: {color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{ offset: 0, color: '#83bff6' },{ offset: 0.5, color: '#188df0' },{ offset: 1, color: '#188df0' },]),},emphasis: {itemStyle: {color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{ offset: 0, color: '#2378f7' },{ offset: 0.7, color: '#2378f7' },{ offset: 1, color: '#83bff6' },]),},},areaStyle: {show: true,color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{offset: 0,color: '#188df0',},{offset: 1,color: '#fff',},]),},},],color: ['#83bff6'],}return option
}
const getLastNDay = (time, n) => {let arry = []let baseDate = new Date(time)for (let i = n - 1; i >= 0; i--) {let date = new Date(baseDate)date.setDate(date.getDate() - i)let year = date.getFullYear()let mon = (date.getMonth() + 1).toString().padStart(2, '0')let d = date.getDate().toString().padStart(2, '0')arry.push(mon + '.' + d)}return arry
}
onMounted(() => {nextTick(() => {setTimeout(() => {initChart()})})
})
const initChart = async () => {if (!chartRef.value) return// 初始化echartmyChart.value = await chartRef.value.init(echarts)// 默认获取容器尺寸myChart.value.resize()const dates = getLastNDay(new Date(), 10)console.log(dates)const optionData = getOptionData(dates)// 设置true清空echart缓存myChart.value?.setOption(optionData, true)console.log(myChart.value)// myChart.value.
}// 组件销毁时销毁图表实例
onUnload(() => {if (myChart.value) {echarts.dispose(myChart.value)}
})
</script>
<style>
page {height: 100%;
}
.container {height: 100%;display: flex;flex-direction: column;background-color: #f5f6fa;
}.chart-container {height: 400rpx;position: relative;border-bottom: 2rpx solid #e5e5e5;
}</style>

正常使用的话可能会体积过大,所以这里我用了分包,pages.json数据结构如下

在这里插入图片描述

项目结构如下

在这里插入图片描述
在这里插入图片描述

http://www.dtcms.com/a/264275.html

相关文章:

  • 吸烟行为检测数据集介绍-2,108张图片 公共场所禁烟监控 健康行为研究
  • SpringCloud系列(45)--SpringCloud Bus简介
  • UE5 - 制作《塞尔达传说》中林克的技能 - 18 - 磁力抓取器
  • 强化学习【chapter0】-学习路线图
  • Java Selenium反爬虫技术方案
  • 07 Springboot+netty+mqtt服务端实现【重构】
  • 数据结构之带头双向循环链表
  • 苍穹外卖系列问题之Day11_05营业额统计代码开发2 StringUtils.join(dateList,“,“)报错
  • Cross-modal Information Flow in Multimodal Large Language Models
  • 【1.6 漫画数据库设计实战 - 从零开始设计高性能数据库】
  • 2025年主流大厂Java后端面试题主题深度解析
  • 推客系统小程序终极指南:从0到1构建自动裂变增长引擎,实现业绩10倍增长!
  • 快速手搓一个MCP服务指南(九): FastMCP 服务器组合技术:构建模块化AI应用的终极方案
  • 【大模型学习 | BLIP2原理】
  • 「Java流程控制」for循环结构
  • langchain从入门到精通(三十二)——RAG优化策略(八)自查询检索器实现动态数据过滤
  • 腾讯 iOA 零信任产品:安全远程访问的革新者
  • Redis-渐进式遍历
  • Java后端调用外部接口标准流程详解
  • python+uniapp基于微信小程序的PS社区系统
  • 使用D435i运行ORB-SLAM3时,纯视觉模式与视觉-惯性模式的位姿矩阵定义问题探讨
  • 基于SpringBoot + HTML 的网上书店系统
  • 转录组分析流程(六):列线图
  • Kafka 生产者和消费者高级用法
  • c++学习(八、函数指针和线程)
  • EasyExcel实现Excel复杂格式导出:合并单元格与样式设置实战
  • web开发,旅游景点管理系统推荐算法版本demo,基于asp.net,mvc,c#,sql server
  • 编写shell脚本扫描工具,扫描服务器开放了哪些端口(再尝试用python编写一个)
  • Set和Map的解析与应用场景
  • OSPF虚拟链路术语一览:快速掌握网络路由