Skip to content

fix: only count bar dataset axes in bar width calculation for multiple x-axis#12263

Open
godfengliang wants to merge 1 commit into
chartjs:masterfrom
godfengliang:fix-bar-width-multiple-axis
Open

fix: only count bar dataset axes in bar width calculation for multiple x-axis#12263
godfengliang wants to merge 1 commit into
chartjs:masterfrom
godfengliang:fix-bar-width-multiple-axis

Conversation

@godfengliang
Copy link
Copy Markdown

Fixes #12262

Problem

When a chart has both bar and line datasets on different x-axes, the bar width is incorrectly calculated. The _getAxis() method counts ALL dataset axes (including those used by non-bar datasets like line), causing stackCount * axisCount to be larger than necessary and bars to appear thinner than they should.

Root Cause

Commit 8ea47ca introduced _getAxis() to handle stacked bars with multiple x-axes. However, it iterates over ALL datasets regardless of type, collecting axes from line/scatter/etc. datasets that do not affect bar width.

Fix

Modified _getAxis() to skip datasets whose resolved type (meta.type) does not match the bar controller type (this._type). This ensures only axes containing bar datasets are counted, consistent with how _getStacks() already filters by type via getMatchingVisibleMetas(this._type).

Before: Axis count includes line dataset axes -> bars too thin
After: Axis count only includes bar dataset axes -> bars fill correct width

Testing

The existing test stacked-and-multiple-axis.js (all bar datasets) continues to work correctly since all datasets have type === 'bar'. Mixed charts (bar + line) now correctly exclude line dataset axes from the calculation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrong bar width with multiple x-Axis

1 participant