Resize chart for mobile view

TeeChart for JavaScript for the HTML5 Canvas
Post Reply
SenSeo
Newbie
Newbie
Posts: 71
Joined: Wed Mar 09, 2016 12:00 am

Resize chart for mobile view

Post by SenSeo » Mon May 02, 2016 11:25 am

The legend is not resized along with the canvas when we access the chart for mobile devices. Below function is used to resize the chart and legend.

Code: Select all

function resize(chart) {
        if (!chart) return;

        var canvas = chart.canvas;

        startWidth = 500;
        startHeight = 600;

        var w = startWidth;
        var h = startHeight;

        if ((window.innerWidth - 156 - canvas.offsetLeft - 20) < startWidth)
            w = window.innerWidth - 156 - canvas.offsetLeft - 20;
        else
            w = startWidth;

        if ((window.innerHeight - 70 - canvas.offsetTop - 20) < startHeight)
            h = window.innerHeight - 70 - canvas.offsetTop - 20;
        else
            h = startHeight;

        canvas.setAttribute('width', "" + w + "px");

        canvas.setAttribute('height', "" + h + "px");

        canvas.style.width = "" + w + "px";
        canvas.style.height = "" + h + "px";

        chart.bounds.width = w;
        chart.bounds.height = h;

        var divWidth = document.getElementById("foo").offsetWidth;

        if (divWidth != 0) {
            canvas.setAttribute('width', "" + divWidth - 10 + "px");

            canvas.setAttribute('height', "" + h + "px");

            canvas.style.width = "" + divWidth - 10 + "px";
            canvas.style.height = "" + h + "px";

            chart.bounds.width = divWidth - 10;
            chart.bounds.height = h;
       }


        chart.draw();
    }
Is there any way to fix the legend issue for a mobile device?
Attachments
Lengend_resize issue.PNG
Resize issue
Lengend_resize issue.PNG (29.16 KiB) Viewed 7692 times

Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Resize chart for mobile view

Post by Yeray » Tue May 03, 2016 8:47 am

Hello,

There's a demo that does a resize and it looks fine for me in a smartphone:
https://www.steema.com/files/public/tee ... resize.htm

Does it reproduce the problem you are reporting?
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply