图和 ASP.Net MVC
我有一个图表,我想使用网站上的图像来表示。问题是根据图形的当前状态动态生成该图像。
我正在使用 ASP.Net MVC 3 和 C#。
我一直在考虑使用某种工具(Graphviz 等)在硬盘上生成图像,然后将文件的路径传递给视图。
安全性不是一个真正的问题,因为目前这只是基于内部项目的工作,更重要的是它易于实施。
我一直在尝试 Quickgraph,最终我让它生成了 DOT 文件(显然它忽略了我制作 PNG 的尝试),但代码失败了,因为程序无法访问生成文件的位置。不过,我想这很容易解决。
您对我如何做到这一点有什么建议吗(如果我应该做一些完全不同的事情或者如何将 DOT 文件渲染为 PNG)?
此致, 丹尼尔
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只是想指出,我使用 Google Image Chart 解决了这个问题,他们有实验性的 Graphviz 支持: http://code.google.com/apis/chart/image/docs/gallery/graphviz.html
只需生成一个网址并在您的网页上插入外部图像即可。
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.
如果图形库允许,请将结果写入内存流,并使用键将其放入缓存(System.Web.HttpRuntime.Cache)中。
使用该键在视图中生成 img 标签,并指向控制器(“Image”)中的操作(“View”?),例如“/Image/View/392838”。
创建此控制器并从那里查看和提供内容(确保包含正确的 MIME 类型、内容类型等)。
在缓存中为对象指定一个适当的生命周期,例如 15 秒,滑动过期。
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.