sankeyChart.vue 2.81 KB
<template>
  <div>
    <basic ref="basic" :chartId="chartId" :chartData="chartData"></basic>
  </div>
</template>
<script>
import mixin from "./mixin";
export default {
  mixins: [mixin],
  data() {
    return {};
  },
  methods: {
    /**
     * 预处理option参数
     * */
    preChartData(cdata) {
      return cdata;
    },
    /**
     * 处理option参数
     * */
    dealChartData(optionFormat) {
      let { _color, animation = false, orient } = optionFormat.otherConf;
      optionFormat.xAxis.show = false;
      optionFormat.yAxis.show = false;
      optionFormat.legend.show = false;
      optionFormat.grid = {
        left: 0,
        top: 0,
        right: 0,
        bottom: 0,
      };
      optionFormat.color = _color || optionFormat.color;
      optionFormat.tooltip = {
        show: true,
        trigger: "item",
        backgroundColor: "#fff",
        padding: [0, 0, 0, 0],
        textStyle: {
          color: "#333333",
        },
      };
      let option = Object.assign({}, optionFormat);

      /*option.series[0].data = [
        { value: 1048, name: 'Search Engine' },
        { value: 735, name: 'Direct' },
        { value: 580, name: 'Email' },
        { value: 484, name: 'Union Ads' },
        { value: 300, name: 'Video Ads' }
      ];*/
      option.series.forEach((item, index) => {
        item.data[0].itemStyle = {
          color: this.tval != "sankey" ? "#ffd588" : "#ea7ccc",
        };
        item.left = this.tval != "sankey3" ? "10%" : "0.5%";
        item.right = this.tval != "sankey2" ? "10%" : "0.5%";
        item.lineStyle = {
          color: this.tval != "sankey2" ? "source" : "target",
          curveness: 0.5,
        };
        item.draggable = false;
        item.orient = orient || "vertical";
        item.label = {
          formatter(params) {
            return params.name;
          },
          position:
            orient && orient == "horizontal"
              ? this.tval == "sankey3"
                ? "right"
                : "left"
              : "bottom",
        };
        if (!orient || orient != "horizontal") {
          item.data[0].label = {
            position: "top",
          };
        }
      });
      option.tooltip.formatter = (params, ticket, callback) => {
        let num = params.data.number;
        let htmls =
          "<div>" +
          '<p style="font-size:14px; text-align: left; padding:4px 15px; color:"#444444"">' +
          params.name +
          `: <br>${
            num ? '<span style="color:#0069ff">' + num + "</span>人," : ""
          }` +
          '<span style="color:#0069ff">' +
          (params.value * 100).toFixed(2) +
          `%</span></p>` +
          "</div>";
        return htmls;
      };
      return option;
    },
  },
  created() {},
};
</script>
<style scoped>
.chart {
  position: relative;
  height: 500px;
}
</style>