yangfeng
2023-12-11 14101bd42ce17dfb9d951d0738abe9d303fb3fe5
src/views/cockpitPage/components/PerSonnelProductivity.vue
@@ -16,48 +16,53 @@
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";
      let spirit = "/cockpitPage/order-bg.png";
      if (data) {
        option = {
          color: ["#00FFFF", "#dcb018"],
@@ -66,11 +71,19 @@
            axisPointer: {
              type: "none",
            },
            textStyle: {
              color: "#00FFFF",
            },
            borderColor: "#00FFFF",
            backgroundColor: "#238d8d6b",
            valueFormatter: function (value) {
              return value + "%";
            },
          },
          grid: {
            right: "80px",
            bottom: "60px",
            left: "60px",
            left: "70px",
            top: "30px",
          },
          dataZoom: [
@@ -78,8 +91,11 @@
              type: "inside",
              yAxisIndex: 0,
              show: false,
              startValue: 0, // 从头开始
              endValue: 5, // 一次性展示几个
              startValue: this.startValue, // 从头开始
              endValue: this.endValue, // 一次性展示几个
              zoomOnMouseWheel: false,
              moveOnMouseWheel: true,
              moveOnMouseMove: true,
            },
          ],
          legend: {
@@ -105,15 +121,22 @@
                // rotate:45,
                margin: 10,
                show: true,
                fontSize: 12,
                textStyle: {
                  color: function (params, index) {
                    let colorList = ["#dcb018", "#00FFFF"];
                    let colorList = ["#fec718", "#00FFFF"];
                    if (index % 2 == 0) {
                      return colorList[0];
                    } else {
                      return colorList[1];
                    }
                  },
                },
                formatter: function (value) {
                  if (value.length > 5) {
                    return `${value.slice(0, 4)}...`;
                  }
                  return value;
                },
              },
              data: data.datax ? data.datax : [],
@@ -122,7 +145,7 @@
          xAxis: [
            {
              type: "value",
              name: "单位:件",
              // name: "单位:件",
              // min: data.yAxis[0].min?data.yAxis.min:0,
              minInterval: 1, //坐标轴是整数
              max: Math.ceil(eval(`Math.max(${data.datay})`) / 5) * 5, //数据最大值加3
@@ -148,30 +171,51 @@
              axisTick: {
                show: false,
              },
              axisLabel: {
                textStyle: {
                  color: "#00FFFF",
                },
                formatter: function (value) {
                  return `${value}%`;
                },
              },
            },
          ],
          series: [
            {
              type: "bar",
              type: "pictorialBar",
              name: "",
              barWidth: "15",
              symbol: spirit,
              symbolRepeat: true,
              symbolMargin: "25%",
              symbolClip: true,
              symbolSize: [4, 11],
              barCategoryGap: "40%",
              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: "#fccd1d",
                  },
                },
              },
              itemStyle: {
                normal: {
                  //柱形图圆角,初始化效果
                  barBorderRadius: [4, 4, 0, 0],
                  color: function (params) {
                    let colorList = ["#dcb018", "#00FFFF"];
                    let colorList = ["#fccd1d", "#00FFFF"];
                    if (params.dataIndex % 2 == 0) {
                      return colorList[0];
                    } else {
@@ -184,10 +228,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,24 +250,41 @@
    },
    getChartRight(chartName, data) {
      let chartDom = this.$refs[chartName];
      let myChart = echarts.init(chartDom);
      if (
        myRightChart != null &&
        myRightChart != "" &&
        myRightChart != undefined
      ) {
        myRightChart.dispose(); //销毁
      }
      myRightChart = echarts.init(chartDom);
      let img = "/cockpitPage/dotted-circle.png";
      let height = myRightChart.getHeight() / 1;
      let width = height + 5;
      let option;
      if (data) {
        option = {
          color: ["#dcb018", "#735b09", "#ebd68e", "#c7b36e"],
          tooltip: {
            trigger: "item",
            textStyle: {
              color: "#00FFFF",
            },
            borderColor: "#00FFFF",
            backgroundColor: "#238d8d6b",
            valueFormatter: function (value) {
              return value + "%";
            },
          },
          graphic: {
            elements: [
              {
                type: "image",
                z: 3,
                // z: 3,
                style: {
                  image: img,
                  width: 238,
                  height: 238,
                  width: width,
                  height: height,
                },
                left: "center",
                top: "center",
@@ -235,14 +294,10 @@
          },
          series: [
            {
              name: "Access From",
              name: "人员技能比",
              type: "pie",
              // center: ['80%', '46%'],
              radius: ["52%", "62%"],
              // minAngle: 20,
              // startAngle: 60,
              avoidLabelOverlap: false,
              label: {
                normal: {
                  position: "outer",
@@ -252,7 +307,11 @@
                  borderWidth: 5,
                  borderRadius: 4,
                  formatter: function (params) {
                    return `{a|${params.name}} {b|${params.value + "%"}}`;
                    let label =
                      params.name.length > 4
                        ? `${params.name.slice(0, 3)}...`
                        : params.name;
                    return `{a|${label}} {b|${params.value + "%"}}`;
                  },
                  rich: {
                    a: {
@@ -277,7 +336,7 @@
              labelLine: {
                show: true,
                length: 4,
                length2: 80,
                length2: 70,
                lineStyle: {
                  color: "#dcb018",
                },
@@ -291,10 +350,10 @@
          ],
        };
        option && myChart.setOption(option);
        option && myRightChart.setOption(option);
      } else {
        option = {};
        myChart.setOption(option, true);
        myRightChart.setOption(option, true);
      }
    },
  },
@@ -304,7 +363,7 @@
<style scoped lang="scss">
.bar-chart {
  width: 100%;
  height: calc(100% - 20px);
  height: calc(100% - 10px);
  padding: 20px 0 0;
  .bar-contents {
@@ -313,7 +372,7 @@
    .chart-left {
      width: calc(60% - 20px);
      height: 100%;
      height: calc(100% - 20px);
      margin-right: 20px;
      float: left;
      border: 1px solid #00ffff;
@@ -323,7 +382,7 @@
    .chart-right {
      width: 40%;
      float: left;
      height: 100%;
      height: calc(100% - 20px);
      position: relative;
      .chart-bg {
        width: 100%;