Google Charts as Image

前端 未结 5 2059
南旧
南旧 2021-02-13 19:36

I am trying to use Google charts to embed images of charts in the emails. So Each user will have a unique graph.

Can we use the API and embed a unique URL that will ren

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-13 20:19

    It is possible to generate a url that will render an image of a chart using the Google Chart Wizard. However, that service recently (April I believe) because deprecated. It still works fine, but for a long term solution, you may have to come up with another method.

    Edit

    Another method would be to generate the image and save it to your server before sending the email. You can do this by having a page on your server dedicated to generating the chart by parsing a given slug, and when the chart is loaded send a POST request with the image data. You can access the data URI by using a hidden canvas (HTML5 is required) and the canvg javascript plugin:

    chart_area = document.getElementById("chart_div").getElementsByTagName('iframe')[0].contentDocument.getElementById("chartArea");
    svg = chart_area.innerHTML;
    canvas = document.getElementById("hidden_canvas");
    canvas.setAttribute('width', chart_area.offsetWidth);
    canvas.setAttribute('height', chart_area.offsetHeight);
    
    canvg(canvas, svg);
    image_data_uri = canvas.toDataURL("image/png");
    

提交回复
热议问题