Newer
Older
KaiFengPC / src / views / project / compensation / homeEcharts / queryChat.vue
@zhangdeliang zhangdeliang on 9 Oct 2 KB update
<template>
  <div>
    <div ref="assetEchart" class="asset_echart"></div>
  </div>
</template>
<script setup>
import { init } from 'echarts';

const assetEchart = ref(null);
let {
  data: { xData, legend, yData },
} = defineProps(['data']);
let options = reactive({
  title: {
    subtext: '单位(万元)',
    left: 5, // 距离左边位置
    top: 16, // 距离上面位置
    subtextStyle: {
      // 设置二级标题的样式
      color: '#fff',
    },
  },
  tooltip: {
    trigger: 'axis',
    axisPointer: {
      type: 'cross',
      crossStyle: {
        color: '#fff',
      },
    },
  },
  legend: {
    data: legend,
    textStyle: {
      color: '#fff',
    },
  },
  grid: {
    left: '1%',
    right: '0%',
    bottom: '12%',
    containLabel: true,
  },
  xAxis: [
    {
      type: 'category',
      data: xData,
      axisPointer: {
        type: 'shadow',
      },
      axisLabel: {
        textStyle: {
          color: '#fff',
        },
      },
    },
  ],
  yAxis: [
    {
      type: 'value',
      min: 0,
      interval: 10,
      axisLabel: {
        formatter: '{value}',
      },
    },
  ],
  series: [
    {
      barWidth: '18px',
      name: legend[0],
      type: 'bar',
      tooltip: {
        valueFormatter: function (value) {
          return value;
        },
      },
      data: yData.paymentMoney,
      itemStyle: {
        color: '#0f69ff',
      },
    },
  ],
});
function chartSize(container, charts) {
  function getStyle(el, name) {
    if (window.getComputedStyle) {
      return window.getComputedStyle(el, null);
    } else {
      return el.currentStyle;
    }
  }
  const hi = getStyle(container, 'height').height;
  charts.style.height = hi;
}
onMounted(() => {
  const chart = init(assetEchart.value);
  chart.setOption(options);
  window.addEventListener('resize', () => {
    chart.resize();
  });
});
</script>
<style lang="scss" scoped>
.asset_echart {
  width: 530px;
  height: 304px;
  margin: 10px 14px 0 16px;
  padding: 24px;
  &_echart {
    width: 100%;
    height: 100%;
  }
}
</style>