【问题标题】:how use graphvis in C# application? [closed]如何在 C# 应用程序中使用 graphvis? [关闭]
【发布时间】:2011-11-21 20:28:17
【问题描述】:

我有一个点格式文件,我现在下载适用于 Windows 的 graphvis 如何使用 graphvis 在我的 c# 应用程序中显示图形?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using VDS.RDF;
using VDS.RDF.Parsing;
using VDS.RDF.Query;
using System.IO;
using System.Windows;
using System.Runtime.InteropServices;
using VDS.RDF.Writing;
using System.Diagnostics;

namespace WindowsFormsApplication2
{
    public partial class first : Form

    {

         Graph g = new Graph();
         string s1 = null;

/**************************************DATA********************************************/
        public first()
        {
            InitializeComponent();

        }

        private void button1_Click(object sender, EventArgs e)
        {

            Stream myStream = null;

            var parser = new Notation3Parser();
            var graph = new Graph();
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            openFileDialog1.Filter = "RDF files (*.n3)|*.n3";
            openFileDialog1.FilterIndex = 1;
            openFileDialog1.RestoreDirectory = true;
            openFileDialog1.Multiselect = false;

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if ((myStream = openFileDialog1.OpenFile()) != null)
                    {
                        using (myStream)
                        {
                            string s = openFileDialog1.FileName.ToString();
                            string w= Directory.GetCurrentDirectory().ToString();
                            string Fname = openFileDialog1.SafeFileName.ToString();
                            File.Copy(s,Path.Combine(w,Fname),true);

                            // Insert code to read the stream here.
                            Win32.AllocConsole();
                            s1 = Path.Combine(w, Fname);
                            insertNodeButton.Visible = true;
                            delBut.Visible = true;
                            simi.Visible = true;
                            showNodes showNodes1 = new showNodes(s1);
                            g = showNodes1.returngraph();

                           Console.Read();
                           Win32.FreeConsole();
                          // g.SaveToFile("firstfile.n3");

                           this.Show();
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                }
            }
            GraphVizWriter hi = new GraphVizWriter();
            hi.Save(g, "c:\\ahmad.dot");

        }

这是我的代码,我想查看 ahmad.dot 文件格式以显示带有 graphvis 或某些 sipmle 类的图形以显示 png 格式的点文件格式

【问题讨论】:

  • 这里有太多事情要做,我们不知道如何帮助您解决您的具体问题。您必须想办法缩小范围,以便我们提供帮助。

标签: c# graphviz


【解决方案1】:

过去我使用简单的代码来启动 dot.exe:

private static string GenDiagramFile(string pathToDotFile)
{
    var diagramFile = pathToDotFile.Replace(".dot", ".png");

    ExecuteCommand("dot", string.Format(@"""{0}"" -o ""{1}"" -Tpng", 
                 pathToDotFile, diagramFile));

    return diagramFile;
}

private static void ExecuteCommand(string command, string @params)
{
    Process.Start(new ProcessStartInfo(command, @params) {CreateNoWindow = true, UseShellExecute = false });
}

如果您不介意快速而肮脏的方法,这可能对您有用

【讨论】:

  • @ghasedak- 告诉我你想要什么。您可以使用GenDiagramFile 功能代码生成图像(例如.png)并将其显示在对话框/控件上。这你想要的,不是吗?
  • @ghasedak-:我的朋友,我也展示了完整的代码。老实说,我认为您只需写 ExecuteCommand("dot", string.Format(@"""{0}"" -o ""{1}"" -Tpng", dotfile, diagramFile)) 其中dotfile 是您自己的现有点文件的路径
  • @ghasedak-:看我之前的评论,尤其是dotfile这个词的用法
  • 我已经简化了我的答案,以便您可以更清楚地看到已经存在的信息:) 另外,请不要大喊大叫。它不会激励我。
  • @ghasedak-:是的。你试过了吗?
猜你喜欢
  • 2012-10-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多