/**********************by garcon1986************************/
记录:这个问题花了我大半天的时间,半天的时间真是很痛苦,几乎已经frustrated,幸好最终还是解决了这个问题。幸好!!
好吧,这个是我stackoverflow上发的帖子。
全程描述:
第一步:安装pear。
第二步:利用pear命令安装image_graphviz。目前安装的是image_graphviz-1.2.1版本(stable release)。 命令有: cmd -> pear install image_graphviz 。
第三步:安装Graphviz。必须是Graphviz.msi。不能是development snapshot里的msi或者zip文件。
第四步:在安装好的C:/wamp/bin/php/php5.3.0/PEAR/Image路径下的Graphviz.php中进行如下修改。(image_graphviz-1.2.1版本,第104行开始)
/**
* Path to GraphViz/dot command
*
* @var string
*/
var $dotCommand = 'C://Graphviz2.24//bin//dot'; //安装路径
/**
* Path to GraphViz/neato command
*
* @var string
*/
var $neatoCommand = 'C://Graphviz2.24//bin//neato'; //安装路径
第五步:test.php页面调用画出图表。
<?php
require_once 'Image/GraphViz.php';
error_reporting(E_ALL ^ E_NOTICE);
$gv = new Image_GraphViz();
$gv->addEdge(array('wake up' => 'visit bathroom'));
$gv->addEdge(array('visit bathroom' => 'make coffee'));
$gv->image();
?>
在pear php官网上也有帖子的解决方案。我就是按照他的方法解决的。
http://pear.php.net/bugs/bug.php?id=3349&edit=1
发问:
Hello,
I have got a warning in image_graphviz, i have viewed a post , who has a similar error. I have installed pear image_graphviz package(Image_GraphViz-1.2.1 ), I also installed graphviz.msi(Graphviz2.25.msi ) in windows(But i don't know if does something with image_graphviz and if it does have some effects when i use image_graphviz).
Do i need to do something else?
Here is my code from pear image_graphviz site.
<?php
require_once 'Image/GraphViz.php';
error_reporting(E_ALL ^ E_NOTICE); //Added E_NOTICE
$gv = new Image_GraphViz();
$gv->addEdge(array('wake up' => 'visit bathroom'));
$gv->addEdge(array('visit bathroom' => 'make coffee'));
$gv->image();
?>
This is the warning:
Warning: fopen(C:/WINDOWS/Temp/gra50.tmp.svg) [function.fopen]: failed to open stream: No such file or directory in C:/wamp/bin/php/php5.3.0/PEAR/Image/GraphViz.php on line 210 Notice: Undefined variable: data in C:/wamp/bin/php/php5.3.0/PEAR/Image/GraphViz.php on line
Thanks Pekka Gaiser, I used error_reporting(E_ALL ^ E_NOTICE);
. I don't know how to change the temp directory, but c:/windows/temp exists in my computer.
I haven't solve the problem. Thanks all for advice.
回答:
[Edited] Are you sure your Graphviz pear package can actually call the binary you installed? Does the package have any settings, maybe (probably) you have to specify the path there?
If the binary is definitely there: Does the c:/windows/temp directory exist? Can you change the temporary directory somewhere in Graphviz? Are you really on Windows? Can you change the location of the temporary setting in php.ini?
To address the notice, try setting error_reporting to error_reporting(E_ALL ^ E_NOTICE)
Notices about undefined variables give important guidance at development time, but if they occur in a production package the only way to get rid of them is to turn them off.
Reply:
Thanks Pekka Gaiser, i have checked the file Image/Graphviz.php and it doesn't indicate any directory about temp. The c:/windows/temp does exists and i don't know how to change it. I think it's default by windows system, not by graphviz. I don't find the settings in php.ini too. But i use E_NOTICE because of your advice. The Notice line is disappeared. But i still have the warning. Thanks.
Reply:
Then you need to check whether the Graphviz PEAR package knows about the Graphviz Program you installed. There is most likely a settings file somewhere where you can set the path. However I don't know this for sure as I know neither PEAR nor Graphviz. – Pekka Gaiser
Reply:
I have solved it. Because the path is not right. Thanks pek.
graph relations {
{rank=min; Emil}
Emil -- Elias;
Emil -- Linda;
Elias -- Annelie;
Elias -- Mamma;
Annelie -- Mamma;
Linda -- Mamma;
Linda -- Annelie;
Mamma -- Stefan;
Stefan -- Elias;
Emil -- Patrik;
Patrik -- Elias;
Emil -- Karin;
Emil -- Per;
Per -- Lars;
Emil -- Greta;
Per -- Greta;
Greta -- Lars;
} 我的另外一个帖子:
http://stackoverflow.com/questions/1998671/how-to-draw-social-networking-graph
I run this command: dot -Tpng emil.dot -o emil.png
I get this file:
If I instead run this command, which is also part of Graphviz: circo -Tpng emil.dot -o emil2.png
, I get this file: