3

I have a graph which I would like to represent using an image on a website. The problem is generating this image dynamically based on the current state of the graph.

I'm using ASP.Net MVC 3 with C#.

I've been thinking about generating the image on the harddisk using some tool(Graphviz etc.) and then passing the path of the file to the view.

Security isn't a real issue, as this is just internal project based work for now, it is much more important that its easy to implement.

I've been trying quickgraph, and eventually i've had it generating DOT files (apperently it ignores my attempts to make PNG's) but the code fails because the program don't have access to where the files are generated. I suppose this is easy to fix, though.

Do you have any suggestions to how I could do this (If i should do something completely different or how i can get the DOT files rendered as PNG)?

Best regards, Daniel

Tarnay Kálmán
  • 6,907
  • 5
  • 46
  • 57
DkM
  • 800
  • 1
  • 7
  • 22
  • 1
    Have a look at this: http://stackoverflow.com/questions/319835/new-asp-net-charting-controls-will-they-work-with-mvc-eventually#320891 – gideon Mar 21 '11 at 11:33
  • Thanks, looks a bit on the way. A problem is that i might (i'm not completely sure on this) have to run graphwiz in order to generate an image, which means that i have to write a file to disk, run the graphwiz executable and then load the image. – DkM Mar 21 '11 at 16:42

2 Answers2

2

Just wanted to note that I solved this using the Google Image Chart, they have experimental Graphviz support: http://code.google.com/apis/chart/image/docs/gallery/graphviz.html

Simply generate an URL and insert an external image on your page.

Tarnay Kálmán
  • 6,907
  • 5
  • 46
  • 57
DkM
  • 800
  • 1
  • 7
  • 22
  • Google Chart Tools are pretty powerful, and look very professional. I'd recommend them! http://code.google.com/apis/chart/ – Scott Rippey Aug 25 '11 at 06:40
0

If the graph library allows you, write the result to a memory stream and place it in the Cache (System.Web.HttpRuntime.Cache) with a key.

Use that key to generate the img tag in the view and point to an action ('View'?) in a controller ('Image') like "/Image/View/392838".

Create this controller and view and serve the contents (make sure to include proper MIME type, content type etc.) from there.

In the cache specify a decent lifetime for the object, such as 15 seconds, sliding expiration.

Andrei Rînea
  • 20,288
  • 17
  • 117
  • 166
  • Hi, sadly graphwiz comes as an exe (at least thats the default way to do it) so its not possible to get it to a memory stream directly. – DkM Aug 24 '11 at 13:23