FLOT data as image to write to PDF

前端 未结 4 1052
星月不相逢
星月不相逢 2020-12-10 18:24

I am using jQuery/FLOT to draw a graph, I would like for the user to be able to download a PDF version of the graph. I am writing the PDF using ColdFusion. After creating th

4条回答
  •  隐瞒了意图╮
    2020-12-10 18:48

    You could also take a snapshot of your canvas using toDataURL() and substitute in an img element, which the PDF converter should be able to handle:

    var canvas = $("canvas.base")[0];
    var tmpimg    = canvas.toDataURL("image/png");
    //console.log(tmpimg);
    $("body").append('');
    

    Note that the image produced is just the canvas contents (ie, the graph itself) and does not include the axes or legend. You might have to do some tricky substitution/alignment of the image in the flot placeholder, but it gets you a usable image to start from.

    This is just a slight re-working of the accepted answer to this question and I thought somebody here might find it useful.

提交回复
热议问题