uniapp打包安卓 使用echarts插件 柱状折线等...

uniapp打包安卓 使用echarts插件 柱状折线等...

因为安卓端没有dom操作所以要使用 renderjs

直接上代码

html

html 复制代码
<template>
	<view class="content">
		<view
			id="echartsa"
			:prop="viewProp"
			:change:prop="echarts.updateEcharts"
			class="echarts"></view>
	</view>
</template>

js

javascript 复制代码
<script>
	import { showApi } from '../../../api/index.js'; //测试接口
	import { onLoad } from '@dcloudio/uni-app';
	export default {
		data() {
			return {
				name: '',
			};
		},
		mounted() {
			this.getdata(); //测试调用
		},
		methods: {
			async getdata() {
				const res = await showApi();
				this.name = res; //测试数据
			},
		},
		computed: {
			viewProp() {
				return {
					option: this.name, //测试数据
				};
			},
		},
	};
</script>

renderjs

javascript 复制代码
<script module="echarts" lang="renderjs">
	import * as echarts from 'echarts';
	 let myChart
	 export default {
		 data(){
			 return{
			  category:[
	            "2012年",
	            "2013年",
	            "2014年",
	            "2015年",
	            "2016年",
	            "2017年",
	            "2018年",
	          ],
	          dottedBase:[],
	          lineData : [
	            18092, 24045, 32808, 36097, 44715, 50415, 56061, 59521, 18092, 24045, 32808,
	            36097, 44715, 50415, 39867, 44715, 48444, 50415, 50061, 32677, 49521, 32808,
	          ],
	          barData : [
	            4600, 5500, 7500, 8500, 12500, 21500, 23200, 25250, 4600, 5500, 6500, 8500,
	            22500, 21500, 9900, 12500, 14000, 21500, 23200, 24450, 25250, 7500,
	          ],
	          rateData : [],
			  name:''
			 }
		 },
	     mounted() {
	     	// 判断
	         if (typeof window.echarts === 'function') {
	             this.initEcharts()
	         } else {
	             const script = document.createElement('script')
	             script.src = 'static/echarts.min.js'
	             script.onload = this.initEcharts.bind(this)
	             document.head.appendChild(script)
	         }

	     },
	     methods: {
				updateEcharts(newValue, oldValue, ownerInstance, instance) {
						this.name = newValue.option.msg //调用一次
			     },
	        initEcharts() {
				for (var i = 0; i < 33; i++) {
				   var rate = (this.barData[i] / this.lineData[i]) * 100;
				   this.rateData[i] = rate.toFixed(2);
				 }
			    var option = {
	              title: {
	                text: "",
	                x: "center",
	                y: 0,
	                textStyle: {
	                  color: "#B4B4B4",
	                  fontSize: 16,
	                  fontWeight: "normal",
	                },
	              },
	              tooltip: {
	                trigger: "axis",
	                backgroundColor: "rgba(255,255,255,0.1)",
	                axisPointer: {
	                  type: "shadow",
	                  label: {
	                    show: true,
	                    backgroundColor: "",
	                  },
	                },
	              },
	              legend: {
	                data: [this.name, "交易笔数"], //测试数据
	                textStyle: {
	                  color: "#B4B4B4",
	                },
	                top: "7%",
	              },
	              grid: {
	                x: "12%",
	                width: "82%",
	                y: "12%",
	              },
	              xAxis: {
	                name: "时",
	                data: this.category,
	                axisLine: {
	                  lineStyle: {
	                    color: "#B4B4B4",
	                  },
	                },
	                axisTick: {
	                  show: false,
	                },
	              },
	              yAxis: [
	                {
	                  name: "元",
	                  splitLine: { show: false },
	                  axisLine: {
	                    lineStyle: {
	                      color: "#B4B4B4",
	                    },
	                  },

	                  axisLabel: {
	                    formatter: "{value} ",
	                  },
	                },
	                {
	                  name: "笔",
	                  splitLine: { show: false },
	                  axisLine: {
	                    lineStyle: {
	                      color: "#B4B4B4",
	                    },
	                  },
	                  axisLabel: {
	                    formatter: "{value} ",
	                  },
	                },
	              ],
	              series: [
	                {
	                  name: "交易笔数",
	                  type: "line",
	                  smooth: true,
	                  showAllSymbol: true,
	                  symbol: "emptyCircle",
	                  symbolSize: 4,
	                  yAxisIndex: 1,
	                  itemStyle: {
	                    normal: {
	                      color: "#FFE666",
	                    },
	                  },
	                  data: this.rateData,
	                },

	                {
	                  name: this.name, //测试数据
	                  type: "bar",
	                  barWidth: 10,
	                  itemStyle: {
	                    normal: {
	                      barBorderRadius: 10,
	                      color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
	                        { offset: 0, color: "#26FFDB" },
	                        { offset: 1, color: "#0F5C74" },
	                      ]),
	                    },
	                  },
	                  data: this.barData,
	                },
	              ],
	            };
	            myChart = echarts.init(document.getElementById('echartsa'))
	            myChart.setOption(option)
					    myChart.resize()
	            window.addEventListener('resize', () => {
	                myChart.resize()
	            });
	         },
	     }
	 }
</script>

css

css 复制代码
<style>
	.echarts {
		width: 420px;
		height: 300px;
	}
</style>
相关推荐
y = xⁿ7 小时前
DeepSeek Harness 学习日记:关于Agent接口,工具调用的底层实现
android·java·学习
2601_9620664910 小时前
【Sql Server】Update中的From语句,以及常见更新操作方式
android·java·数据库
张人玉15 小时前
基于 Python 机器学习 与 PyQt5 桌面框架开发的可视化分析系统——基于大数据的网上购物消费行为分析可视化大屏
python·qt·机器学习·echarts·three.js
用户693717500138415 小时前
曾经安卓开发人手一个的 EventBus,为什么现在没人爱用了?
android·android studio
九皇叔叔17 小时前
MySQL ORDER BY 性能优化详解:Using filesort、联合索引、ASC/DESC 与覆盖索引
android·adb
OriginCoding17 小时前
用 AI Agent 协作完成一个 Android TOTP 应用:从需求边界到 v1.0.0
android·ai编程
杉氧20 小时前
React 灵魂:深入剖析 Hooks 与副作用(Side Effects)陷阱
android·前端·react native
又见情义21 小时前
RK3568 + RTL8211F 网络唤醒(WOL)功能适配全记录
android·网络·驱动开发
用户09340777351421 小时前
HarmonyOS WPS Open SDK 实践:registerApp 鉴权与就绪门禁
android·typescript·harmonyos
jike_202621 小时前
会议离线录音APP:无网络记录能力对比
android·智能手机·语音识别