yangfeng
2023-12-06 93d04e35d6ff02470687b73ff7494b62bdc85f2c
src/views/cockpitPage/components/PerSonnelProductivity.vue
@@ -16,35 +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"],
        datay: [120, 200, 150, 380, 470, 150, 230],
      },
      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) {
@@ -59,30 +74,19 @@
          grid: {
            right: "80px",
            bottom: "60px",
            left: "60px",
            left: "70px",
            top: "30px",
          },
          dataZoom: [
            {
              type: "inside",
              // show: true, //显示滚动条
              start: 0,
              end: 100,
              yAxisIndex: 0,
              minSpan: 20,
              maxSpan: 100,
              // handleSize: 8
            },
            {
              //   type: 'slider', //两个一个是slider,一个是inside,slider是增加滚动条以及鼠标拖动滚动条功能,inside则是鼠标滚轮滚动滚动条。
              type: "inside",
              // show: true,
              // realtime : true,
              yAxisIndex: 0,
              minSpan: 20,
              maxSpan: 100,
              start: 0,
              end: 100,
              show: false,
              startValue: this.startValue, // 从头开始
              endValue: this.endValue, // 一次性展示几个
              zoomOnMouseWheel: false,
              moveOnMouseWheel: true,
              moveOnMouseMove: true,
            },
          ],
          legend: {
@@ -108,6 +112,7 @@
                // rotate:45,
                margin: 10,
                show: true,
                fontSize: 12,
                textStyle: {
                  color: function (params, index) {
                    let colorList = ["#dcb018", "#00FFFF"];
@@ -118,13 +123,19 @@
                    }
                  },
                },
                formatter: function (value) {
                  if (value.length > 5) {
                    return `${value.slice(0, 4)}...`;
                  }
                  return value;
                },
              },
              data: data.datax ? data.datax : [],
            },
          ],
          xAxis: [
            {
              type: "",
              type: "value",
              name: "单位:件",
              // min: data.yAxis[0].min?data.yAxis.min:0,
              minInterval: 1, //坐标轴是整数
@@ -151,10 +162,12 @@
              axisTick: {
                show: false,
              },
              axisLabel: {
                textStyle: {
                  color: "#00FFFF",
                },
                formatter: function (value) {
                  return `${value}%`;
                },
              },
            },
@@ -167,7 +180,21 @@
              label: {
                show: true,
                position: "right",
                color: "#00FFFF",
                formatter: function (params) {
                  if (params.dataIndex % 2 == 0) {
                    return `{a|${params.value}%}`;
                  } else {
                    return `{b|${params.value}%}`;
                  }
                },
                rich: {
                  a: {
                    color: "#00FFFF",
                  },
                  b: {
                    color: "#dcb018",
                  },
                },
              },
              itemStyle: {
                normal: {
@@ -187,8 +214,21 @@
            },
          ],
        };
        this.chartTimer = setInterval(function () {
          if (option.dataZoom[0].endValue == data.datay.length) {
            option.dataZoom[0].startValue = 0;
            option.dataZoom[0].endValue = 5;
          } else {
            option.dataZoom[0].endValue = option.dataZoom[0].endValue + 1;
            option.dataZoom[0].startValue = option.dataZoom[0].startValue + 1;
          }
          myChart.setOption(option);
        }, 4000);
        option && myChart.setOption(option);
        window.addEventListener("resize", function () {
          myChart.resize();
        });
      } else {
        option = {};
        myChart.setOption(option, true);
@@ -196,12 +236,20 @@
    },
    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) {
        option = {
          color: ["#dcb018", "#735b09", "#ebd68e", "#FF3000"],
          color: ["#dcb018", "#735b09", "#ebd68e", "#c7b36e"],
          tooltip: {
            trigger: "item",
          },
@@ -212,8 +260,8 @@
                z: 3,
                style: {
                  image: img,
                  width: 118,
                  height: 118,
                  width: 240,
                  height: 240,
                },
                left: "center",
                top: "center",
@@ -225,23 +273,33 @@
            {
              name: "Access From",
              type: "pie",
              // center: ['80%', '46%'],
              radius: ["52%", "65%"],
              // minAngle: 20,
              // startAngle: 60,
              radius: ["52%", "62%"],
              avoidLabelOverlap: false,
              label: {
                normal: {
                  position: "outer",
                  padding: [0, -55],
                  padding: [0, -62],
                  color: "#01f7fd",
                  fontSize: 12,
                  borderWidth: 20,
                  borderWidth: 5,
                  borderRadius: 4,
                  formatter: function (params) {
                    let str = params.name + params.value + "%";
                    return str;
                    let label =
                      params.name.length > 5
                        ? `${params.name.slice(0, 4)}...`
                        : params.name;
                    return `{a|${label}} {b|${params.value + "%"}}`;
                  },
                  rich: {
                    a: {
                      color: "#00ffff",
                      fontSize: 14,
                    },
                    b: {
                      color: "#fccd1d",
                      fontSize: 14,
                    },
                  },
                },
              },
@@ -255,7 +313,7 @@
              },
              labelLine: {
                show: true,
                length: 5,
                length: 4,
                length2: 70,
                lineStyle: {
                  color: "#dcb018",
@@ -270,10 +328,10 @@
          ],
        };
        option && myChart.setOption(option);
        option && myRightChart.setOption(option);
      } else {
        option = {};
        myChart.setOption(option, true);
        myRightChart.setOption(option, true);
      }
    },
  },
@@ -283,7 +341,7 @@
<style scoped lang="scss">
.bar-chart {
  width: 100%;
  height: calc(100% - 20px);
  height: calc(100% - 10px);
  padding: 20px 0 0;
  .bar-contents {