5

I'm trying to convert the entire jqplot bar chart, including it's legend and chart title, to image. However, using toDataURL and steps in this post (Convert canvas to image and open in new window using ruby on rails and javascript), I'm only able to convert the chart with it's axis and axis label to image.

As the legend and chart title is not rendered on the canvas, they are not being converted.

Can someone tell me how to convert the chart title and legend with the canvas please?

Community
  • 1
  • 1
Mich
  • 257
  • 1
  • 3
  • 9

2 Answers2

3

Since the title and axes are div and not img or canvas I think the only solution would be to write every text in a canvas with the fillText() function. Then convert this to picture.

You can write in canvas like that : fillText("Hello World!", x, y);

Now you can also add this to jQplot as a plugin :)

Good luck

Tim
  • 1,938
  • 1
  • 13
  • 20
  • Thank you for the great suggestion Tim. But the legend of the chart is a HTML table, so I was wondering if it is possible to use fillText() to write the table in canvas. If it's possible, how do I achieve that? – Mich Jun 09 '11 at 01:58
2

I have been working on a bare implementation. It is linked here https://bitbucket.org/cleonello/jqplot/issue/14/export-capabilities#comment-554274 It should support every example that is distributed with jqplot.

Kevin Risden
  • 306
  • 2
  • 7
  • I have a requirements where I have to display 120 chart on the screen. And IE9 hang. so I want to use your code to convert the jqplot chart to image, and then destroy the jqplot object to avoid memory leak issue. So I want to ask a question, your method return a string, how do I display that string as a image on the browser? Thank you – Thang Pham Jan 09 '13 at 17:04
  • @ThangPham You should be able to set an img tag src to the string that is returned and it will display. – Kevin Risden Jul 05 '13 at 19:07