【问题标题】:Does Quickgraph.Graphviz needs graphviz installation to draw graph image?Quickgraph.Graphviz 是否需要安装 graphviz 才能绘制图形图像?
【发布时间】:2016-11-10 00:23:32
【问题描述】:

我能够通过命令行使用 graphviz (dot.exe) 生成图形文件。需要使用 Quickgraph.Graphviz 生成图形,无需安装。有可能吗?

【问题讨论】:

    标签: c# graphviz quickgraph


    【解决方案1】:

    这在一定程度上取决于您如何定义“安装”。如果您希望通过代码使用当前系统上的 dot.exe,您可以(来自我无法在线重新找到的示例):

    public sealed class GraphRenderer : IDotEngine
    {
        public string Run(GraphvizImageType imageType, string dot, string outputFileName)
        {
            string output = outputFileName;
            File.WriteAllText(output, dot);
    
            // assumes dot.exe is in the path EnvVar:
            var args = $@"{output} -Tjpg -O";
            System.Diagnostics.Process.Start("dot", args);
            return output;
        }
    }
    

    使用:

    var exportGraph = new GraphvizAlgorithm<TNode, TEdge>(graphToDraw);
    exportGraph.Generate(new GraphRenderer(), "ActionGraph");
    

    您可以使用exportGraph.FormatVertex/FormatEdge 修改渲染。虽然这里我假设“点”在环境变量中,但如果安装得太多了,没有理由不能将进程指向本地文件。

    【讨论】:

      猜你喜欢
      • 2011-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-12
      • 1970-01-01
      • 2023-02-26
      相关资源
      最近更新 更多