6

I'm looking for a way to draw directed graphs in PHP. (as in http://upload.wikimedia.org/wikipedia/commons/0/08/Directed_acyclic_graph.png). I want it to create an image of the graph just like GD can output an image.

I've googled a lot on this, but I only can find a lot of libraries for drawing graphs in general (with bars etc), not directed graphs.

P.S. I've tried using dot (the linux program) via system(), but unfortunately I have no permission to do that on the server. Also, I have no rights to install PHP extensions and stuff like that on the server, so it should work with normal PHP (ideally just by including a file).

Thanks in advance.

Michael Dorfman
  • 4,060
  • 1
  • 22
  • 29
openbas2
  • 263
  • 1
  • 7
  • 16
  • Why can't you do this using gd? It would be relatively trivial, you just need to keep track of where each node is. Do you want to just give the list of nodes and what they connect to, and it automatically generates the directed graph? – James Black May 11 '09 at 20:56
  • I've tried this, but it is quite complex to make that work without (to much) bugs, it results in really ugly formatted graphs. The biggest problem is the structure of the network, avoid to much crossing lines etc. – openbas2 May 11 '09 at 21:23

5 Answers5

3

I found a PEAR interface to GraphViz; I have not used it before so can't give you any personal recommendation whether it's good or bad. (but perhaps that doesn't solve your problem since you say you can't install applications)

Jason S
  • 184,598
  • 164
  • 608
  • 970
  • It would indeed be a good solution, but PEAR is unfortunately not installed on my account, and I have no rights to do that myself. – openbas2 May 11 '09 at 21:35
  • 5
    You can also manually download the package and it's dependencies. You don't need the PEAR installer in order to use PEAR packages. – Sander Marechal May 11 '09 at 22:28
2

I'm not aware of any graph visualization implementation in php.

However I suggest you to consider drawing the graph with javascript, for instance with the canviz JS library which works on most browsers (yes, including IE 6 & 7, but not 8 currently).

Elazar Leibovich
  • 32,750
  • 33
  • 122
  • 169
0

Haven't tried it yet, but this looks very promising.

http://www.kylescholz.com/blog/2006/06/using_force_directed_graphs.html

0

I use php to generate json that is consumed by the d3 force-directed graph system. So the display is all handled client side, all I need to do is make the right json data structures...

-FT

ftrotter
  • 3,066
  • 2
  • 38
  • 52
0

After a quick Google search, I found graph.php, which in the comments states that it connects nodes through arcs, vice straight lines in the example provided, but may be a good step in the right direction.

qat
  • 32
  • 1
  • Maybe I'm missing something, but as far I can see, this is only the data structure (which I already have). It doesn't seem to draw the graph? – openbas2 May 11 '09 at 21:27
  • Aye, I noticed this as I was getting ready to put it to use. I thought the code on that page was clipped. Sorry 'bout that. – qat May 11 '09 at 21:29