Skip to content

fix legend line point style not showing the dataset dash - #12292

Open
HuzaifaChaudary wants to merge 1 commit into
chartjs:masterfrom
HuzaifaChaudary:fix/legend-line-point-style-dash
Open

fix legend line point style not showing the dataset dash#12292
HuzaifaChaudary wants to merge 1 commit into
chartjs:masterfrom
HuzaifaChaudary:fix/legend-line-point-style-dash

Conversation

@HuzaifaChaudary

Copy link
Copy Markdown

fixes #12291

what happens

with usePointStyle: true and pointStyle: 'line' the legend key draws solid even when the dataset has borderDash on it. the plotted line is dashed but the key beside it is not so the two do not match.

before after
before after

why it happens

the drawing side is already right. drawLegendBox does

ctx.setLineDash(valueOrDefault(legendItem.lineDash, []));

so the dash would be honoured if it were there. it is not there. the miss is one step earlier in generateLabels

const style = meta.controller.getStyle(usePointStyle ? 0 : undefined);

when usePointStyle is on this asks for index 0 which resolves the point scope and the point element has no borderDash on it. so style.borderDash comes back undefined and the legend item gets an empty dash. when usePointStyle is off it asks for the dataset element which does carry the dash and that is why the plain box legend has always drawn it fine.

i printed both scopes on master to be sure rather than going off the defaults list

getStyle(0).borderDash         = [null, null]
getStyle(undefined).borderDash = [[], [6,3]]

the change

read the dash off the dataset element but only when the point style is line. that style stands for the dataset line itself so it should look like it. every other point style is a marker and keeps resolving exactly as before so a dashed dataset does not suddenly get a chopped up circle or rect outline. on chart types with no dataset element such as bar getStyle(undefined) falls back to the same point options so nothing moves there either.

checked

  • test/specs/plugin.legend.tests.js 79 of 79 pass and that includes all 52 legend image fixtures so the existing legend rendering is untouched
  • the new test fails without the source change
Expected $[0] = undefined to equal [  ].
Expected $[1] = undefined to equal [ 6, 3 ].
  • eslint clean on both files
  • the two shots above are the same config rendered before and after the change. only the dashed key differs and the solid key is unchanged

i went narrow on purpose here. if you would rather every point style inherit the dataset dash when usePointStyle is on i am happy to widen it. also glad to add an image fixture if you want one though the legend needs text so i left it out to avoid a chrome against firefox mismatch.

with usePointStyle the legend reads its style from the point scope and that scope has no borderDash on it so a line symbol always came out solid even when the dataset line was dashed. take the dash off the dataset element for the line point style only so markers like circle or rect keep drawing solid.
Copilot AI lite review requested due to automatic review settings August 29, 2026 17:36

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@HuzaifaChaudary
HuzaifaChaudary force-pushed the fix/legend-line-point-style-dash branch from a099b55 to a1a33cd Compare August 29, 2026 22:05
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.

Legend pointStyle: 'line' does not apply dataset borderDash pattern

2 participants