Generateing Graphs

Topics: graph
Sep 18, 2008 at 1:04 PM
Edited Sep 18, 2008 at 1:22 PM
Hi, I'm just following the example in the document, but haven't got any luck.
Here is the code snippet.

var g = new AdjacencyGraph<int, TaggedEdge<int, string>>();
            int v1 = 1;
            int v2 = 2;
            int v3 = 1;
            int v4 = 2;

           
            g.AddVertex(v1);
            g.AddVertex(v2);
            //The edges (v1,v2) and (v2,v1) are created and added to the graph.
            var e1 = new TaggedEdge<int,string>(v1,v2, "hello");
 
            g.AddEdge(e1);

            // v3, v4 are not added to the graph yet
            var e2 = new TaggedEdge<int,string>(v3,v4,"hello");
            var e3 = new TaggedEdge<int, string>(v1, v3, "v1->v3");
            g.AddVerticesAndEdge(e2);
            g.AddEdge(e3);

            GraphvizAlgorithm<int, TaggedEdge<int, string>> graphviz = new GraphvizAlgorithm<int, TaggedEdge<int, string>>(g, @"c:\", QuickGraph.Graphviz.Dot.GraphvizImageType.Png);

            // render
            string output = graphviz.Generate(new FileDotEngine(), "outputTest");
            Console.Write(output);

=============================================================================
I didn't see any particular file generated, neither the exceptions, except that graph.dot in the bin folder. And it's content is not what I expected either.
digraph G {
0 ;
1 ;
0 -> 1 [];
0 -> 1 [];
}

Is there anyone could help ? How do I generate an image by using the lib? Do I also need to install Graphviz?

Sep 18, 2008 at 7:11 PM
Yes, you need graphviz to render the .dot file to an image. Please refer to Graphviz documentation on how to do that.

To 'customize' the output of the dot file, hook to {{graphviz.FormatVertex}} event.