yangfeng
2023-12-06 d372f82db7bf15ed38f8faf2e6b90080f9343c04
src/views/cockpitPage/components/PerSonnelProductivity.vue
@@ -16,46 +16,50 @@
import ChartTitle from "@/views/cockpitPage/components/ChartTitle.vue";
//引入echart
import * as echarts from "echarts";
let myChart;
let myRightChart;
export default {
  components: {
    ChartTitle,
  },
  props: {},
  props: {
    chartData: {
      type: Object,
      require: true,
      default: () => {
        return {
          datax: [],
          datay: [],
        };
      },
    },
  },
  data() {
    return {
      chartData: {
        datax: [
          "人员1",
          "人员2",
          "人员3",
          "人员4",
          "人员5",
          "人员6",
          "人员7",
          "人员8",
          "人员9",
        ],
        datay: [120, 200, 150, 380, 470, 150, 230, 330, 190, 440],
      },
      startValue: 0,
      endValue: 5,
      chartTimer: null,
    };
  },
  mounted() {
    this.pieChart("chart", this.chartData);
    let chartData2 = [
      { value: 10, name: "一类" },
      { value: 20, name: "二类" },
      { value: 60, name: "三类" },
      { value: 10, name: "四类" },
    ];
    this.getChartRight("chart2", chartData2);
  watch: {
    "chartData.datay"(val) {
      this.startValue = 0;
      this.endValue = 5;
      this.pieChart("chart", this.chartData);
    },
  },
  watch: {},
  mounted() {},
  methods: {
    //在职
    pieChart(chartName, data) {
      let that = this;
      clearInterval(this.chartTimer);
      let chartDom = this.$refs[chartName];
      let myChart = echarts.init(chartDom);
      // let myChart = echarts.init(chartDom);
      if (myChart != null && myChart != "" && myChart != undefined) {
        myChart.dispose(); //销毁
      }
      myChart = echarts.init(chartDom);
      let option;
      let lineColor = "#35ddc74d";
      if (data) {
@@ -70,7 +74,7 @@
          grid: {
            right: "80px",
            bottom: "60px",
            left: "60px",
            left: "70px",
            top: "30px",
          },
          dataZoom: [
@@ -78,8 +82,8 @@
              type: "inside",
              yAxisIndex: 0,
              show: false,
              startValue: 0, // 从头开始
              endValue: 5, // 一次性展示几个
              startValue: this.startValue, // 从头开始
              endValue: this.endValue, // 一次性展示几个
            },
          ],
          legend: {
@@ -105,6 +109,7 @@
                // rotate:45,
                margin: 10,
                show: true,
                fontSize: 12,
                textStyle: {
                  color: function (params, index) {
                    let colorList = ["#dcb018", "#00FFFF"];
@@ -114,6 +119,12 @@
                      return colorList[1];
                    }
                  },
                },
                formatter: function (value) {
                  if (value.length > 5) {
                    return `${value.slice(0, 4)}...`;
                  }
                  return value;
                },
              },
              data: data.datax ? data.datax : [],
@@ -148,7 +159,6 @@
              axisTick: {
                show: false,
              },
              axisLabel: {
                textStyle: {
                  color: "#00FFFF",
@@ -184,10 +194,8 @@
            },
          ],
        };
        setInterval(function () {
          // 每次向左滑动一个,最后一个从头开始。
          if (option.dataZoom[0].endValue == that.chartData.datay.length) {
        this.chartTimer = setInterval(function () {
          if (option.dataZoom[0].endValue == data.datay.length) {
            option.dataZoom[0].startValue = 0;
            option.dataZoom[0].endValue = 5;
          } else {
@@ -208,7 +216,15 @@
    },
    getChartRight(chartName, data) {
      let chartDom = this.$refs[chartName];
      let myChart = echarts.init(chartDom);
      // let myRightChart = echarts.init(chartDom);
      if (
        myRightChart != null &&
        myRightChart != "" &&
        myRightChart != undefined
      ) {
        myRightChart.dispose(); //销毁
      }
      myRightChart = echarts.init(chartDom);
      let img = "/cockpitPage/dotted-circle.png";
      let option;
      if (data) {
@@ -224,8 +240,8 @@
                z: 3,
                style: {
                  image: img,
                  width: 238,
                  height: 238,
                  width: 240,
                  height: 240,
                },
                left: "center",
                top: "center",
@@ -237,10 +253,7 @@
            {
              name: "Access From",
              type: "pie",
              // center: ['80%', '46%'],
              radius: ["52%", "62%"],
              // minAngle: 20,
              // startAngle: 60,
              avoidLabelOverlap: false,
              label: {
@@ -291,10 +304,10 @@
          ],
        };
        option && myChart.setOption(option);
        option && myRightChart.setOption(option);
      } else {
        option = {};
        myChart.setOption(option, true);
        myRightChart.setOption(option, true);
      }
    },
  },