From 9e60fb89a8b1c8a1d16b557b20b6d0a509f37983 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期五, 04 六月 2021 19:22:39 +0800 Subject: [PATCH] 2021-06-04 --- src/tabviews/custom/components/chart/antv-pie/index.jsx | 48 ++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 42 insertions(+), 6 deletions(-) diff --git a/src/tabviews/custom/components/chart/antv-pie/index.jsx b/src/tabviews/custom/components/chart/antv-pie/index.jsx index 717b6d7..5bb3f99 100644 --- a/src/tabviews/custom/components/chart/antv-pie/index.jsx +++ b/src/tabviews/custom/components/chart/antv-pie/index.jsx @@ -514,6 +514,17 @@ let type = plot.type let color = plot.color + 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) + } + }) + } + let _data = this.getnestdata() const dvx = new DataView().source(_data) @@ -577,7 +588,6 @@ .interval() .adjust('stack') .position(Y_axis) - .color(type) .tooltip(`${type}*${Y_axis}`, (type, percent) => { if (plot.show !== 'value') { percent = (percent * 100).toFixed(2) + '%' @@ -591,6 +601,19 @@ lineWidth: 1, stroke: '#fff', }) + if (plot.colors && plot.colors.length > 0) { + let limit = chartColors.length + chart1.color(type, (_type) => { + if (colors.has(_type)) { + return colors.get(_type) + } else { + colorIndex++ + return chartColors[(colorIndex - 1) % limit] + } + }) + } else { + chart1.color(type) + } if (plot.label !== 'false') { chart1.label(type, { @@ -618,7 +641,6 @@ .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) + '%' @@ -632,6 +654,20 @@ lineWidth: 1, stroke: '#fff', }) + + if (plot.colors && plot.colors.length > 0) { + let limit = chartColors.length + chart2.color(X_axis, (type) => { + if (colors.has(type)) { + return colors.get(type) + } else { + colorIndex++ + return chartColors[(colorIndex - 1) % limit] + } + }) + } else { + chart2.color(X_axis) + } if (plot.label !== 'false') { if (plot.label === 'inner') { @@ -810,11 +846,11 @@ if (plot.colors && plot.colors.length > 0) { let limit = chartColors.length _chart.color(X_axis, (type) => { - if (colors.get(type)) { + if (colors.has(type)) { return colors.get(type) } else { - colors.set(type, chartColors[colorIndex % limit]) colorIndex++ + return chartColors[(colorIndex - 1) % limit] } }) } else { @@ -877,11 +913,11 @@ if (plot.colors && plot.colors.length > 0) { let limit = chartColors.length _chart.color(X_axis, (type) => { - if (colors.get(type)) { + if (colors.has(type)) { return colors.get(type) } else { - colors.set(type, chartColors[colorIndex % limit]) colorIndex++ + return chartColors[(colorIndex - 1) % limit] } }) } else { -- Gitblit v1.8.0