Converting Google Chart into Image

后端 未结 2 1832
一向
一向 2021-01-15 12:39

I\'m trying convert a Google Chart into a image like this link but I don\'t understand about the line

var chartArea = chartContainer.getElementsByTagName(\'if

2条回答
  •  暖寄归人
    2021-01-15 12:46

    This can be done by following the steps on this page. Note that the code in the article is based on an old version of Google Visualization which used iframes, and will not work as posted. However, you can do the same using the following code (found in the comments):

    var svg = $(chartContainer).find('svg').parent().html();
    var doc = chartContainer.ownerDocument;
    var canvas = doc.createElement('canvas');
    canvas.setAttribute('style', 'position: absolute; ' + '');
    doc.body.appendChild(canvas);
    canvg(canvas, svg);
    var imgData = canvas.toDataURL("image/png");
    canvas.parentNode.removeChild(canvas);
    return imgData; 
    

    Note: I did not create this code, it was originally created by the author of the above site (Riccardo Govoni) and updated in the comments section by user Thomas.

提交回复
热议问题