<template>
	<view>
		<canvas canvas-id="canvasColumnStack" id="canvasColumnStack" @touchstart="touchColumn" style="width: 700rpx; height: 800rpx;"></canvas>
	</view>
</template>

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

	export default {
		data() {
			return {
				cWidth: '',
				cHeight: '',
				pixelRatio: 1,
				serverData: '',
			};
		},
		mounted() {
			_self = this;
			this.cWidth = uni.upx2px(700);
			this.cHeight = uni.upx2px(780);
			this.getServerData();
		},
		methods: {
			getServerData() {
				this.$p_api.coalmine_trend({
					
				}).then((res)=>{
					// console.log(res.data.data)
					
					let ColumnStack={
						categories:[],
						series:[
							{
								"name": "早班",
								"data": []
							},
							{
								"name": "中班",
								"data": []
							},
							{
								"name": "晚班",
								"data": []
							}
						],
					};
					
					res.data.data.map((item,index)=>{
						var sevm = {};
						sevm = item.date;
						ColumnStack.categories[index] = sevm
					})
					
					res.data.data.map((item,index)=>{
						var sevm = {};
						sevm = item.n1;
						ColumnStack.series[0].data[index] = sevm
					})
					res.data.data.map((item,index)=>{
						var sevm = {};
						sevm = item.n2;
						ColumnStack.series[1].data[index] = sevm
					})
					res.data.data.map((item,index)=>{
						var sevm = {};
						sevm = item.n3;
						ColumnStack.series[2].data[index] = sevm
					})
					
					
					_self.showColumnStack("canvasColumnStack", ColumnStack);
				})
				
				
			},
			showColumnStack(canvasId, chartData) {
				canvaColumn = new uCharts({
					$this: _self,
					canvasId: canvasId,
					type: 'column',
					legend: {
						show: true,
						position: 'top',
						itemGap: 30,
					},
					fontSize: 11,
					background: '#FFFFFF',
					pixelRatio: _self.pixelRatio,
					animation: true,
					categories: chartData.categories,
					series: chartData.series,
					xAxis: {
						disableGrid: true,
					},
					yAxis: {
						//disabled:true
					},
					dataLabel: false,
					width: _self.cWidth * _self.pixelRatio,
					height: _self.cHeight * _self.pixelRatio,
					extra: {
						column: {
							type: 'stack',
							width: _self.cWidth * _self.pixelRatio * 0.5 / chartData.categories.length
						}
					}
				});

			},
			touchColumn(e) {
				canvaColumn.showToolTip(e, {
					format: function(item, category) {
						// return category + ' ' + item.name + ':' + item.data
						return item.name + ':' + item.data
					}
				});
			},
		}
	}
</script>

<style lang="scss">

</style>
