0

I have an Android application which uses WebView to load the GUI using HTML. There is a <canvas> element into which i draw charts using Chart.js Javascript library for plotting charts. It was tested on 3 devices. On two of them it works fine (Android 2.2 and 2.6), but on a later vesion of android (4.1.2) the canvas makes it double: all the charts are visible twice in the canvas, one of them is shifted a bit up and to the left.

canvas with double chart

What is the problem with the canvas? Why does it double the things rendered? How can i made it render only once?

Here's the code:

HTML:

<canvas id="graph_canvas"></canvas>

JavaScript:

var canvas=document.getElementById("graph_canvas");
canvas.height=200;
canvas.width=200;
var graphSelection=document.getElementById("graphSelection");
var ctx = canvas.getContext("2d");
var data_=JSON.parse(JI.getGraphData(graphSelection.value));    
var myNewChart = new Chart(ctx).Line(data_);

Where graphSelection is a <select> element with which we select the chart, JI.getGraphData returns JSON data for Chart.js.

3
  • Try to make the graph position fixed, via style tag, into the canvas html code Commented Oct 3, 2013 at 19:59
  • that worked. it messed some other things, but the graph works. thanks! Commented Oct 3, 2013 at 20:08
  • now a new problem appeared, i posted it under stackoverflow.com/questions/19847582/chart-js-canvas-resize Commented Nov 9, 2013 at 8:05

3 Answers 3

1

If you do not want problems caused by "position: fixed;" on element, canvas parent element should not have css property "overflow" with value "hidden".

So define something like "overflow: visible;" on parent element.

Sign up to request clarification or add additional context in comments.

1 Comment

Actually I solved a similar problem by setting overflow: hidden; to the canvas's parent element.
0

Try this:

// If Samsung android browser is detected
if (window.navigator && window.navigator.userAgent.indexOf('534.30') > 0) {

    // Tweak the canvas opacity, causing it to redraw
    $('canvas').css('opacity', '0.99');

    // Set the canvas opacity back to normal after 5ms
    setTimeout(function() {
        $('canvas').css('opacity', '1');
    }, 5);

}

Comments

0

I met this problem too. I solved it by using position:relative , left and -webkit-transform instead margin;. The problem was solved accidentally.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.