3

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.

MSalters
  • 173,980
  • 10
  • 155
  • 350
Ruchir Sharma
  • 819
  • 1
  • 10
  • 18
  • FYI the code in this question is just the example from https://quickgraph.codeplex.com/wikipage?title=Visualization%20Using%20Graphviz&referringTitle=Documentation – StayOnTarget Jan 24 '18 at 15:05

2 Answers2

2

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.

Marijn
  • 10,367
  • 5
  • 59
  • 80
  • Thanks a lot sir for your reply. However, my code is unable to find the file "dot.exe". I just searched for it & came to know that it's not on my system as well. What should I do now? Can I download it from some location? – Ruchir Sharma Oct 11 '13 at 14:30
  • dot.exe is part if the graphviz package - from your question I thought you already used it. Google for graphviz and windows and you'll find it in no time – Marijn Oct 12 '13 at 11:25
0

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.

Marijn
  • 10,367
  • 5
  • 59
  • 80