<template>
  <el-card class="box-card">
    <div class="text-sm">积分电量(C)</div>
    <el-empty description="暂无数据" v-if="noData"></el-empty>
    <div id="container"></div>
  </el-card>
</template>

<script setup>
import { onMounted, ref, defineExpose } from 'vue';
import { Column } from '@antv/g2plot';

const show = ref(false);
const noData = ref(true);
let bar = null;

// 设置图表
onMounted(() => {
  show.value = true;
});

const setDate = data => {
  noData.value = false;
  if (bar) {
    bar.destroy();
  }
  bar = new Column('container', {
    data,
    layout: 'vertical',
    xField: 'time',
    yField: 'value',
    padding: [30, 16, 60, 50],
    columnWidthRatio: 0.6, // 宽度占比
    yAxis: {
      title: {
        text: '积分电量',
        spacing: 20,
      },
    },
    slider: {
      start: 0.1,
      end: 0.5,
    },
    meta: { value: { alias: '积分电量(C)' } },
  });

  bar.render();
};

defineExpose({ setDate });
</script>
