dpq59734 2009-11-01 17:25
浏览 69
已采纳

如何使用GraphViz生成多个级别(PHP的Image_Graphviz接口)

i'm trying to generate the following diagram using Image_GraphViz for PEAR. However It only shows a top-level node (with the text "0") and childnodes "1", "2", "3" and "4" directly under the top-node. Am I missing something?

This is the code:

    $gv = new Image_GraphViz(true);

    $gv->addEdge(array('1', '2'));
    $gv->addEdge(array('2', '3'));
    $gv->addEdge(array('2', '4'));
    $gv->addEdge(array('3', '5'));
    $gv->addEdge(array('3', '6'));
    $gv->addEdge(array('3', '7'));
    $gv->addEdge(array('4', '5'));

    echo $gv->fetch('svg');

I tried the following, but this is obviously wrong :).

    $gv->addEdge(array('1', '2'));
    $gv->addEdge(array('1', '2', '3'));
    $gv->addEdge(array('1', '2', '4'));
    $gv->addEdge(array('1', '2', '3', '5'));
    $gv->addEdge(array('1', '2', '3', '6'));
    $gv->addEdge(array('1', '2', '3', '7'));
    $gv->addEdge(array('1', '2', '4', '5'));

I understand there are two ways to get to 5. Through (1, 2, 3, 5) and/or (1, 2, 4, 5).

The image should just show two lines going to 5. I'm very confused, any suggestions?

  • 写回答

1条回答 默认 最新

  • douji6735 2009-11-02 14:11
    关注

    From the documentation it seems you need associative arrays. Can you try this instead?

    $gv = new Image_GraphViz(true);
    
    // Notice the use of =>
    $gv->addEdge(array('1' => '2'));
    $gv->addEdge(array('2' => '3'));
    $gv->addEdge(array('2' => '4'));
    $gv->addEdge(array('3' => '5'));
    $gv->addEdge(array('3' => '6'));
    $gv->addEdge(array('3' => '7'));
    $gv->addEdge(array('4' => '5'));
    
    echo $gv->fetch('svg');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 绿盟安全扫描--检测到目标站点存在javascript框架库漏洞
  • ¥30 Android STD快速启动
  • ¥15 如何使用simulink建立一个永磁同步直线电机模型?
  • ¥30 天体光谱图的的绘制并得到星表
  • ¥15 PointNet++的onnx模型只能使用一次
  • ¥20 西南科技大学数字信号处理
  • ¥15 有两个非常“自以为是”烦人的问题急期待大家解决!
  • ¥30 STM32 INMP441无法读取数据
  • ¥15 R语言绘制密度图,一个密度曲线内fill不同颜色如何实现
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包