question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Chart invisible when Legend too large

See original GitHub issue

Expected Behavior

Imagine a Pie/Doughnut Chart with the following requirements:

  1. It has a Dataset of 100 Products
  2. Each Product is represented by a Legend Label (thus, 100 labels)
  3. The Chart resides within a medium div (say “col-lg-4” of Bootstrap)

It can be obvious that both the 6 generated columns with the Labels cannot fit to the div with the Chart. In my opinion, they should not.

Image presenting the Chart in a full-screen mode: largechart

Current Behavior

When working with a Chart following the aforementioned requirements:

  1. The div of the chart (canvas) shows some of the Legend Labels (say the 60 last ones)
  2. The other Labels are hidden, rendered outside the canvas
  3. The Chart is nowhere to be seen, probably thrown out by the Labels

Image presenting the Chart in a smaller Div. Most elements are gone. All that is left are some of the Legend Labels: smallchart

Possible Solution

Add a scrollable overflow to the “box” that hosts the Legends?

Steps to Reproduce

  1. Create a medium div (any size will do, as long as it’s not a full-screen one) <div class="row"> <div class="col-lg-4"> <div> <div>
  2. In the “col-lg-4” div, place a canvas for your Chart. Make it :
  • Type = Pie/Doughnut
  • Responsive = true
  • Fullwidth = true (although “false” has the exact same behavior)
  • Dataset = any array holding 100+ elements (e.g. array of {name, value})
  • Labels = the “name” values of your array (so that you will have 100 labels) Options Example: options="{ 'responsive': true,'maintainAspectRatio':true,'transparencyEffects':true,'dataSetBorderWidth': 2, 'legend':{ 'display': true, 'fullWidth':true, 'position': 'right', 'labels':{'boxWidth':40, 'fontSize':12, 'fontStyle':'normal', 'fontColor':'#666', 'usePointStyle':false}}, 'pallette': ['#a694ff','#a59891','#98a7ad','#ea7d7d','#80d27a','#99b4f4','#fed444','#3f3f3f','#b6696c','#417d83','#ff9750']}"

When you run it, you will see that your div will only present some of the Legend Labels. All other Labels and the Chart will be cone.

Environment

  • Chart.js version:2.2.1
  • Browser name and version: Chrome & Mozilla

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:26
  • Comments:22 (5 by maintainers)

github_iconTop GitHub Comments

14reactions
daniel-shuycommented, Jul 8, 2017

I have an idea. What if Chart.js’ constructor took in 2 canvases, 1 for the Chart itself, and the other for the Legend?

That way, one could control the sizing and positioning of each canvas separately.

For example, to solve the above problem, one could simply increase the height of the Legend canvas and wrap it with a scrollable <div> (with overflow: scroll;), without affecting the Chart canvas.

This would also solve issue #1959 (size of Chart will not change if the height/width of the Legend changes).

9reactions
adriglibcommented, Dec 18, 2019

How is this issue still opened? Is there no way to add a ‘min-height’ to the graph so it doesn’t shrink? That way the container will grow.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Chart.js legend took up too much spaces - Stack Overflow
I was having some problem with chart. js legend. The legend with long text took up too much spaces which resulting in the...
Read more >
Pie Chart - Legend Value Problem in UI for ASP.NET AJAX
I believe the "-" label is related to this too. It might be a glitch caused by positioning and hiding these labels. I...
Read more >
Show or hide a chart legend or data table - Microsoft Support
Select a chart and then select the plus sign to the top right. Point to Legend and select the arrow next to it....
Read more >
Solved: Re: Legend not always showing on stacked bar chart...
When the legend is not visible, right click on that area of the sheet and select Properties... This will allow you to inspect...
Read more >
Putting a Chart Legend On Its Own Page - Microsoft Excel Tips
Another option involves "hiding" the chart so the only visible item in Chart 2 is the legend. Click on Chart 2 so it...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found