当前位置: 首页 > 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.lqws.cn/news/601507.html

相关文章:

  • imx6ull芯片中断机制6.24-6.25
  • Redis为什么是单线程
  • UE5.6 官方文档笔记 [1]——虚幻编辑器界面
  • 6.2 实现文档加载和切分和简易向量数据库的功能
  • browser-tools-mcp + excel-mcp-server + cursor 实现读取网页信息自动写入Excel
  • SQL Server 进阶:递归 CTE+CASE WHEN 实现复杂树形统计(第二课)
  • 读Vista
  • Python实例题:基于 Python 的简单爬虫与数据可视化
  • Hibernate中save与saveOrUpdate的差异解析
  • HDMI2.1 FRL流控 概览
  • Linux驱动学习day13(同步与互斥)
  • AI的未来:人类会被取代,还是变得更强大?
  • HTTPS安全传输时采用的顶级阳谋
  • 【Maven 】 <resources> 配置中排除 fonts/** 目录无效,可能是由于以下原因及解决方案:
  • 编写rosbag脚本记录雷达与imu数据包
  • 学习经验分享【41】YOLOv13:基于超图增强自适应视觉感知的实时目标检测
  • day41简单CNN
  • 【Web3.0】Web1.0、Web2.0和Web3.0有哪些区别联系?
  • MySQL 8.4 备份与恢复完全指南
  • win11,visual studio 2022,配置dcmtk,opencv
  • 【记录】Word|Word创建自动编号的多级列表标题样式
  • 结构体实战:用Rust编写矩形面积计算器
  • Linux安装JDK和Maven
  • vue中scss下载方式与引入方式
  • 【深度学习1】ModernBert学习
  • 【IP 潮玩行业深度研究与学习】
  • SpringCloud系列(45)--SpringCloud Bus简介
  • 基于Spring Cloud微服务架构的API网关方案对比分析
  • 快应用(QuickApp)技术解析与UniApp跨端开发生态探秘优雅草卓伊凡
  • 振荡电路Multisim电路仿真实验汇总——硬件工程师笔记