Chart.js icon indicating copy to clipboard operation
Chart.js copied to clipboard

Toggle Individual Bar Visibility via the Legend

Open HattoriHenzo opened this issue 7 years ago • 11 comments

Documentation Is:

  • [ ] Missing or needed
  • [x] Confusing
  • [ ] Not Sure?

Please Explain in Detail...

While trying the default sample code, the legend appear just for the first item and all the other legend value don't appear. This is a known issue and there are sample code that helps correct it (not the good way). But the main issue is that the labels values are not displayed anymore (just a single value) and the legend appears instead.

Your Proposal for Changes

I guess it is a bug in Chart.js (or may be I am wrong), the Legend should appear with all the labels defined. In the back log I did not found any issue registred about it. Or can you please provide a sample code where the labels and all the associated legends appear together.

Example

image

The image above, shows the sample chart with the legend showing only the first bar (red) and all the labels displayed on the X axis. When you want to display the legend of all the bars while using the proposed sample code we have one label on the X axis :

image

HattoriHenzo avatar Jul 30 '19 12:07 HattoriHenzo

@HattoriHenzo thanks for the detailed report. The issue at hand is that the legend only shows an item for each dataset, rather than for each item in a dataset. You may be able to achieve a legend like the polar area chart by changing out the default legend callbacks. In the polar area charts, this is done at https://github.com/chartjs/Chart.js/blob/master/src/controllers/controller.polarArea.js#L55-L92

The biggest risk I see is that I cannot recall if hiding individual bars is supported or not. @benmccann @kurkle @simonbrunel @nagix any ideas?

etimberg avatar Jul 30 '19 22:07 etimberg

@etimberg Hello! I think this should be done by default without any additional code. Also, do you think this issue should be add to bug or enhancement ?

HattoriHenzo avatar Jul 31 '19 08:07 HattoriHenzo

I'd consider this an enhancement. The challenge is differentiating this case from the case where there the user wants to toggle an entire dataset away

etimberg avatar Jul 31 '19 11:07 etimberg

@etimberg I am trying to edit the label to set the issue to enhancement, but it doesn't work.

HattoriHenzo avatar Jul 31 '19 11:07 HattoriHenzo

@HattoriHenzo
Hey,I would like to work on this. I just need to rectify the legend ,right?

jatiny17 avatar Sep 07 '19 10:09 jatiny17

@jatiny17 Hello, the enhancement is to make the values visible by default on the X Axis for every single data, and the legend visible at the same time. The images give you more details. Are you available on Gitter?

HattoriHenzo avatar Sep 07 '19 10:09 HattoriHenzo

@jatiny17 Hello, the enhancement is to make the values visible by default on the X Axis for every single data, and the legend visible at the same time. The images give you more details. Are you available on Gitter?

@HattoriHenzo yes , i am on gitter

jatiny17 avatar Sep 07 '19 11:09 jatiny17

@jatiny17 I hope my explanations are clear enough. If you want more details, we can discuss after on Gitter.

HattoriHenzo avatar Sep 07 '19 11:09 HattoriHenzo

Hiding individual bars is now supported as of v3.0.0-beta.4. See https://jsfiddle.net/an6g71ud/

I'm not sure if this is good enough to close this ticket, but it's getting there. The other way to achieve it is to create different datasets for each colour and have only one X axis label. Example: https://jsfiddle.net/20uzf7cs/

etimberg avatar Oct 25 '20 02:10 etimberg

Closing per my previous comment since there is a good way to do this

etimberg avatar Dec 24 '20 21:12 etimberg

Hiding individual bars is now supported as of v3.0.0-beta.4. See https://jsfiddle.net/an6g71ud/

Is there a way to make the remaining bars fill the empty space of the hidden bar? This happens in your second example, but not the first. I would prefer to use data visibility as they are all one dataset, but with ~50 items (only 5 of which will show at a time), this wouldn't work well

alex-statsig avatar May 31 '23 22:05 alex-statsig