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>
相关推荐
吃汉堡吃到饱1 小时前
【Android】浅析MVC与MVP
android·mvc
贰叁!4 小时前
uniapp输入车牌号组件
uni-app
她似晚风般温柔7897 小时前
Uniapp + Vue3 + Vite +Uview + Pinia 分商家实现购物车功能(最新附源码保姆级)
开发语言·javascript·uni-app
深海呐8 小时前
Android AlertDialog圆角背景不生效的问题
android
Jiaberrr8 小时前
前端实战:使用JS和Canvas实现运算图形验证码(uniapp、微信小程序同样可用)
前端·javascript·vue.js·微信小程序·uni-app
ljl_jiaLiang8 小时前
android10 系统定制:增加应用使用数据埋点,应用使用时长统计
android·系统定制
花花鱼8 小时前
android 删除系统原有的debug.keystore,系统运行的时候,重新生成新的debug.keystore,来完成App的运行。
android
落落落sss9 小时前
sharding-jdbc分库分表
android·java·开发语言·数据库·servlet·oracle
工业互联网专业10 小时前
毕业设计选题:基于springboot+vue+uniapp的驾校报名小程序
vue.js·spring boot·小程序·uni-app·毕业设计·源码·课程设计
消失的旧时光-194311 小时前
kotlin的密封类
android·开发语言·kotlin