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 the graph I then send the html of the graph div, via ajax to a CF script that uses cfdocument to write the pdf. The problem is that in the PDF, it only displays the axis and labels, not the actual graph data. Does anybody know of a way to get the actual image that is dynamically created on the canvas?
相关问题
- flot chart ticks lines not uniform
- jQuery/Flot: How do you get the coordinates of a d
- Jquery Flot “plothover” event not working
- Plot a new series on an already-rendered jquery fl
- Getting color of a data series from a flot chart
相关文章
- Jquery Flot “plothover” event not working
- Plot a new series on an already-rendered jquery fl
- Getting color of a data series from a flot chart
- Flot graph does not render when parent container i
- Create dynamic JSON from foreach
- Display tooltip with correct Time zone using Flot
- Saving flot chart to image or pdf
- With flot, how can I create a linked pie chart tha
You could render the chart on the server with a headless browser like phantomJS (WebKit engine).
You only need a script that takes an URL and renders the output as a Base64 encoded string to the console stream or writes an image.
As far as I know it's the only semi browser-independent way to do this.
Here's a script for phantomjs that outputs a given web page as base64 encoded image-string:
I don't think this has been implemented in flot yet see http://code.google.com/p/flot/issues/detail?id=175
You could also take a snapshot of your
canvas
usingtoDataURL()
and substitute in animg
element, which the PDF converter should be able to handle: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.
Check out CutyCapt (http://cutycapt.sourceforge.net/), it seems to work with Flot.