From d3272e82652361e5e9bd045925222ef042b6731f Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期三, 18 十一月 2020 18:15:15 +0800 Subject: [PATCH] 2020-11-18 --- src/tabviews/custom/components/chart/antv-pie/index.jsx | 68 ++++++++++++++++++++++++++------- 1 files changed, 53 insertions(+), 15 deletions(-) diff --git a/src/tabviews/custom/components/chart/antv-pie/index.jsx b/src/tabviews/custom/components/chart/antv-pie/index.jsx index 447101a..4f7ce11 100644 --- a/src/tabviews/custom/components/chart/antv-pie/index.jsx +++ b/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() -- Gitblit v1.8.0