Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scales don't update when toggling data (compared to datasets) visibility #11949

Open
alex-statsig opened this issue Nov 8, 2024 · 0 comments

Comments

@alex-statsig
Copy link

alex-statsig commented Nov 8, 2024

Expected behavior

I would expect the scales to update when some of the data has been toggled off, similar to when a dataset is toggled off.

In particular:

  • the "y" scale should auto-scale / shrink to the bounds of the data being displayed
  • the "x" category scale which shows a column for each piece of data should ideally remove that column if its data is hidden

Current behavior

Currently, the scale factors in all data regardless of if they're hidden (only shrinking the scale if a dataset gets hidden)

Reproducible sample

https://codepen.io/alexrcoleman/pen/KKOryXe

Optional extra steps/info to reproduce

Toggle some categories using the legend (referencing the pie chart legend plugin settings which uses chart.toggleDataVisibility() to hide one piece of data), observe that the y-axis does not resize and the x-axis continues reserving space (making the ability to toggle that data fairly pointless here)

Possible solution

The scales could be updated to only factor in visible data. For category scale, this might require a bit more to only consider labels coming from visible data. For a numerical scale though, it should simply only use visible values.

Context

I am trying to display a bar chart with many categories (20-50). It should generally behave the same as a pie chart (helping the user view the breakdown of a dataset), but using bars rather than pie to allow easier relative comparison of sizes.

The downside of a bar chart is the many small slices of the "pie" take up a lot of real estate. By default, I only want to mark 5 of the 20-50 categories as visible so the user can see all the options in the legend, but the bar chart isnt too cluttered by the full list. In a pie chart, the pie would properly resize to include only the visible items, but the scales on a bar chart do not adjust.

This is related to an old feature request I filed: #11319

I've already hacked a version of CategoryScale which supports this, but I think the "y" scaling in particular feels more like a bug than feature request.

chart.js version

v4.4.6

Browser name and version

No response

Link to your project

No response

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

No branches or pull requests

1 participant