From 379fba7590d11bfbc295488d3a0e17ebf8013e92 Mon Sep 17 00:00:00 2001 From: jianneng-fit2cloud Date: Thu, 26 Mar 2026 16:50:34 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E5=9B=BE=E8=A1=A8):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E8=BE=85=E5=8A=A9=E7=BA=BF-=E6=95=B0=E5=80=BC=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E6=B2=A1=E6=9C=89=E4=B8=8E=E8=BD=B4=E6=A0=87=E7=AD=BE?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E7=BB=9F=E4=B8=80=E7=9A=84=E9=97=AE=E9=A2=98?= =?UTF-8?q?=EF=BC=8C=E4=BB=A5=E5=8F=8A=E8=BE=85=E5=8A=A9=E7=BA=BF=E6=96=87?= =?UTF-8?q?=E6=9C=AC=E6=A0=B7=E5=BC=8F=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/js/panel/charts/g2/bar/bar.ts | 48 ++++++++++++------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/bar.ts b/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/bar.ts index a7f3b36b4a..9bd0b78126 100644 --- a/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/bar.ts +++ b/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/bar.ts @@ -19,6 +19,7 @@ import { } from '@/views/chart/components/js/panel/common/common_antv' import { DEFAULT_BASIC_STYLE, + DEFAULT_XAXIS_STYLE, DEFAULT_YAXIS_EXT_STYLE, DEFAULT_YAXIS_STYLE } from '@/views/chart/components/editor/util/chart' @@ -533,17 +534,27 @@ export class Bar extends G2ChartView { if (assistLineArr?.length > 0) { const customStyle = parseJson(chart.customStyle) let axisFormatterCfg, axisExtFormatterCfg - if (customStyle.yAxis) { - const a = JSON.parse(JSON.stringify(customStyle.yAxis)) - axisFormatterCfg = a.axisLabelFormatter - ? a.axisLabelFormatter - : DEFAULT_YAXIS_STYLE.axisLabelFormatter - } - if (customStyle.yAxisExt) { - const a = JSON.parse(JSON.stringify(customStyle.yAxisExt)) - axisExtFormatterCfg = a.axisLabelFormatter - ? a.axisLabelFormatter - : DEFAULT_YAXIS_EXT_STYLE.axisLabelFormatter + const isHorizontalBar = this.name.includes('horizontal') + if (isHorizontalBar) { + if (customStyle.xAxis) { + const a = JSON.parse(JSON.stringify(customStyle.xAxis)) + axisFormatterCfg = a.axisLabelFormatter + ? a.axisLabelFormatter + : DEFAULT_XAXIS_STYLE.axisLabelFormatter + } + } else { + if (customStyle.yAxis) { + const a = JSON.parse(JSON.stringify(customStyle.yAxis)) + axisFormatterCfg = a.axisLabelFormatter + ? a.axisLabelFormatter + : DEFAULT_YAXIS_STYLE.axisLabelFormatter + } + if (customStyle.yAxisExt) { + const a = JSON.parse(JSON.stringify(customStyle.yAxisExt)) + axisExtFormatterCfg = a.axisLabelFormatter + ? a.axisLabelFormatter + : DEFAULT_YAXIS_EXT_STYLE.axisLabelFormatter + } } const fixedLines = assistLineArr.filter(ele => ele.field === '0') const dynamicLineFields = assistLineArr @@ -562,25 +573,28 @@ export class Bar extends G2ChartView { const lines = fixedLines.concat(dynamicLines || []) lines.forEach(item => { const value = parseFloat(item.value) - const content = - item.name + - ' : ' + - valueFormatter(value, item.yAxisType === 'left' ? axisFormatterCfg : axisExtFormatterCfg) + const targetFormatter = + item.yAxisType === 'left' || !axisExtFormatterCfg ? axisFormatterCfg : axisExtFormatterCfg + const content = item.name + ' : ' + valueFormatter(value, targetFormatter) + const fontSize = item.fontSize ? parseInt(item.fontSize + '') : '100%' assistLine.push({ type: 'lineY', data: [value], style: { stroke: item.color, + strokeOpacity: 1, lineDash: getLineDash(item.lineType) }, labels: [ { text: content, - position: 'left', + position: isHorizontalBar ? 'inside' : 'left', textBaseline: 'bottom', fill: item.color, + fillOpacity: 1, background: false, - fontSize: item.fontSize ? item.fontSize : 10 + fontSize, + style: isHorizontalBar ? { transform: 'rotate(90deg)' } : undefined } ] })