yangfeng
2023-12-05 f5976f38c33048020de1b116ffa004b0d889a14d
src/views/cockpitPage/components/BarChart.vue
@@ -15,42 +15,66 @@
import ChartTitle from "@/views/cockpitPage/components/ChartTitle.vue";
//引入echart
import * as echarts from "echarts";
let myChart;
export default {
  components: {
    ChartTitle,
  },
  props: {},
  data() {
    return {
  props: {
      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],
      },
      type: Object,
      require: true,
      default: () => {
        return {
          total: 0,
          rate: "0",
          datax: [],
          datay: [],
          datay2: [],
    };
  },
  mounted() {
    },
  },
  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],
      // },
      chartTimer: null,
    };
  },
  watch: {
    "chartData.datay"(val) {
    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) {
@@ -145,11 +169,16 @@
                },
              },
              axisLabel: {
                // rotate:45,
                margin: 10,
                show: true,
                textStyle: {
                  color: "#00FFFF",
                },
                formatter: function (value) {
                  if (value.length > 5) {
                    return `${value.slice(0, 4)}...`;
                  }
                  return value;
                },
              },
              data: data.datax ? data.datax : [],
@@ -159,7 +188,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,7 +282,7 @@
            },
          ],
        };
        setInterval(function () {
        this.chartTimer = setInterval(function () {
          // 每次向左滑动一个,最后一个从头开始。
          if (option.dataZoom[0].endValue == that.chartData.datay.length) {
            option.dataZoom[0].startValue = 0;