SVG and Canvas

Using Images

  1. Create a new Image or use one from document.images.
  2. Use drawImage to draw it on the canvas.
function drawchart() {
    var ctx = document.getElementById('canvas').getContext('2d');
    var img = new Image();
    img.src = 'backdrop.png';
    img.onload = function(){
        ctx.drawImage(img,0,0);
        ctx.beginPath();
        ctx.moveTo(30,96);
        ctx.lineTo(70,66);
        ctx.lineTo(103,76);
        ctx.lineTo(170,15);
        ctx.stroke();
    }
}
drawchart()


José M. Vidal .

5 of 24