2011-11-21 4 views
-1

도트 형식의 파일이 있고 Windows 용 그래프를 다운로드 할 수 있습니다. graphva를 사용하여 C# 응용 프로그램에서 그래프를 표시하는 방법은 무엇입니까?C# 응용 프로그램에서 graphvis를 사용하는 방법은 무엇입니까?

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"); 

     } 

이 내가 시작하는 간단한 코드를 사용했습니다 형식

+0

당신의 특정한 pr에서 당신을 도울 방법을 알고 있으십시오 oblem. 우리가 도울 수 있도록 범위를 좁힐 방법을 찾아야합니다. – BoltClock

답변

6

을 PNG로에 도트 파일 형식을 보여 graphvis와 그래프 또는 일부 sipmle 클래스를 보여 ahmad.dot 파일 형식을 visul 할 내 코드입니다 과거에과 같이 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 }); 
} 

을 조금 빠른 - 및 - 더러운 방법을 생각하지 않는 경우,이 작동 할 수 있습니다 당신

너무 많은 우리 여기가 진행되고
+0

@ ghasedak- 원하는 것을 말해주세요. 'GenDiagramFile' 함수 코드를 사용하여 이미지 ('.png' 등)를 생성하고이를 대화 상자/컨트롤에 표시 할 수 있습니다. 이게 _ 당신이 원하는 것 아닌가요? – sehe

+0

@ ghasedak- : 내 친구, 그 전체 코드도 보여 줬어. 모든 정직한 점에서 나는'ExecuteCommand ("dot", string.Format (""{0} ""-o ""{1} ""-Tpng ", dotfile, diagramFile))' 여기서'dotfile'은 당신 자신의 기존 파일 인 dotfile에 대한 경로입니다. – sehe

+0

@ ghasedak- : 이전 주석, 특히'dotfile'을 사용합니다. – sehe

관련 문제