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

<script>
import * as echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import resize from './mixins/resize'

const animationDuration = 3000

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '96%'
    },
    height: {
      type: String,
      default: '300px'
    },
    chartData: {
      type: Object,
      required: true
    }
  },
watch: {
     chartData: {
       deep: true,
       handler(val) {
         this.setOptions(val)
       }
     }
   },
   data() {
     return {
       chart: null
     }
   },
   mounted() {
     this.$nextTick(() => {
       this.initChart()
     })
   },
   beforeDestroy() {
     if (!this.chart) {
       return
     }
     this.chart.dispose()
     this.chart = null
   },
   methods: {
     initChart() {
       this.chart = echarts.init(this.$el, 'macarons');
       this.chart = echarts.init(this.$el, 'macarons')
       this.setOptions(this.chartData)
	   console.log(this.chartData)
     },
       setOptions({ Y1, X } = {}) {
         console.log(Y1, X ,56)
        this.chart.setOption({
                 title: {
                        text: '历史身高统计图(单位CM)',
						textStyle:{
						        //文字颜色
						        color:'#FFB132',
						        //字体风格,'normal','italic','oblique'
						//         fontStyle:'normal',
						//         //字体粗细 'normal','bold','bolder','lighter',100 | 200 | 300 | 400...
						//         fontWeight:'bold',
						//         //字体系列
						//         fontFamily:'sans-serif',
						//         //字体大小
						// 　　　　 fontSize:18
						    }
                    },
                    tooltip: {
                        trigger: 'axis'
                    },
                    legend: {
                        data: []
                    },
                    grid: {
                        left: '3%',
                        right: '4%',
                        bottom: '3%',
                        containLabel: true
                    },
                    toolbox: {
                        feature: {
                            saveAsImage: {}
                        }
                    },
                    color:['#FFB132'],
                    xAxis: {
                        type: 'category',
                        boundaryGap: false,
                        axisLine: {
                          lineStyle: {
                            color: '#343434',
                            width: 1 //这里是为了突出显示加上的
                          }
                        },
                        data: X
                    },
                    yAxis: {
                        type: 'value',
                        axisLine: {
                          lineStyle: {
                            color: '#343434',
                            width: 1 //这里是为了突出显示加上的
                          }
                        }
                    },
                    series: [
                        {
                            name: '身高',
                            type: 'line',
                            stack: '厘米',
                            data: Y1
                        },
                    ]
              })
       }
   }
}
</script>
