<script setup lang="ts">
import {onMounted, ref} from "vue";
import * as echarts from "echarts";


const main = ref();
onMounted(() => {
  init();
});

const labelRight = {
  position: 'right'
};


const init = () => {
  const myChart = echarts.init(main.value);
  let option = {
    title: {
      text: '每日用户新增'
    },
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        type: 'shadow'
      }
    },
    grid: {
      top: 80,
      bottom: 30
    },
    xAxis: {
      type: 'value',
      position: 'top',
      splitLine: {
        lineStyle: {
          type: 'dashed'
        }
      }
    },
    yAxis: {
      type: 'category',
      axisLine: { show: false },
      axisLabel: { show: false },
      axisTick: { show: false },
      splitLine: { show: false },
      data: [
        'three',
        'two',
        'one'
      ]
    },
    series: [
      {
        name: 'Cost',
        type: 'bar',
        stack: 'Total',
        label: {
          show: true,
          formatter: '{b}'
        },
        data: [
          { value: -0.07, label: labelRight },
          { value: -0.09, label: labelRight },
          0.2,
          0.44,
          { value: -0.23, label: labelRight },
          0.08,
          { value: -0.17, label: labelRight },
          0.47,
          { value: -0.36, label: labelRight },
          0.18
        ]
      }
    ]
  };

  myChart.setOption(option);
}

</script>

<template>>
  <div class="echarts">
    <div style="width: 100%; height: 100%; margin-top: 1rem">
      <div ref="main" style="width: 100%; height: 100%"></div>
    </div>
  </div>
</template>

<style scoped>
.echarts {
  width: 90%;
  height: 80%;
  border-radius: 12px;
  margin: 1rem;
  padding: 1rem;
  background-color: #ffffff;
  min-width: 0;
}
</style>

