Skip to content

Fix category scales inferring labels from other scales - #12405

Open
Yahiro025 wants to merge 1 commit into
chartjs:masterfrom
Yahiro025:fix-category-scale-labels
Open

Yahiro025 wants to merge 1 commit into
chartjs:masterfrom
Yahiro025:fix-category-scale-labels

Conversation

@Yahiro025

Copy link
Copy Markdown

Fixes #11495

Problem

With more than one category scale and no data.labels or scale labels, each scale shows categories from the other scales. A medications axis and an encounters axis both end up labeled "Medications" and "Encounters", and the bars are placed on the wrong index. The same mix happens between a category x scale and a category y scale.

Root cause

CategoryScale.parse infers a missing string label by pushing it onto the array from getLabels(). That falls through to the shared chart.data.labels array. Every category scale appends to the same list, so later buildTicks walks categories that were parsed by a different scale.

Fix

When another category scale exists and the user did not supply labels, the inferred labels stay on the scale that parsed them. One category scale still writes inferred labels into data.labels. options.labels, data.xLabels, data.yLabels, and a non-empty data.labels are unchanged.

Tests

Regression coverage in test/specs/scale.category.tests.js:

  • two x category scales infer only their own categories and place the value on tick 0
  • category x and category y do not share inferred labels
  • a single category scale still fills data.labels
  • user-supplied data.labels are still shared

The new assertions failed before the change (['Medications', 'Encounters'] on both scales). The category specs and the full Chrome Karma suite pass afterward, and pnpm run lint passes.

Scope

src/scales/scale.category.js and the category scale spec. No public options and no change for charts that already pass labels.

When several category scales have no labels of their own, each one
appends its values to the shared data.labels array, so every scale
shows categories that belong to the others.

Keep inferred labels on the scale that parsed them. A single category
scale still writes them into data.labels, and labels supplied by the
user are unchanged.

Fixes chartjs#11495
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.

Category scale infers labels from data plotted on other scales

1 participant