0

Why would you do such thing??: because in some particular cases I need to hide the source values of a graph generated by dygraph. Since in the case of "not hidden values" I am using dygraphs js libray, using this particular feature would save me a lot of time.

This way I would have the same look and feel, and I would not have to modify the data generation process.

I would like to know if this road is feasible or utter madness:

Steps: (using Yii-PHP over an Apache server)

  1. Generate javascript page on the server side.
  2. Get image as png (somehow), still on the server side.
  3. Send the image to the client as the only thing he can receive.
Xavier Peña
  • 7,399
  • 9
  • 57
  • 99
  • 1
    If in your use case the dygraph library is meant to be used on the client-side, why not use a charting library for PHP that is meant to be used on the server-side? – Boaz Sep 02 '14 at 07:43
  • _why not use a charting library for PHP that is meant to be used on the server-side?_ : because unfortunately (and due to legal restrictions) I need to mix in the same webpage both styles. 1. full dygraphs js features, 2. image graphs in order to stop people form parsing the data. As I said, using the same dygraphs look and feel would have two advantages: the most important is having the same look and feel for both types of graph, and the secondary one is not having to change the a single comma in our data generation functions (a PHP library would certainly use a different data format). – Xavier Peña Sep 02 '14 at 07:58
  • In that case, see @Amadan's suggestion below to use a headless browser, such as PhantomJS. – Boaz Sep 02 '14 at 08:02

2 Answers2

2

There's a ton of graphing libraries for PHP, why not use one of those? (e.g. JpGraph, pChart...) Pretty much every one of them can produce an image in PNG.

Feasible steps:

  1. Invoke a PHP graphing library on server side
  2. Render it as PNG and send to the client

If you insist on using a JavaScript library, then I guess PhantomJS is your only option, but it is not exactly optimal.

tl;dr: My vote goes to "utter madness".

Amadan
  • 191,408
  • 23
  • 240
  • 301
  • Thank you very much. I know it looks like utter madness, but it would certainly reduce our problems (as I have further explained after @Boaz 's question in the main post). Your hint has lead me to [PHP PhantomJS](https://github.com/jonnnnyw/php-phantomjs), which looks promising, and [this Stackoverflow post](http://stackoverflow.com/questions/20202407/how-to-execute-phantomjs-from-php) explaining how to Execute PhantomJS from PHP. I think it is worth to give it a try before we switch to the "feasible solution" (the PHP generated chart), which would have the "look and feel" disadvantage. – Xavier Peña Sep 02 '14 at 08:07
0

Some dygraphs users have built a tool for exporting PNGs: demo and discussion.

danvk
  • 15,863
  • 5
  • 72
  • 116