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] Pie chart is cut in half when responsive and inside a collapsed element 2.6.0

See original GitHub issue

Expected Behavior

Currently while using a pie chart with responsive: true in a bootstrap modal and using Reactjs.net (or any collapsible element in html5 by my reckoning) I experienced a bug where the pie chart in a grid would become broken when re-rendered in a hidden modal.

Before I go any further yes I know reactjs has a charts wrapper called react-chartjs but using react components in Reactjs.net is hard and as far as I can tell charts.js works fine beyond this bug I found.

Here is the modal before I search my list of modals: working

The canvas is in a <div class="col-sm-4"> wrapper element. The same goes for the bootstrap panels next to it.

I would expect this behavior to remain constant but when I used a reactjs search feature to filter out my list of modals and then reopen a modal the below behavior is encountered.

Current Behavior

After filtering out the modals based on their name, the pie chart appears like so: broken broken2

The pie chart will flicker between the half-pie and the small pie depending on which one has had a mouseover event most recently.

Possible Solution

For now, the solution I found was to manually resize the canvas each time the modal is updated in Reactjs using componentWillUpdate(). Simply getting the canvas node and setting canvas.height=height and canvas.width=width works fine. I did this because the issue seems to be related to the responsive resizing returning a value of -30 for the dimensions of the canvas due to the canvas being in a collapsed modal element and then getting confused when it tries to resize from there. So simply changing this value manually before calling new Chart( ... ) works to fix this bug. However this does result in blurry canvas in some situations.

Steps to Reproduce (for bugs)

Bug would be hard to reproduce in a fiddle or something because it involves Reactjs. If someone can point me in the right direction for reproducing this bug in straight-forward way I would be glad to do that.

Environment

  • Chart.js version: 2.6.0
  • Browser name and version: Chrome Version 58.0.3029.110 (64-bit)
  • Reactjs v15.3.2
  • Bootstrap v3.3.7

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Peter-Van-Drunencommented, Jun 22, 2017

PR submitted. #4406

0reactions
gabrielchtcommented, Jun 23, 2017

I had a similar problem (issue 4410). Strangely i solved with this:

if ((window.outerHeight > window.outerWidth) && window.devicePixelRatio > 1) { alturaCanvas = parseInt(4 * anchoCanvas); $('#contenedorGraficosTemp #grDescuentos').height(alturaCanvas); $('#contenedorGraficosTemp #grDescuentos').width(anchoCanvas); } else { $('#contenedorGraficosTemp #grDescuentos').height(alturaCanvas); }

I don’t know why the canvas was smaller than his precedent hidden iframe

Read more comments on GitHub >

github_iconTop Results From Across the Web

Explode or expand a pie chart - Microsoft Support
Right-click the pie chart, then click Format Data Series. · Drag the Pie Explosion slider to increase the separation, or enter a number...
Read more >
Chart.js legend took up too much spaces - Stack Overflow
js legend. The legend with long text took up too much spaces which resulting in the reduce in the size of my pie...
Read more >
Visualization: Pie Chart - Google Developers
Draws the chart inside an inline frame. (Note that on IE8, this option is ignored; all IE8 charts are drawn in i-frames.) Type:...
Read more >
Older Announcements | GnuCash
Set the initial Split horizontal paned position to be half way when the window is realized. ... Bug 779411 - jqplot fixes for...
Read more >
Doughnut and Pie Charts - Chart.js
This equates to what portion of the inner should be cut out. This defaults to 0 for pie charts, and '50%' for doughnuts....
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