<template>
	<view>
		<div class="chart1" ref="chart"></div>
	</view>
</template>
 
<script>
	import echarts from "echarts";
	export default {
		props: {
			fangQu:{
				type: Array,
				// 定义是否必须传
				required: false,
				// 定义默认值
				default: []
			},
			fangquTime:{
				type: Array,
				// 定义是否必须传
				required: false,
				// 定义默认值
				default: []
			},
		},
		mounted() {
			this.getEchartData()
		},
		watch:{
		   fangQu: {
				immediate: true,
				handler(value) {
				  this.fangQu = value
				  this.getEchartData()
				}
			},
		},
		data() {
			return {
			}
		},
 
		methods: {
			// 折线图
			getEchartData() {
			  const chart = this.$refs.chart;
			  var option = null;
			  const myChart = this.$echarts.init(chart);
			  option = {
				  legend: {
					  top: 20,
				  },
				  xAxis: {
				      type: 'category',
				      data: this.fangquTime//['05-01', '05-02', '05-03', '05-04', '05-05']
				    },
				    yAxis: {
				      type: 'value'
				    },
				    series: [
				      {
						name: '访问量',
				        data: this.fangQu,//[150, 230, 224, 218, 135, 147, 260],
				        type: 'line'
				      }
				    ]
			  };
			  myChart.setOption(option);
			  window.addEventListener("resize", function () {
				myChart.resize();
			  });
			  this.$on("hook:destroyed", () => {
				window.removeEventListener("resize", function () {
				  chart.resize();
				});
			  });
			  return option;
			},
			  
		},
 
	}
</script>
<style>
	.chart1 {
		width: 100%;
		height: 115%;
		display: block;
	}
</style>