format.vue 3.66 KB
<!-- 业态客群洞察 -->
<template>
  <div>
    <!-- 顶部区域 S-->
    <div class="ipage_top">
      <div class="tit">
        <img :src="bindIcon('shichang3')" />{{title||chartData.title}}
      </div>
      <div class="acts"></div>
    </div>
    <div class="ichart">
      <bars-chart ref="chart" :cdata="chartData" tval="notit"></bars-chart>
    </div>
  </div>
</template>

<script>
import mixin from "./mixin";
import mallData from "@/components/Echarts/data";
import _ from 'underscore';
/**********************************************************/
const chartsConfig = {
  default: {
    //默认
    otherConf: {
      _color: ["#90BDFF"],
      reverseAxis: true,
      showBackground: true,
      labelPosition: "insideLeft",
      grid: [],
    },
  },
};
/*******************************************************/
export default {
  mixins: [mixin],
  data() {
    return {
      configObj: {},
    };
  },
  created() {},
  methods: {
    getChartsConfig() {
      return chartsConfig;
    },
    loadChartData(params) {
      // this.setChartData();
      this.chartId = this.getChartId(this.ckey);
      if (this.chartId) {
        this.ajaxModuleData().then((data) => {
          this.setChartData(data);
        });
      } else {
        this.setChartData();
      }
    },
    setChartData(data) {
      let ydata, sdata;
      ydata = {
        data: data.series.map((item) => item.name),
        type: "bar",
      };
      sdata = [];
      data.xaxis.data.forEach((item, index) => {
        let obj = {};
        obj.name = item;
        obj.data = [];
        obj.type = "bar";
        data.series.forEach((item1) => {
          obj.data.push(item1.data[index]);
        });
        sdata.push(obj);
      });
      let grids = [],
        series = [],
        xAxis = [],
        yAxis = [];
      let length = data.xaxis.data.length;
      let twidth = 5;
      let bwidth = (100 - twidth) / length;
      for (var i = 0; i < length; i++) {
        grids.push({
          left: i * bwidth + twidth + "%",
          top: 20,
          bottom: 0,
          width: bwidth - 1 + "%",
        });
        xAxis.push({
          gridIndex: i,
          type: "value",
          show: true,
          nameGap: 0,
          // name: data.xaxis.data[i],
          name: data.xaxis.data[i],
          nameTextStyle: {
            color: "#6a696c",
            fontWeight: "bold",
          },
          max: _.max(sdata[i].data)*1,
          axisLine: { show: false },
          axisTick: { show: false },
          axisLabel: { show: false },
          splitLine: { show: false },
          nameLocation: "middle",
          position: "top",
        });
        ydata.type = "category";
        yAxis.push({
          ...ydata,
          gridIndex: i,
          axisLabel: { show: i == 0, padding: [0, 10, 0, 0] },
          axisLine: { show: false },
          axisTick: { show: false },
        });
        // let item = JSON.parse(JSON.stringify(sdata));
        let item = JSON.parse(JSON.stringify(sdata[i]));
        item.showBackground = true;
        item.xAxisIndex = i;
        item.yAxisIndex = i;
        series.push(item);
      }
      let chartData = {
        xAxis,
        yAxis,
        series,
        noProcess: true,
      };
      this.configObj.otherConf._color = new Array(length).fill('#90BDFF'); 
      this.chartData = Object.assign({}, chartData, {
        otherConf: { ...(this.configObj.otherConf || {}), grid: grids },
      });
    },
  },
};
</script>

<style  scoped lang="less">
.iwrap {
  position: relative;
  display: flex;
  flex-direction: row;
  width: 100%;
  li {
    display: block;
    position: relative;
    flex: 1;
    h5 {
      text-align: center;
    }
  }
}
</style>