ucharts,数据交互

30 篇文章 5 订阅
3 篇文章 0 订阅
<template>
	<view>
		<view class="ucharts-tit">kw.h</view>
		<view class="qiun-charts">
			<canvas canvas-id="ExtremunColumn" id="ExtremunColumn" class="charts" disable-scroll=true @touchstart="touchColumn"
				@touchmove="moveColumn" @touchend="touchEndColumn"></canvas>
		</view>
	</view>
</template>

<script>
	import uCharts from '@/components/u-charts/u-charts/u-charts.js';
	var _self;
	var canvaColumn = null;

	export default {
		data() {
			return {
				cWidth: '',
				cHeight: '',
				pixelRatio: 1,
				serverData: '',
				back_id: this.backid,
				day_date: this.dayresult,
				day: [],
				name: '',
				event_hour: [], //小时
				dayuser: [],
			}
		},
		props: ['backid', 'dayresult'],

		watch: {
			backid(val) {
				this.event_hour = [];
				this.dayuser = [];
				this.getServerData()
			},
			dayresult(val) {
				this.event_hour = [];
				this.dayuser = [];
				this.getServerData()
			},
		},

		beforeMount() {
			_self = this;
			this.cWidth = uni.upx2px(680);
			this.cHeight = uni.upx2px(420);
			this.getServerData();
		},
		methods: {
			getServerData() {
				this.$http.get('/power/day', {
					back_id: this.backid,
					day: this.daydate
				}).then(res => {
					if (res.data.result === 1) {
						let server = res.data.data;
						server.list.forEach(item => {
							name: item.back_name;
							this.dayuser.push(
								item.used
							);
							this.event_hour.push(
								item.event_hour,
							);
						});

						let Column = {
							categories: [], //横轴
							series: [{
								name: '用电量',
								data: this.dayuser,
								color: '#047efd'
							}]
						};
						Column.categories = this.event_hour; //横坐标值
						// Column.series = ; //竖坐标值(每天电量)
						_self.showColumn("ExtremunColumn", Column);
					} else {
						uni.showToast({
							icon: 'none',
							title:'图表暂无数据'
						})
					}
				})
			},
			showColumn(canvasId, chartData) {
				canvaColumn = new uCharts({
					$this: _self,
					canvasId: canvasId,
					type: 'column',
					legend: {
						show: true
					},
					fontSize: 11,
					background: '#FFFFFF',
					pixelRatio: _self.pixelRatio,
					animation: true,
					categories: chartData.categories,
					series: chartData.series,
					enableScroll: true, //开启图表拖拽功能
					xAxis: {
						disableGrid: true,
						fontSize: 11,
						gridType: 'dash',
						itemCount: 7, //x轴单屏显示数据的数量,默认为5个
						scrollShow: true, //新增是否显示滚动条,默认false
						scrollAlign: 'left', //滚动条初始位置
						scrollBackgroundColor: '#F7F7FF', //默认为 #EFEBEF
						scrollColor: '#DEE7F7', //默认为 #A6A6A6
					},
					yAxis: {
						max: 300,
						splitNumber: 5,
						gridType: 'dash',
						gridColor: '#CCCCCC',
						dashLength: 5,
						splitNumber: 6,
						format: (val) => {
							return val.toFixed(0)
						}
						// splitNumber: 2, //横轴区间
					},
					dataLabel: false,
					width: _self.cWidth * _self.pixelRatio,
					height: _self.cHeight * _self.pixelRatio,
					extra: {
						column: {
							type: 'group',
							width: _self.cWidth * _self.pixelRatio * 0.45 / chartData.categories.length
						}
					}
				});

			},
			//拖拽
			touchColumn(e) {
				canvaColumn.scrollStart(e);
			},
			moveColumn(e) {
				canvaColumn.scroll(e);
			},
			touchEndColumn(e) {
				canvaColumn.scrollEnd(e);
				//下面是toolTip事件,如果滚动后不需要显示,可不填写
				canvaColumn.showToolTip(e, {
					format: function(item, category) {
						return category + ' ' + item.name + ':' + item.data
					}
				});
			},
		}
	}
</script>

<style>
	.qiun-charts {
		width: 680upx;
		height: 420upx;
		background-color: #FFFFFF;
	}

	.charts {
		width: 680upx;
		height: 420upx;
		background-color: #FFFFFF;
	}
</style>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值