import * as echarts from 'echarts';
// import {remoteCount2} from '@/api/estate/customer';


let option = {
  color:["#3d7bbf"],
  grid: {
    left: '10px',
    right: '10px',
    bottom: '10px',
    top: '25px',
    containLabel: true
  },
  xAxis: {
    type: 'category',
    data: []
  },
  yAxis: {
    type: 'value'
  },
  series: [
    {
      data: [],
      type: 'bar',
      label: {
        show: true,
        position: 'top'
      }
    }
  ]
};



let chart = null;

let resetOption = JSON.stringify(option);

/**
 * echart 初始化
 * @param {*} data 
 * @param {*} ele 
 */
export const chartInit = async (ele) => {
  chart = echarts.init(ele);
  chart.setOption(option);
  return Promise.resolve(chart);
}




let map = new Map();
/**
 * echart发生改变
 * @param {*} arg - 数据
 */
export const chartChange = async (num) => {

  option = JSON.parse(resetOption);

  let names = [];
  let vs = [];
  let d = new Date();
  for(let i = 0 ;i < num;i++){
      names.unshift(d.format("MM月"));
      d.setMonth(d.getMonth()-1);
      vs.unshift(0);
  }

  // let r = await remoteCount2({num});

  // for(let item of r.data){
  //   vs[item.i]=item.value;
  // }

  option.xAxis.data=names;
  option.series[0].data=vs;

  chart.setOption(option);

}