<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() {

				let ColumnStack = {
					 "categories": ["19日", "20日", "21日", "22日", "23日", "24日","25日"],
					  "series": [{
						"name": "早班",
						"data": [96258.6, 102354.2, 87569.5, 87512.2, 79854.2, 89896.7,80666.3]
					  }, {
						"name": "中班",
						"data": [15089.5, 34256.1, 30659.7, 28665.1, 27458.6, 26597.4,12658.7]
					  }, {
						"name": "晚班",
						"data": [105203.2, 116542.2, 102654.2, 106598.2, 113568.2, 99685.2,0]
					  }]
				};
				_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>
