Page 1 of 1

Resize chart for mobile view

Posted: Mon May 02, 2016 11:25 am
by 15677821
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?

Re: Resize chart for mobile view

Posted: Tue May 03, 2016 8:47 am
by yeray
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?