Một chút muộn, nhưng nó thực sự là tương đối dễ dàng để thực hiện bản thân: Kiểm soát WPF
public class DGMLWriter
{
public struct Graph
{
public Node[] Nodes;
public Link[] Links;
}
public struct Node
{
[XmlAttribute]
public string Id;
[XmlAttribute]
public string Label;
public Node(string id, string label)
{
this.Id = id;
this.Label = label;
}
}
public struct Link
{
[XmlAttribute]
public string Source;
[XmlAttribute]
public string Target;
[XmlAttribute]
public string Label;
public Link(string source, string target, string label)
{
this.Source = source;
this.Target = target;
this.Label = label;
}
}
public List<Node> Nodes { get; protected set; }
public List<Link> Links { get; protected set; }
public DGMLWriter()
{
Nodes = new List<Node>();
Links = new List<Link>();
}
public void AddNode(Node n)
{
this.Nodes.Add(n);
}
public void AddLink(Link l)
{
this.Links.Add(l);
}
public void Serialize(string xmlpath)
{
Graph g = new Graph();
g.Nodes = this.Nodes.ToArray();
g.Links = this.Links.ToArray();
XmlRootAttribute root = new XmlRootAttribute("DirectedGraph");
root.Namespace = "http://schemas.microsoft.com/vs/2009/dgml";
XmlSerializer serializer = new XmlSerializer(typeof(Graph), root);
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
XmlWriter xmlWriter = XmlWriter.Create(xmlpath, settings);
serializer.Serialize(xmlWriter, g);
}
}
Nguồn
2012-09-18 10:56:45
+1 NodeXL là rất mạnh mẽ. Thật tuyệt vời khi đại diện cho dữ liệu liên quan theo đồ họa. Cảm ơn bạn đã tham khảo! –
Mô tả đang diễn ra khó hiểu. Điều đó có nghĩa là nó sẽ hoạt động trên một hệ thống không có cài đặt Excel? –
Vâng, đúng vậy, tôi cũng chưa cài đặt Excel. Bây giờ, đây là một vài năm trước. Ngày nay tôi có lẽ sẽ sử dụng D3 cho điều này hoặc một thành phần sử dụng d3, chẳng hạn như Dagre, được đề nghị ở đây: http://stackoverflow.com/a/20342129/1373170 –