From fc176de273dd8b3a8fb4ff8958d43522bee86e8f Mon Sep 17 00:00:00 2001 From: ulleo Date: Fri, 11 Jul 2025 10:48:53 +0800 Subject: [PATCH] fix: pie null value --- .../src/views/chat/component/charts/Pie.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/frontend/src/views/chat/component/charts/Pie.ts b/frontend/src/views/chat/component/charts/Pie.ts index 39c4769b..be9bd727 100644 --- a/frontend/src/views/chat/component/charts/Pie.ts +++ b/frontend/src/views/chat/component/charts/Pie.ts @@ -1,7 +1,7 @@ import { BaseG2Chart } from '@/views/chat/component/BaseG2Chart.ts' import type { ChartAxis, ChartData } from '@/views/chat/component/BaseChart.ts' import type { G2Spec } from '@antv/g2' -import { endsWith, replace } from 'lodash-es' +import { endsWith, filter, replace } from 'lodash-es' export class Pie extends BaseG2Chart { constructor(id: string) { @@ -17,12 +17,21 @@ export class Pie extends BaseG2Chart { return } - // 特殊处理 % + // % const _data = [] let isPercent = false - if (data.length > 0) { - const v = data[0][y[0].value] + '' - if (endsWith(v, '%')) { + const notEmptyData = filter( + data, + (d) => + d && + d[y[0].value] !== null && + d[y[0].value] !== undefined && + d[y[0].value] !== 0 && + d[y[0].value] !== '0' + ) + if (notEmptyData.length > 0) { + const v = notEmptyData[0][y[0].value] + '' + if (endsWith(v.trim(), '%')) { isPercent = true } }