du0173 2011-10-20 01:56
浏览 51
已采纳

使用php中的md数组创建graphviz图

Hy, I'm looking for a way to create a GraphViz graph from php arrays. I have an associative multidimensional array from which I need to extract the keys and their corresponding values, and use them to create a graph. Example by 1D array:

$arr = ("dogs" => "4", "cats" => "3"); 

I need to extract the key "dogs" and use it as the label of a nod, and extract the corresponding value "4" and somehow use that to define the size of that nod. I need to do the same thing with multidimensional arrays. Just a silly example:

$md_arr = ("dogs" => array("rot" => "7", "blood_hound" => "4"), 
           "cats" => array("long_hair" => "12", "some_other_kind" => "1")
          );

I need the output to be defined something like this:

name/label of the first node: first key from the first array => "dogs" name/label of the second node: first key from the second array => "rot" , size of that node is a value of the corresponding key - in this case "7".

I also need to know how to pass the variable from my array_script.php (script that creates my MD array) to a new script that will create the graph. I tried putting the example code for creating graph into my php script, and the output was a warning message stating:

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\test\hare.php:1) in C:\xampp\php\PEAR\Image\GraphViz.php on line 174

Can anyone please help me with this?

  • 写回答

1条回答 默认 最新

  • duanan1228 2018-02-01 08:27
    关注

    I figured it out on my own :) link the trick is to use addNode function. In my case, I needed to create dynamic graph using data from dynamicaly populated MD array. So you just need to name the node with a variable containing data you need. I needed the label to be set by the value from a variable as well, so here's the code: $graph->addNode($var1, array('label' => $var1)); $graph->addNode($var2, array('label' => $var2)); $graph->addEdge(array($var1 => $var2)) works if var names are same, but values are differnet

    6 years late to the party, but hey! I do apologize to the community. I have no idea what was happening 6 years ago.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
  • ¥15 NX MCD仿真与博途通讯不了啥情况
  • ¥15 win11家庭中文版安装docker遇到Hyper-V启用失败解决办法整理
  • ¥15 gradio的web端页面格式不对的问题
  • ¥15 求大家看看Nonce如何配置
  • ¥15 Matlab怎么求解含参的二重积分?
  • ¥15 苹果手机突然连不上wifi了?
  • ¥15 cgictest.cgi文件无法访问