yangfeng
2023-12-11 da4d9e70d2c37f59a365b0fb88ad70e8c1ba79b4
src/views/cockpitPage/components/MaterialChart.vue
@@ -11,55 +11,72 @@
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 {
          datax: [],
          datay: [],
        };
      },
    },
  },
  data() {
    return {
      chartData: {
        datax: [
          "产品1",
          "产品2",
          "产品3",
          "产品4",
          "产品5",
          "产品6",
          "产品7",
          "产品8",
          "产品9",
          "产品10",
        ],
        datay: [120, 200, 150, 380, 470, 150, 230, 130, 210, 145, 330],
      },
      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() {},
  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";
      let spirit = "/cockpitPage/order-bg.png";
      if (data) {
        option = {
          color: ["#00FFFF", "#dcb018"],
          color: ["#00FFFF", "#fccd1d"],
          tooltip: {
            trigger: "axis",
            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: [
@@ -67,8 +84,11 @@
              type: "inside",
              yAxisIndex: 0,
              show: false,
              startValue: 0, // 从头开始
              endValue: 5, // 一次性展示几个
              startValue: that.startValue, // 从头开始
              endValue: that.endValue, // 一次性展示几个
              zoomOnMouseWheel: false,
              moveOnMouseWheel: true,
              moveOnMouseMove: true,
            },
          ],
          legend: {
@@ -81,6 +101,7 @@
          yAxis: [
            {
              type: "category",
              inverse: true,
              axisTick: {
                show: false,
              },
@@ -94,15 +115,22 @@
                // rotate:45,
                margin: 10,
                show: true,
                fontSize: 12,
                textStyle: {
                  color: function (params, index) {
                    let colorList = ["#dcb018", "#00FFFF"];
                    let colorList = ["#fccd1d", "#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 : [],
@@ -142,20 +170,28 @@
                textStyle: {
                  color: "#00FFFF",
                },
                formatter: function (value) {
                  return `${(value / 1000).toFixed(1)}k`;
                },
              },
            },
          ],
          series: [
            {
              type: "bar",
              type: "pictorialBar",
              name: "",
              barWidth: "15",
              symbol: spirit,
              symbolRepeat: true,
              symbolMargin: "25%",
              symbolClip: true,
              symbolSize: [4, 11],
              barCategoryGap: "40%",
              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 {
@@ -168,8 +204,7 @@
            },
          ],
        };
        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;