我有一个点格式文件,我现在为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格式显示点文件格式
答案 0 :(得分:6)
我过去曾使用简单的代码启动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 });
}
如果你不介意一点点快速和肮脏的方法,这可能适合你