king
2021-09-01 31ec63f0419895876cbaba99637a884a32d33d0d
src/tabviews/zshare/chartcomponent/index.jsx
@@ -22,11 +22,10 @@
    data: PropTypes.array,           // 图表传入数据
    loading: PropTypes.bool,         // 数据加载中
    config: PropTypes.object,        // 页面配置信息
    getexceloutparam: PropTypes.func // 获取excel导出参数
  }
  state = {
    dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS, // 字典
    dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS, // 字典
    empty: true,               // 图表数据为空
    actions: [],               // 图表绑定的按钮组
    chartId: Utils.getuuid(),  // 图表Id
@@ -79,7 +78,7 @@
              percentFields.push(_column.label)
            }
          })
        } catch {
        } catch (e) {
          console.warn('Incorrect percentage setting')
        }
      }
@@ -230,22 +229,6 @@
      })
      _data = [..._mdata.values()]
    }
    if (plot.correction && plot.chartType === 'bar' && _data.length > 0 && _data.length < plot.correction) {
      if (plot.enabled !== 'true' || (plot.customs && plot.customs.filter(cell => cell.chartType !== 'bar').length === 0)) {
        let _num = plot.correction - _data.length
        for (let i = 0; i < _num; i++) {
          let _val = Array( i + 2 ).join(' ')
          let _cell = {}
          _cell[plot.Xaxis] = _val
          _columns.forEach(col => {
            _cell[col.field] = ''
          })
          _data.push(_cell)
        }
      }
    }
    this.setState({empty: _data.length === 0})
@@ -431,10 +414,15 @@
    let _data = []
    let _valfield = 'value'
    let _typefield = 'key'
    let ispercent = false
    if (plot.datatype === 'statistics') {
      _valfield = plot.InfoValue
      _typefield = plot.InfoType
      if (percentFields.length > 0) {
        ispercent = true
      }
      _data = this.getStaticData()
    } else {
@@ -490,7 +478,8 @@
      })
    }
    chart.scale(_valfield, {
      nice: true
      nice: true,
      range: [0, 0.93]
    })
    // 坐标轴格式化
@@ -499,8 +488,8 @@
        formatter: (val) => {
          if (!val || /^\s*$/.test(val)) return val
          let _val = `${val}`
          if (_val.length <= 10) return val
          return _val.substring(0, 7) + '...'
          if (_val.length <= 11) return val
          return _val.substring(0, 8) + '...'
        }
      }
    })
@@ -540,7 +529,7 @@
      .tooltip(`${plot.Xaxis}*${_valfield}*${_typefield}`, (name, value, type) => {
        return {
          name: type,
          value: percentFields.includes(type) ? value + '%' : value
          value: percentFields.includes(type) || ispercent ? value + '%' : value
        }
      })
@@ -633,8 +622,8 @@
        formatter: (val) => {
          if (!val || /^\s*$/.test(val)) return val
          let _val = `${val}`
          if (_val.length <= 10) return val
          return _val.substring(0, 7) + '...'
          if (_val.length <= 11) return val
          return _val.substring(0, 8) + '...'
        }
      }
    })
@@ -746,10 +735,15 @@
    let _data = []
    let _valfield = 'value'
    let _typefield = 'key'
    let ispercent = false
    if (plot.datatype === 'statistics') {
      _valfield = plot.InfoValue
      _typefield = plot.InfoType
      if (percentFields.length > 0) {
        ispercent = true
      }
      _data = this.getStaticData()
    } else {
@@ -798,13 +792,21 @@
    // dodge is not support linear attribute, please use category attribute! 时间格式
    if (_data[0] && _data[0][plot.Xaxis] && /^\d{4}-\d{2}-\d{2}(\s\d{2}:\d{2}:\d{2})?/.test(_data[0][plot.Xaxis])) {
      for (let i = 1; i < 12; i++) {
        if (_data[i] && _data[i][plot.Xaxis] === _data[0][plot.Xaxis]) {
          _data[i][plot.Xaxis] += ' '
        } else {
          break;
        }
      }
      _data[0][plot.Xaxis] += ' '
    }
    chart.data(_data)
    chart.scale(_valfield, {
      nice: true
      nice: true,
      range: [0, 0.93]
    })
    // 坐标轴格式化
@@ -813,8 +815,8 @@
        formatter: (val) => {
          if (!val || /^\s*$/.test(val)) return val
          let _val = `${val}`
          if (_val.length <= 10) return val
          return _val.substring(0, 7) + '...'
          if (_val.length <= 11) return val
          return _val.substring(0, 8) + '...'
        }
      }
    })
@@ -851,6 +853,7 @@
      let _chart = chart
        .interval()
        .position(`${plot.Xaxis}*${_valfield}`)
        .size(30)
        .color(_typefield)
        .adjust([
          {
@@ -862,7 +865,7 @@
        .tooltip(`${plot.Xaxis}*${_valfield}*${_typefield}`, (name, value, type) => {
          return {
            name: type,
            value: percentFields.includes(type) ? value + '%' : value
            value: percentFields.includes(type) || ispercent ? value + '%' : value
          }
        })
@@ -873,13 +876,14 @@
      let _chart = chart
        .interval()
        .position(`${plot.Xaxis}*${_valfield}`)
        .size(30)
        .color(_typefield)
        .adjust('stack')
        .shape(plot.shape || 'rect')
        .tooltip(`${plot.Xaxis}*${_valfield}*${_typefield}`, (name, value, type) => {
          return {
            name: type,
            value: percentFields.includes(type) ? value + '%' : value
            value: percentFields.includes(type) || ispercent ? value + '%' : value
          }
        })
@@ -975,8 +979,10 @@
          }
        })
      if (plot.label === 'true') {
        let setting = {
      if (plot.label !== 'false') {
        _chart.label('percent', {
          layout: { type: 'pie-spider' },
          labelHeight: 20,
          content: (data) => {
            let val = data[plot.Xaxis]
            if (val) {
@@ -986,20 +992,14 @@
              }
            }
            return `${val}: ${(data.percent * 100).toFixed(2)}%`
          },
          labelLine: {
            style: {
              lineWidth: 0.5,
            },
          }
        }
        if (plot.labelLayout === 'overlap') {
          setting.type = 'pie'
          setting.layout = {
            type: 'overlap'
          }
          setting.offset = 0
        }
        _chart.label('percent', setting)
        })
      }
    } else {
      let _chart = chart
        .interval()
@@ -1091,8 +1091,6 @@
                    btn={item}
                    show="icon"
                    setting={config.setting}
                    getexceloutparam={this.props.getexceloutparam}
                    updateStatus={() => {}}
                  />
                )
              } else {
@@ -1104,7 +1102,6 @@
                    btn={item}
                    show="icon"
                    setting={config.setting}
                    updateStatus={() => {}}
                  />
                )
              }