uni app 图表

html id 不能重复 option 为配置项

<view :prop="option" :change:prop="echarts.updateEcharts" id="echarts" class="echarts"></view>
			<view :prop="option2" :change:prop="echarts.updateEcharts" id="echarts2" class="echarts"></view>
			<view :prop="option3" :change:prop="echarts.updateEcharts" id="echarts3" class="echarts"></view>

js 初始化图表 需要引入echarts.js文件

下载地址 https://echarts.apache.org/handbook/zh/get-started/

<script module="echarts" lang="renderjs">
let myChart
let myChart1
let myChart3
export default {
	onNavigationBarButtonTap(){
		uni.navigateTo({
			url: "/pages/transaction/groupSelection"
		})
	},
	mounted() {
		if (typeof window.echarts === 'function') {
			this.initEcharts()
		} else {
			// 动态引入较大类库避免影响页面展示
			const script = document.createElement('script')
			// view 层的页面运行在 www 根目录,其相对路径相对于 www 计算
			script.src = 'static/echarts.js'
			script.onload = this.initEcharts.bind(this)
			document.head.appendChild(script)
		}
	},
	methods: {
		initEcharts() {
			myChart = echarts.init(document.getElementById('echarts'))
			myChart1 = echarts.init(document.getElementById('echarts2'))
			myChart3 = echarts.init(document.getElementById('echarts3'))

			// 观测更新的数据在 view 层可以直接访问到
			myChart.setOption(this.option)
			myChart1.setOption(this.option2)
			myChart3.setOption(this.option3)
		},
		updateEcharts(newValue, oldValue, ownerInstance, instance) {
			// 监听 service 层数据变更
			myChart.setOption(this.option)
			myChart1.setOption(this.option2)
			myChart3.setOption(this.option3)
		}, 
		onClick(event, ownerInstance) {
			// 调用 service 层的方法
			ownerInstance.callMethod('onViewClick', {
				test: 'test'
			})
		}
	}
}
</script>

这里是配置项

// 获取总金额
		getzongMoney() {
			this.option2 = {
				title: {
					text: `近7日交易总金额${this.jiaoyiMoney}`,
					top: 5,
					left: 5,
					textStyle: {
						fontSize: 14
					}
				},
				legend: {
					right: 5,
					top: 5
				},
				xAxis: {
					type: 'category',
					// width:20,
					// boundaryGap: false,
					data: ['09/09', '09/10', '09/11', '09/12'], //数据
					// axisLine: {
					// 	lineStyle: {
					// 		color: '#999'
					// 	}
					// },
					axisTick: {
						length: 3
					}
				},
				yAxis: {
					show: true
				},
				grid: {
					left: '10%',
					right: '10%',
					bottom: '15%',
					top: '25%'
				},
				dataZoom: [
					{
						type: 'inside',
						start: 1,
						end: 200
					}
				], // 收缩
				series: [
					{
						type: 'bar',
						data: ['5', '10', '18', '30'], //数据
						// barWidth: 20,
						// barGap: '1%',
						/*多个并排柱子设置柱子之间的间距*/
						// barCategoryGap: '50%',
						/*多个并排柱子设置柱子之间的间距*/
						showBackground: true,
						backgroundStyle: {
							color: 'rgba(180, 180, 180, 0.2)'
						},
						label: {
							show: false,
							position: 'center',
							textStyle: {
								fontSize: 12
							}
						},
						itemStyle: {
							color: '#2c76fd'
						},
						lineStyle: {
							width: 1
						}
					}
				]
			};
		},
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值