diff --git a/src/chart/bar/BarView.ts b/src/chart/bar/BarView.ts index eac83aab02..38fccd44e0 100644 --- a/src/chart/bar/BarView.ts +++ b/src/chart/bar/BarView.ts @@ -1041,8 +1041,8 @@ function updateStyle( ) ) : (isHorizontalOrRadial - ? ((layout as RectLayout).height >= 0 ? 'bottom' : 'top') - : ((layout as RectLayout).width >= 0 ? 'right' : 'left')); + ? getLabelPositionForHorizontal(layout as RectLayout, seriesModel.coordinateSystem) + : getLabelPositionForVertical(layout as RectLayout, seriesModel.coordinateSystem)); const labelStatesModels = getLabelStatesModels(itemModel); @@ -1288,4 +1288,22 @@ function createBackgroundEl( }); } +function getLabelPositionForHorizontal(layout: RectLayout, coordSys: CoordSysOfBar): 'top' | 'bottom' { + if (layout.height === 0) { + // For zero height, determine position based on axis inverse status + const valueAxis = (coordSys as Cartesian2D).getOtherAxis((coordSys as Cartesian2D).getBaseAxis()); + return valueAxis.inverse ? 'bottom' : 'top'; + } + return layout.height > 0 ? 'bottom' : 'top'; +} + +function getLabelPositionForVertical(layout: RectLayout, coordSys: CoordSysOfBar): 'left' | 'right' { + if (layout.width === 0) { + // For zero width, determine position based on axis inverse status + const valueAxis = (coordSys as Cartesian2D).getOtherAxis((coordSys as Cartesian2D).getBaseAxis()); + return valueAxis.inverse ? 'left' : 'right'; + } + return layout.width >= 0 ? 'right' : 'left'; +} + export default BarView; diff --git a/test/bar-zero-label.html b/test/bar-zero-label.html new file mode 100644 index 0000000000..c69de751a3 --- /dev/null +++ b/test/bar-zero-label.html @@ -0,0 +1,119 @@ + + + + +
+ + + + + + + + + +