king
2020-11-18 d3272e82652361e5e9bd045925222ef042b6731f
src/tabviews/custom/components/chart/antv-pie/index.jsx
@@ -8,6 +8,7 @@
// import searchLine from '../../share/searchLine'
import Api from '@/api'
import Utils from '@/utils/utils.js'
import { chartColors } from '@/utils/option.js'
import UtilsDM from '@/utils/utils-datamanage.js'
import './index.scss'
@@ -247,6 +248,7 @@
      let _mdata = new Map()
      _cdata.forEach(item => {
        if (item[plot.Xaxis] && !_mdata.has(item[plot.Xaxis])) {
          if (typeof(item[plot.Yaxis]) !== 'number') {
            item[plot.Yaxis] = parseFloat(item[plot.Yaxis])
            if (isNaN(item[plot.Yaxis])) {
@@ -306,6 +308,7 @@
      Y_axis = 'percent' // 显示百分比
    }
    chart.data(dv.rows)
    if (plot.shape === 'nightingale') {
@@ -351,12 +354,22 @@
      })
    }
    let colors = new Map()
    let colorIndex = 0
    if (plot.colors && plot.colors.length > 0) {
      plot.colors.forEach(item => {
        if (!colors.has(item.label)) {
          colors.set(item.label, item.color)
        }
      })
    }
    if (plot.shape !== 'nightingale') {
      let _chart = chart
        .interval()
        .adjust('stack')
        .position(Y_axis)
        .color(X_axis)
        .tooltip(`${X_axis}*${Y_axis}`, (name, value) => {
          if (plot.show !== 'value') {
            value = (value * 100).toFixed(2) + '%'
@@ -366,6 +379,19 @@
            value: value
          }
        })
      if (plot.colors && plot.colors.length > 0) {
        let limit = chartColors.length
        _chart.color(X_axis, (type) => {
          if (colors.get(type)) {
            return colors.get(type)
          } else {
            colors.set(type, chartColors[colorIndex % limit])
            colorIndex++
          }
        })
      } else {
        _chart.color(X_axis)
      }
      if (plot.label !== 'false') {
        if (plot.label === 'inner') {
          _chart.label(Y_axis, {
@@ -419,24 +445,36 @@
      let _chart = chart
        .interval()
        .position(`${X_axis}*${Y_axis}`)
        .color(X_axis)
        if (plot.label !== 'false') {
          let _label = {}
          if (plot.label === 'inner') {
            _label.offset = -15
      if (plot.colors && plot.colors.length > 0) {
        let limit = chartColors.length
        _chart.color(X_axis, (type) => {
          if (colors.get(type)) {
            return colors.get(type)
          } else {
            _label.style = {
              fill: color
            }
            colors.set(type, chartColors[colorIndex % limit])
            colorIndex++
          }
          _chart.label(X_axis, _label)
          .style({
            lineWidth: 1,
            stroke: '#fff',
          })
        })
      } else {
        _chart.color(X_axis)
      }
      if (plot.label !== 'false') {
        let _label = {}
        if (plot.label === 'inner') {
          _label.offset = -15
        } else {
          _label.style = {
            fill: color
          }
        }
        _chart.label(X_axis, _label)
        .style({
          lineWidth: 1,
          stroke: '#fff',
        })
      }
    }
    chart.render()