yangfeng
2023-12-06 93d04e35d6ff02470687b73ff7494b62bdc85f2c
src/views/cockpitPage/components/BarChart.vue
@@ -15,42 +15,70 @@
import ChartTitle from "@/views/cockpitPage/components/ChartTitle.vue";
//引入echart
import * as echarts from "echarts";
let myChart;
export default {
  components: {
    ChartTitle,
  },
  props: {},
  props: {
    chartData: {
      type: Object,
      require: true,
      default: () => {
        return {
          total: 0,
          rate: "0",
          datax: [],
          datay: [],
          datay2: [],
        };
      },
    },
  },
  data() {
    return {
      chartData: {
        total: 1000,
        rate: "99%",
        datax: [
          "第一车间",
          "第二车间",
          "第三车间",
          "第四车间",
          "第五车间",
          "第六车间",
          "第七车间",
          "第八车间",
          "第九车间",
        ],
        datay: [120, 200, 150, 180, 170, 150, 130, 180, 140],
        datay2: [20, 30, 50, 40, 70, 50, 30, 80, 40],
      },
      // chartData: {
      //   total: 1000,
      //   rate: "99%",
      //   datax: [
      //     "第一车间",
      //     "第二车间",
      //     "第三车间",
      //     "第四车间",
      //     "第五车间",
      //     "第六车间",
      //     "第七车间",
      //     "第八车间",
      //     "第九车间",
      //   ],
      //   datay: [120, 200, 150, 180, 170, 150, 130, 180, 140],
      //   datay2: [20, 30, 50, 40, 70, 50, 30, 80, 40],
      // },
      startValue: 0,
      endValue: 5,
      chartTimer: null,
    };
  },
  mounted() {
    this.pieChart("chart", this.chartData);
  watch: {
    "chartData.datay"(val) {
      this.startValue = 0;
      this.endValue = 5;
      this.pieChart("chart", this.chartData);
    },
  },
  watch: {},
  mounted() {
    // this.pieChart("chart", this.chartData);
  },
  methods: {
    //在职
    pieChart(chartName, data) {
      let that = this;
      clearInterval(this.chartTimer);
      let chartDom = this.$refs[chartName];
      let myChart = echarts.init(chartDom);
      if (myChart != null && myChart != "" && myChart != undefined) {
        myChart.dispose(); //销毁
      }
      myChart = echarts.init(chartDom);
      let option;
      let lineColor = "#35ddc74d";
      if (data) {
@@ -105,8 +133,11 @@
              type: "inside",
              xAxisIndex: 0,
              show: false,
              startValue: 0, // 从头开始
              endValue: 5, // 一次性展示几个
              startValue: that.startValue, // 从头开始
              endValue: that.endValue, // 一次性展示几个
              zoomOnMouseWheel: false,
              moveOnMouseWheel: true,
              moveOnMouseMove: true,
            },
          ],
          legend: {
@@ -145,11 +176,16 @@
                },
              },
              axisLabel: {
                // rotate:45,
                margin: 10,
                show: true,
                textStyle: {
                  color: "#00FFFF",
                },
                formatter: function (value) {
                  if (value.length > 4) {
                    return `${value.slice(0, 3)}...`;
                  }
                  return value;
                },
              },
              data: data.datax ? data.datax : [],
@@ -159,7 +195,6 @@
            {
              type: "value",
              name: "",
              // min: data.yAxis[0].min?data.yAxis.min:0,
              minInterval: 1, //坐标轴是整数
              max: Math.ceil(eval(`Math.max(${data.datay})`) / 5) * 5, //数据最大值加3
              interval:
@@ -254,11 +289,11 @@
            },
          ],
        };
        setInterval(function () {
        this.chartTimer = setInterval(function () {
          // 每次向左滑动一个,最后一个从头开始。
          if (option.dataZoom[0].endValue == that.chartData.datay.length) {
            option.dataZoom[0].startValue = 0;
            option.dataZoom[0].endValue = 5;
            option.dataZoom[0].startValue = that.startValue;
            option.dataZoom[0].endValue = that.endValue;
          } else {
            option.dataZoom[0].endValue = option.dataZoom[0].endValue + 1;
            option.dataZoom[0].startValue = option.dataZoom[0].startValue + 1;