-
Notifications
You must be signed in to change notification settings - Fork 760
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
Chart increase size each redraw #84
Comments
Same Issue here |
I am not able to repro with pasting your code in jsbin (actually nothing show up). Can you create a valid repro with this jsbin template please? |
with responsive=false it works |
@boonkerz You're right, with responsive=false it won't redraw itself bigger everytime, but what if you WANT responsive? On your phone for example, if you open it in portrait view, and then rotate the phone to landscape view, the chart is not sharp anymore. Blurry. I asked a detailed question about this: http://stackoverflow.com/questions/29819173/strange-angular-chartjs-issue-not-displaying-correctly-in-ionic-app but there are not a lot of answers yet. Also, when the chart is initially in an ng-hidden element, it's height will be 0. I hope someone can solve this? |
I am having the same problem. |
Same Issue |
Can you provide a jsbin to repro the issue instead of saying "me too"? |
I'm not really able to reproduce it on jsbin, I don't know what causes the problem. But here is the setup I have: https://jsfiddle.net/1t0x6qmb/ I would start with the fact that if I set height to 50, the actual height set to canvas via style is about 120px, if I set 150, the actual size is about 360px. If I then use more data (read I have more items on x axis), the chart seems to double its height. Maybe it holds the ratio and as it grows wider (as its parent element does), it grows also in height? |
responsive= false also fixed my ever increasing chart height but I'm struggling now to get the dimensions the way I want. What is the correct way to specify the dimensions for a chart? |
Using |
I resolved my issue by setting the canvas height in an external css file rather than inline in the canvas element. Setting height inline would increase by 5px every time the chart was created. |
was what I needed. |
I have same issue, you can take a look on http://soyto.github.io/#/ranking/Alquima for example. When you resize the window you will how chart have their height increased. If needed you can access sources on https://github.com/soyto/soyto.github.io |
I was also having problems getting the chart to fill the height properly, particularly with relative heights ( Why does it not work with the defaults?
How to fix:
Hope this helps, and please do correct any mistakes in my explanation. [1] E.g. something like |
@farrago THANK YOU SO MUCH! I have been fighting this issue for months now. Your solution finally allows me to have the graphs use the full height available on different devices. Kudos kudos kudos to you. |
I'm trying to put charts in a bootstrap col-lg-{{size} where size can be toggled through a select by the user. |
Thank you @jirihelmich |
@farrago This has made me very happy. First rate debugging! Thank you. |
@farrago thanks for that detailed post. Helped me figure out my issue |
@farrago does not work on firefox |
@farrago's answer doesn't work anymore as Chart.js 2 uses canvas. |
What about ChartJs 2.0 ? |
Chart.js 1.x was also using canvas so not sure this is relevant. On Tue, Oct 25, 2016 at 7:32 PM, Yuriy notifications@github.com wrote:
|
@farrago thanks for your solution. In my case the item 4 has been not needed to fix the issue. |
A hack $('.chartjs-hidden-iframe').remove();
$('#chartjs-canvas').remove();
$('.chart').html('<canvas id="chartjs-canvas" height="300"></div>');
var myLine = new Chart($('#chartjs-canvas')[0].getContext("2d"), { |
Multiple instances of iframes seem to be the issue. With each redraw chart.js is adding an iframe instance with the class "chartjs-hidden-iframe" to the DOM. Similar to shivabhusal above, with each redraw I am clearing those out. I put the canvas inside a div, then with each redraw empty it, then appended the canvas back in. |
I solved this in a different way and would like to share my solution. So I wanted to keep it responsive, and solved it by setting the Example:
This is the least hacky solution that I was able to find. |
I ran into this same problem using vue.js to control updating a chart.js Chart instance. I found this page by doing some googling. A lot of these solutions helped me look in the right direction, thank you all. However, the real problem for me ( and I suspect many others) turned out to be that I was recreating a whole new chart.js Chart object on data updates and attaching it to the same DOM (or VDOM) element as before, and NOT updating the already made chart.js Chart object using the chart.js Chart object's update method. Once I used that, I had no doubling of height on each update and I didn't need to fiddle around with any responsive or maintainAspectRatio properties of the chart.js config. Lesson learned, use Chart.update() on an existing Chart(), even if you stored no reference to the original. Update documentation: My code: Original Chart Instantiation code
The above code would be called after each time the data was updated. Updated Chart Instantiation code
Now I store a reference to a Chart when created and I check to see if that reference exists. If it does, I update the properties of labels and datasets on the referenced chart and then call update(). |
* Recreating a new chart.js Chart object on every update and attaching it to a DOM element(or VDOM in this case) causes the chart's height to double in size. * Similar to this issue jtblin/angular-chart.js#84 for an angular.js chart.js library * Now storing a reference to each Chart created and calling native chart.js update methods on them when the data is refreshed. * http://www.chartjs.org/docs/latest/developers/updates.html
I don't know if it's some kind of help, but I had the same problem using the following options: and worked when I modified to: options: { |
mine was that i was inserting the containing div again i forgot the check to see if exists |
Just change the responsive to true it will adjust automatically responsive = true; |
Hi. I am facing the same issue as in 713 and 759 of Chart.js issues. But after a lot of testing, it appears not to be a Chart.js issue.
I give you a simple test case that reproduce the error.
you ll have to install dependencies
-----> bower install jquery angular Chart.js angular-chart.js
Can you please see whats happens when graph redraw.( on window resize or on data change i got the same problem)
The text was updated successfully, but these errors were encountered: