Newer
Older
HuangJiPC / src / pages / views / pumpWorking / components / barChart.vue
@zhangdeliang zhangdeliang on 21 Jun 2 KB update
<template>
  <div :id="id" style="width: 100%; height: 100%"></div>
</template>
<script>
import * as echarts from "echarts";
import { guid } from "@/utils/util";
import { reactive, toRefs, onMounted, watch } from "vue";
export default {
  name: "bar-chart",
  props: {
    data: Object,
  },
  setup(props) {
    const state = reactive({
      id: guid(),
      chart: null,
    });
    const resizeTheChart = () => {
      if (state.chart) {
        state.chart.resize();
      }
    };
    const init = () => {
      let chartDom =echarts.init(document.getElementById(state.id)) ;
      var option;
      option = {
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "shadow",
          },
        },
        grid: {
          top: "14%",
          left: "3%",
          right: "3%",
          bottom: "5%",
          containLabel: true,
        },
        xAxis: {
          type: "category",
          data: ["15:00", "16:00", "17:00", "18:00", "19:00", "20:00"],
          splitLine: {
            show: true,
          },
        },
        yAxis: {
          type: "value",
          name: "m³/s",
        },
        series: [
          {
            name:'瞬时流量',
            data: [120, 200, 150, 80, 70, 110],
            type: "bar",
            barWidth: 10,
            itemStyle: {
              normal: {
                  barBorderRadius: [10,10,0,0],
                color: new echarts.graphic.LinearGradient(
                  0,
                  1,
                  0,
                  0, // 0,0,1,0表示从左向右    0,0,0,1表示从右向左
                  [
                    { offset: 1, color: "rgba(44, 254, 252, 1)" },
                    { offset: 0, color: "rgba(44, 254, 252, 0)" },
                  ]
                ),
              },
            },
          },
        ],
      };

      option && chartDom.setOption(option,true)
      state.chart=chartDom
    };
    onMounted(() => {
      init();
      window.addEventListener("resize", resizeTheChart);
    });
    return {
      ...toRefs(state),
      resizeTheChart,
      init,
    };
  },
};
</script>