<template>
	<div :style="{ height: height, width: width }" />
</template>

<script>
import * as echarts from 'echarts';
import { defineComponent } from '@vue/composition-api';
import resize from './dashboard/mixins/resize';
// import { defineComponent } from 'vue';
import {option} from './options/mid_bot_options';
export default defineComponent({
	mixins: [resize],
	props: {
		year: null,
		className: {
			type: String,
			default: 'chart'
		},
		width: {
			type: String,
			default: '400px'
		},
		height: {
			type: String,
			default: '230px'
		},
    reportData:{
			type : Array,
			default () {
				return []
			}
    }
	},
	data() {
		return {
			loading: true,
		};
	},
	async mounted() {
		this.chartOptions = JSON.parse(JSON.stringify(option));
		this.initChart()
	},
	watch : {
		reportData : {
			handler (newValue) {
        let xData = []
        let sData = []
        newValue.forEach(item => {
          xData.push(item.date);
          sData.push(item.weight);
        });
        this.chartOptions.xAxis.data = xData;
        this.chartOptions.series[0].data = sData;
        this.initChart();
      },
      deep : true
		}
	},
	methods: {
		initChart() {
			let myChart = echarts.init(this.$el);
			myChart.setOption(this.chartOptions);
			this.$nextTick(() => {
				myChart.resize()
				this.$emit('endLoading', 11)
			})
		}
	}
});
</script>
