<template>
	<view class="">
		<view class="charts" >
			<canvas canvas-id="canvasColumn" id="canvasColumn" class="charts" @touchstart="touchColumn"></canvas>
		</view>
	</view>
</template>

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

	export default {
		data() {
			return {
				cWidth:'',
				cHeight:'',
				pixelRatio:1,
				serverData:'',
			}
		},
		created() {
			_self = this;
			this.cWidth=uni.upx2px(750);
			this.cHeight=uni.upx2px(500);
			
			this.getServerData();
		},
		methods: {
			async getServerData(){
				let agencyId=this.$cache.get('agencyId')
				let tenantId=this.$cache.get('agencyTenantId')
				let params={
					agencyId,
					tenantId
				}
				let res=await this.$api.statistical.carTendency(params)
				let inOutRecordsData={
					categories:res.data.dateList.reverse(),
					data:res.data.peopleNUm.reverse()
				}
				
				let chartData={
				  "categories": inOutRecordsData.categories,
				  "series": [{
					"name": "人员数",
					"data": inOutRecordsData.data,
					color: '#5064eb'
				  }]
				}
				_self.showColumn("canvasColumn",chartData);
			},
			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,
					xAxis: {
						disableGrid:true,
					},
					yAxis: {
					
					},
					dataLabel: true,
					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.showToolTip(e, {
					format: function (item, category) {
						if(typeof item.data === 'object'){
							return category + ' ' + item.name + ':' + item.data.value 
						}else{
							return category + ' ' + item.name + ':' + item.data 
						}
					}
				});
			},
		}
	}
</script>

<style>
.charts{
	padding: 30rpx 0;
	width: 100%;
	height: 550rpx;
	background-color: #FFFFFF;
}
</style>