From 4272afb100ec3670c2cb48a7b5f1196966c06b3d Mon Sep 17 00:00:00 2001 From: plainheart Date: Sat, 12 Sep 2026 10:46:15 +0800 Subject: [PATCH 1/2] fix(marker): retrieve mark line precision from value rather than default precision when it targets axis value to ensure it is at the expected position --- src/component/marker/MarkLineView.ts | 14 ++- test/markLine-precision.html | 175 +++++++++++++++++++++++++++ 2 files changed, 187 insertions(+), 2 deletions(-) create mode 100644 test/markLine-precision.html diff --git a/src/component/marker/MarkLineView.ts b/src/component/marker/MarkLineView.ts index 9ee9aa43d0..0d470029c1 100644 --- a/src/component/marker/MarkLineView.ts +++ b/src/component/marker/MarkLineView.ts @@ -71,6 +71,8 @@ const markLineTransform = function ( ) { const data = seriesModel.getData(); + let precision: number; + let itemArray: MarkLineMergedItemOption[]; if (!isArray(item)) { // Special type markLine like 'min', 'max', 'average', 'median' @@ -90,12 +92,18 @@ const markLineTransform = function ( if (item.yAxis != null || item.xAxis != null) { valueAxis = coordSys.getAxis(item.yAxis != null ? 'y' : 'x'); value = retrieve(item.yAxis, item.xAxis); + // retrieve mark line precision from value rather than default precision when it targets axis value + // to ensure it is at the expected position + if (isNumber(value)) { + precision = numberUtil.getPrecision(value); + } } else { const axisInfo = markerHelper.getAxisInfo(item, data, coordSys, seriesModel); valueAxis = axisInfo.valueAxis; const valueDataDim = getStackedDimension(data, axisInfo.valueDataDim); value = markerHelper.numCalculate(data, valueDataDim, mlType); + // PENDING: auto precision for special type (min/max...) and consider supporting precision for single marker item? } const valueIndex = valueAxis.dim === 'x' ? 0 : 1; const baseIndex = 1 - valueIndex; @@ -112,9 +120,11 @@ const markLineTransform = function ( mlFrom.coord[baseIndex] = -Infinity; mlTo.coord[baseIndex] = Infinity; - const precision = mlModel.get('precision'); + if (precision == null) { + precision = mlModel.get('precision'); + } if (precision >= 0 && isNumber(value)) { - value = +value.toFixed(Math.min(precision, 20)); + value = numberUtil.round(value, precision); } mlFrom.coord[valueIndex] = mlTo.coord[valueIndex] = value; diff --git a/test/markLine-precision.html b/test/markLine-precision.html new file mode 100644 index 0000000000..5c36fd0432 --- /dev/null +++ b/test/markLine-precision.html @@ -0,0 +1,175 @@ + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + From 581ae9a39f907fa0302c553f28d93c15636a4007 Mon Sep 17 00:00:00 2001 From: plainheart Date: Sat, 12 Sep 2026 11:22:53 +0800 Subject: [PATCH 2/2] fix(marker): use raw value without precision rounding when the mark line targets a specific axis value or is in `min/max` type --- src/component/marker/MarkLineView.ts | 44 +++++++++++++++------------- test/markLine-precision.html | 4 +-- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/src/component/marker/MarkLineView.ts b/src/component/marker/MarkLineView.ts index 0d470029c1..b3b3002659 100644 --- a/src/component/marker/MarkLineView.ts +++ b/src/component/marker/MarkLineView.ts @@ -71,39 +71,41 @@ const markLineTransform = function ( ) { const data = seriesModel.getData(); - let precision: number; + let useRawValue = false; let itemArray: MarkLineMergedItemOption[]; if (!isArray(item)) { - // Special type markLine like 'min', 'max', 'average', 'median' const mlType = item.type; - if ( - mlType === 'min' || mlType === 'max' || mlType === 'average' || mlType === 'median' - // In case - // data: [{ - // yAxis: 10 - // }] - || (item.xAxis != null || item.yAxis != null) - ) { + // Special statistic type like 'min', 'max', 'average', 'median' + const isSpecialType = mlType === 'min' || mlType === 'max' || mlType === 'average' || mlType === 'median'; + // In case + // data: [{ + // yAxis: 10 + // }] + const isAxisValueType = item.xAxis != null || item.yAxis != null; + if (isSpecialType || isAxisValueType) { let valueAxis; let value; - if (item.yAxis != null || item.xAxis != null) { + if (isAxisValueType) { valueAxis = coordSys.getAxis(item.yAxis != null ? 'y' : 'x'); value = retrieve(item.yAxis, item.xAxis); - // retrieve mark line precision from value rather than default precision when it targets axis value + + // use raw value without precision rounding when targeting axis value // to ensure it is at the expected position - if (isNumber(value)) { - precision = numberUtil.getPrecision(value); - } + useRawValue = true; } else { const axisInfo = markerHelper.getAxisInfo(item, data, coordSys, seriesModel); valueAxis = axisInfo.valueAxis; const valueDataDim = getStackedDimension(data, axisInfo.valueDataDim); value = markerHelper.numCalculate(data, valueDataDim, mlType); - // PENDING: auto precision for special type (min/max...) and consider supporting precision for single marker item? + // PENDING: + // consider supporting precision for single marker item and auto precision for statistic type (average/median)? + + // use raw value for min/max value + useRawValue = mlType === 'min' || mlType === 'max'; } const valueIndex = valueAxis.dim === 'x' ? 0 : 1; const baseIndex = 1 - valueIndex; @@ -120,11 +122,11 @@ const markLineTransform = function ( mlFrom.coord[baseIndex] = -Infinity; mlTo.coord[baseIndex] = Infinity; - if (precision == null) { - precision = mlModel.get('precision'); - } - if (precision >= 0 && isNumber(value)) { - value = numberUtil.round(value, precision); + if (!useRawValue) { + const precision = mlModel.get('precision'); + if (precision >= 0 && isNumber(value)) { + value = numberUtil.round(value, precision); + } } mlFrom.coord[valueIndex] = mlTo.coord[valueIndex] = value; diff --git a/test/markLine-precision.html b/test/markLine-precision.html index 5c36fd0432..4f9e39adb8 100644 --- a/test/markLine-precision.html +++ b/test/markLine-precision.html @@ -100,7 +100,7 @@ data: [ 2.024, 2.024, 2.025, 2.02, 2.026, 2.025, 2.019, 2.024, 2.023, 2.022, 2.024, 2.018, 2.02, 2.022, 2.02, 2.027, 2.026, 2.027, 2.027, 2.025, - 2.027, 2.026, 2.027, 2.027, 2.029, 2.031, 2.025, 2.027 + 2.027, 2.026, 2.027, 2.027, 2.029, 2.03194, 2.025, 2.027 ], type: 'line', markLine: { @@ -159,7 +159,7 @@ var chart = testHelper.create(echarts, 'main0', { title: [ - 'Use value precision for marker line that targets axis value' + 'Use raw value without precision rounding when the mark line **targets a specific axis value** or is **in `min/max` type**' ], option: option });