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

mobile browser odd behaviour #713

Closed
nits opened this issue Oct 22, 2014 · 7 comments · Fixed by #855
Closed

mobile browser odd behaviour #713

nits opened this issue Oct 22, 2014 · 7 comments · Fixed by #855
Milestone

Comments

@nits
Copy link

nits commented Oct 22, 2014

jsfiddle: http://jsfiddle.net/1sc6L8dk/5/

Open this jsfiddle in mobile browser (I am using safari,chrome).

    var ChartData = '', ChartOptions = '';

function updategraph() {
    ChartData = [{
        value: 400,
        color: "#000",
        title: "#1"
    }, {
        value: 375,
        color: "#555",
        title: "#2"
    }, {
        value: 323,
        color: "#222",
        title: "#3"
    }, {
        value: 375,
        color: "#000",
        title: "#4"
    }, {
        value: 323,
        color: "#000",
        title: "#5"
    }];
    ChartOptions = {

    };

    new Chart(document.getElementById("myChart").getContext("2d")).PolarArea(ChartData, ChartOptions);
}
window.onload = function () {
    polarChart = new Chart(document.getElementById("myChart").getContext("2d")).PolarArea(ChartData, ChartOptions);
};

$("span").click(function () {
    updategraph();
});

If you click on "click here to draw" you will see the graph generated which is perfectly fine on Mozilla, Chrome, Safari (all latest desktop browsers).

Now when I try doing the same in mobile browser(iPhone 5 Safari, Samsung S4 Chrome) this behaves really strange. If you click on graph for second time, this graph will appear double of its first size and then again the same. It just gets expanded where it should behave like how it behaves in desktop browser.

First I thought this might be the issue only with PolarArea, but same issue appears with Pie too. You can check the same just changing PolarArea to Pie.

Any ideas on this ? May be some small mistake in my code?

Thanks in advance.

http://stackoverflow.com/questions/26495262/generating-chartjs-graph-dynamically-odd-behavior-in-mobile-browsers

Posted this question here earlier.

@leighquince
Copy link
Contributor

when i looked at this the problem seems to arrive from the helper function retinaScale() which continues to scale the graph every time it is initialized on an already used canvas

@nits
Copy link
Author

nits commented Oct 23, 2014

yeah. But this is something which is to be fixed soon

@quilkin
Copy link

quilkin commented Dec 19, 2014

Still needs fixing! Same problem on using with Cordova app on android 4.4.4. Chart draws OK first time then canvas grows every time afterwards, eventually causing a crash.

@nits
Copy link
Author

nits commented Dec 19, 2014

http://jsfiddle.net/leighking2/1sc6L8dk/9/

See this solution as quince pointed out.

@quilkin
Copy link

quilkin commented Dec 19, 2014

Thanks, nits. I can confirm that removing 'helpers.retinaScale(this)' from the constructor solves it for a Cordova app on Android 4.4.4

@nnnick
Copy link
Member

nnnick commented Jan 1, 2015

So an easy solution for you would be to not reuse the canvas html element, and recreate it when you recreate the chart itself.

You should also use the .destroy() method for destroying a previously created chart to clean up references to that chart object internally.

That said, I think the library should cleanup the original canvas back to it's original size, and remove any applied styles within .destroy()

@quilkin
Copy link

quilkin commented Jan 5, 2015

Thanks Nick. I'll try that later although the modification to chartjs
seems to work OK.
In the meantime I've got a new issue; using the 'repsonsive' option
works fine on the desktop, but with it set the chart doesn't show at all
on the Android device!

regards
Chris
On 01/01/2015 15:22, Nick Downie wrote:

So an easy solution for you would be to not reuse the canvas html
element, and recreate it when you recreate the chart itself.

You should also use the |.destroy()| method for destroying a
previously created chart to clean up references to that chart object
internally.

That said, I think the library should cleanup the original canvas back
to it's original size, and remove any applied styles within |.destroy()|


Reply to this email directly or view it on GitHub
#713 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants