diff --git a/common/changes/@visactor/vchart/fix-bug-for-sampling_2026-04-28-11-20.json b/common/changes/@visactor/vchart/fix-bug-for-sampling_2026-04-28-11-20.json new file mode 100644 index 0000000000..6808a2d5b3 --- /dev/null +++ b/common/changes/@visactor/vchart/fix-bug-for-sampling_2026-04-28-11-20.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@visactor/vchart", + "comment": "fix: bar smapling not work bug. fix#4571", + "type": "none" + } + ], + "packageName": "@visactor/vchart" +} \ No newline at end of file diff --git a/packages/vchart/__tests__/unit/chart/bar.test.ts b/packages/vchart/__tests__/unit/chart/bar.test.ts index f3d0043a94..6d86761aba 100644 --- a/packages/vchart/__tests__/unit/chart/bar.test.ts +++ b/packages/vchart/__tests__/unit/chart/bar.test.ts @@ -225,6 +225,34 @@ describe('Bar chart test', () => { expect(series.fieldX2).toBeUndefined(); }); + test('Bar chart with lttb sampling should keep valid bar data', () => { + const samplingSpec = { + type: 'bar', + data: [ + { + id: 'barData', + values: [ + { month: 'Monday', sales: 22 }, + { month: 'Tuesday', sales: 13 }, + { month: 'Wednesday', sales: 25 }, + { month: 'Thursday', sales: 29 }, + { month: 'Friday', sales: 38 } + ] + } + ], + xField: 'month', + yField: 'sales', + sampling: 'lttb' + }; + chart = createBarChart(samplingSpec); + + const series: BarSeries = chart.getAllSeries()[0] as BarSeries; + series.getRegion().setLayoutRect({ width: 500, height: 500 }); + series.compile(); + + expect(series.getData().getProduct()).toHaveLength(5); + }); + test('stackCornerRadius should build valid clip paths when barMinHeight is enabled', () => { const stackSpec = { type: 'bar', diff --git a/packages/vchart/src/series/bar/bar.ts b/packages/vchart/src/series/bar/bar.ts index 5ef1938b62..cced15b1ed 100644 --- a/packages/vchart/src/series/bar/bar.ts +++ b/packages/vchart/src/series/bar/bar.ts @@ -961,7 +961,7 @@ export class BarSeries extends Cartes this._data.setTransform([ { - type: 'sampling', + type: 'dataSampling', size: this._direction === Direction.horizontal ? height : width, factor: this._spec.samplingFactor, yfield: this._direction === Direction.horizontal ? fieldsX[0] : fieldsY[0],