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

Responsive Chart overflowing when padded added #486

Closed
corysimmons opened this issue Jul 27, 2014 · 6 comments
Closed

Responsive Chart overflowing when padded added #486

corysimmons opened this issue Jul 27, 2014 · 6 comments

Comments

@corysimmons
Copy link

Doesn't matter what box-sizing I use on the containing element. Any ideas?

@corysimmons
Copy link
Author

Side question: is there any way to get rid of the lines in the bg or make them meet ends flushly instead of like this +

@omgaunicorn
Copy link

For your side question: use the option "scaleShowGridLines: false" to get rid of the bg lines, if you don't want either lines or labels, use "showScale: false".

I was the same issue with the overflowing chart, but check out #56 , nnnick's answer worked for me on Chrome, FF and Safari, if I get it to work on IE9, I'll post later.

@corysimmons
Copy link
Author

 width: 100% !important
    max-width: 800px
    height: auto !important

did the trick thanks!

@nnnick
Copy link
Member

nnnick commented Jul 27, 2014

Yeah don't do that - I suspect it'll break tooltips the Chart is scaled via CSS.

Chart.js doesn't attempt to calculate sizing on a container elements with padding, so when box-sizing: border-box is set, clientWidth is inclusive of the padding.

A way simpler fix for this is to wrap your canvas in a div without any padding.

@corysimmons
Copy link
Author

@nnnick Works, thanks

@lackneets
Copy link

lackneets commented Dec 2, 2016

I have same problem on IE edge, but Chrome is ok

Finally figured out it caused by Chart.helpers.getStyle not return exact pixels

image

I am going to overwrite the helper methods for fixing my project

Chart.helpers.getMaximumWidth = function(domNode) {
  var container = domNode.parentNode;
  var paddingLeft = parseInt(document.defaultView.getComputedStyle(container, null).paddingLeft, 10);
  var paddingRight = parseInt(document.defaultView.getComputedStyle(container, null).paddingRight, 10);
  var w = container.clientWidth - paddingLeft - paddingRight;
  var cw = Chart.helpers.getConstraintWidth(domNode);
  return isNaN(cw)? w : Math.min(w, cw);
};
Chart.helpers.getMaximumHeight = function(domNode) {
  var container = domNode.parentNode;
  var paddingTop = parseInt(document.defaultView.getComputedStyle(container, null).paddingTop, 10);
  var paddingBottom = parseInt(document.defaultView.getComputedStyle(container, null).paddingDown, 10);
  var h = container.clientHeight - paddingTop - paddingBottom;
  var ch = Chart.helpers.getConstraintHeight(domNode);
  return isNaN(ch)? h : Math.min(h, ch);
};

FYI.

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

No branches or pull requests

4 participants