简体   繁体   中英

How to render my graph using QuickGraph C#

I'm new to QuickGraph . I followed the examples on the documentation page to add vertices & edges to my graph. Now, I want to display my graph on a windows form. I'm using Graphviz for that purpose, which generates a .DOT file as output. I'm following the code sample below for rendering:

IVertexAndEdgeListGraph<TVertex,TEdge> g= ...;
var graphviz = new GraphvizAlgorithm<TVertex,TEdge>(g);
string output = graphviz.Generate(new FileDotEngine(), "graph");

But, my compiler is not detecting FileDotEngine() . Moreover, I don't know what to do after the .DOT file is generated.

You have to provide a FileDotEngine yourself; see for instance this example on Github . A simple FileDotEngine that generates a jpg could be:

public sealed class FileDotEngine : IDotEngine
{
    public string Run(GraphvizImageType imageType, string dot, string outputFileName)
    {
        string output = outputFileName;
        File.WriteAllText(output, dot);

        // assumes dot.exe is on the path:
        var args = string.Format(@"{0} -Tjpg -O", output);
        System.Diagnostics.Process.Start("dot.exe", args);
        return output;
    }
}

Then you could display the generated image in a picture box or similar.

Another approach would be to host a WPF control in your winforms app and then use Graph# to display the graph. I haven't tried this myself, however.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM