ex2.vue 2.02 KB
<template>
  <div>
    <div class="echart" id="mychart2" :style="myChartStyle"></div>
  </div>
</template>
   
  <script>
import * as echarts from "echarts";
export default {
  data() {
    return {
      myChartStyle: { float: "left", width: "100%", height: "300px" }, //图表样式
    };
  },
  mounted() {
    //   this.initEcharts();
  },
  methods: {
    initEcharts(x, y) {
      // 基本柱状图
      const option = {
        title: {
          text: "最近30天进件量分析",
          subtext: "",
          left: "center",
        },
        color: ["#409EFF"],
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "shadow",
          },
        },
        grid: {
          left: "3%",
          right: "4%",
          bottom: "3%",
          containLabel: true,
          y2: 150,
        },
        xAxis: [
          {
            type: "category",
            data: x,
            axisTick: {
              alignWithLabel: true,
            },
            // axisLabel: {
            //   interval:0,
            //   rotate:-30
            // },
          },
        ],
        yAxis: [
          {
            type: "value",
          },
        ],
        series: [
          {
            name: "当日进件量",
            type: "line",
            smooth: true,
            stack: "Total",
            barWidth: "100%",
            data: y,
            areaStyle: {
              //   color: "#ff0",
              //   opacity: 0.5,
            },
            emphasis: {
              focus: "series",
            },
            label: {
              show: true,
              position: "top",
              textStyle: {
                color: "#333",
                fontSize: 12,
              },
            },
          },
        ],
      };
      const myChart = echarts.init(document.getElementById("mychart2"));
      myChart.setOption(option);
      //随着屏幕大小调节图表
      window.addEventListener("resize", () => {
        myChart.resize();
      });
    },
  },
};
</script>