管道基础大数据平台系统开发-【前端】-新系統界面
1
Surpriseplus
2022-12-19 9c803f20cc05395bac2d3386accfe230210c07dc
src/components/echart26.vue
@@ -10,15 +10,18 @@
  components: {},
  data() {
    //这里存放数据
    return {};
    return { myChart };
  },
  mounted() {
    this.lineChart();
    this.$bus.$on('resizeEchart', (res) => {
      this.myChart.resize();
    });
  },
  //方法集合
  methods: {
    lineChart() {
      let dataAxis = ["A2", "A3", "A4", "A5", "A6", "A7"];
      let dataAxis = ['A2', 'A3', 'A4', 'A5', 'A6', 'A7'];
      // prettier-ignore
      let data =  [300,200,80,120,80,50];
      let yMax = 500;
@@ -28,33 +31,33 @@
      }
      let option = {
        title: {
          text: "各项目数据量",
          text: '各项目数据量',
          textStyle: {
            color: "#fff",
            color: '#fff',
          },
        },
        tooltip: {
          trigger: "axis",
          trigger: 'axis',
          axisPointer: {
            type: "shadow",
            type: 'shadow',
          },
        },
        grid: {
          left: "0%",
          right: "0%",
          bottom: "0%",
          left: '0%',
          right: '0%',
          bottom: '0%',
          containLabel: true,
        },
        xAxis: {
          type: "category",
          type: 'category',
          data: dataAxis,
          axisLabel: {
            show: true,
            textStyle: {
              color: "#fff",
              color: '#fff',
            },
            formatter: function (params) {
              var newParamsName = ""; // 最终拼接成的字符串
              var newParamsName = ''; // 最终拼接成的字符串
              var paramsNameNumber = params.length; // 实际标签的个数
              var provideNumber = 6; // 每行能显示的字的个数
              var rowNumber = Math.ceil(paramsNameNumber / provideNumber); // 换行的话,需要显示几行,向上取整
@@ -65,7 +68,7 @@
              if (paramsNameNumber > provideNumber) {
                /** 循环每一行,p表示行 */
                for (var p = 0; p < rowNumber; p++) {
                  var tempStr = ""; // 表示每一次截取的字符串
                  var tempStr = ''; // 表示每一次截取的字符串
                  var start = p * provideNumber; // 开始截取的位置
                  var end = start + provideNumber; // 结束截取的位置
                  // 此处特殊处理最后一行的索引值
@@ -74,7 +77,7 @@
                    tempStr = params.substring(start, paramsNameNumber);
                  } else {
                    // 每一次拼接字符串并换行
                    tempStr = params.substring(start, end) + "\n";
                    tempStr = params.substring(start, end) + '\n';
                  }
                  newParamsName += tempStr; // 最终拼成的字符串
                }
@@ -98,32 +101,32 @@
          axisLabel: {
            show: true,
            textStyle: {
              color: "#fff",
              color: '#fff',
            },
          },
        },
        dataZoom: [
          {
            type: "inside",
            type: 'inside',
          },
        ],
        series: [
          {
            type: "bar",
            type: 'bar',
            showBackground: true,
            itemStyle: {
              color: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [
                { offset: 0, color: "#83bff6" },
                { offset: 0.5, color: "#188df0" },
                { offset: 1, color: "#188df0" },
                { offset: 0, color: '#83bff6' },
                { offset: 0.5, color: '#188df0' },
                { offset: 1, color: '#188df0' },
              ]),
            },
            emphasis: {
              itemStyle: {
                color: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [
                  { offset: 0, color: "#2378f7" },
                  { offset: 0.7, color: "#2378f7" },
                  { offset: 1, color: "#83bff6" },
                  { offset: 0, color: '#2378f7' },
                  { offset: 0.7, color: '#2378f7' },
                  { offset: 1, color: '#83bff6' },
                ]),
              },
            },
@@ -132,11 +135,11 @@
        ],
      };
      const zoomSize = 6;
      let myChart = this.$echarts.init(document.getElementById("echart26"));
      myChart.on("click", function (params) {
      this.myChart = this.$echarts.init(document.getElementById('echart26'));
      this.myChart.on('click', function (params) {
        console.log(dataAxis[Math.max(params.dataIndex - zoomSize / 2, 0)]);
        myChart.dispatchAction({
          type: "dataZoom",
        this.myChart.dispatchAction({
          type: 'dataZoom',
          startValue: dataAxis[Math.max(params.dataIndex - zoomSize / 2, 0)],
          endValue:
            dataAxis[
@@ -145,9 +148,9 @@
        });
      });
      myChart.setOption(option);
      window.addEventListener("resize", function () {
        myChart.resize();
      this.myChart.setOption(option);
      window.addEventListener('resize', function () {
        this.myChart.resize();
      });
    },
  },