<template>
  <div  :style="currentStyle" ref="mychart">
  </div>
</template>

<script>
import Base from '@/components/mychart/basechart.vue';
// 引入柱状图组件
require('echarts/lib/chart/scatter');
export default {
    name: 'scatter',
    extends: Base,
    data () {
        return {
            mychartconfig: {
                legend: {
                    data: []
                },
                grid: {
                    left: '2%',
                    right: '2%',
                    bottom: '2%',
                    containLabel: true
                },
                xAxis: {},
                yAxis: {},
                series: []
            },
            myConfig:{
                xfieldname:'', // x轴字段
                yfieldname:'',   //值字段名
                mychartconfig:{},
               
            }
        };
    },
    methods: {
        customInitMychartConfig () {
            let curlConfig = Object.assign({},this.mychartconfig,this.myConfig.mychartconfig); 
            let data = [];
            let self = this;
            let series = [];
            if (this.currentData && this.currentData.length > 0) {
                this.currentData.forEach(el => {
                    let obj = [];
                    if (el[self.myConfig.xfieldname]) {
                        obj.push(Number(el[self.myConfig.xfieldname]));
                    } else {
                        obj.push(0);
                    }
                    if (el[self.myConfig.yfieldname]) {
                        obj.push(Number(el[self.myConfig.yfieldname]));
                    } else {
                        obj.push(0);
                    }
                    data.push(obj);
                });
                let temp = {
                    symbolSize:20,
                    type: 'scatter',
                    data: data
                };
                if (this.myConfig.OnUpdataSeries) {
                    let that = this;
                    this.myConfig.OnUpdataSeries(temp,that);
                }
                series.push(temp);
            }
            // 处理数据
            curlConfig.series = series;
            return curlConfig;
        }
       
    }
};
</script>