关于devexpress:数据可视化新方式SankeyDiagramControl类的使用你不能错过Part-1

24次阅读

共计 3582 个字符,预计需要花费 9 分钟才能阅读完成。

点击获取工具 >>
命名空间 :DevExpress.XtraCharts.Sankey

程序集 :DevExpress.XtraCharts.v20.2.UI.dll

申明

C#

`[SerializationContext(typeof(SankeySerializationContext))]
public class SankeyDiagramControl :
Control,
ISankeyContainer,
IToolTipControlClient,
ISupportLookAndFeel,
ISankeyRenderProvider,
IChartRenderProvider,
IPrintable,
IBasePrintable`

VB.NET

`<SerializationContext(GetType(SankeySerializationContext))>
Public Class SankeyDiagramControl
Inherits Control
Implements ISankeyContainer,
IToolTipControlClient,
ISupportLookAndFeel,
ISankeyRenderProvider,
IChartRenderProvider,
IPrintable,
IBasePrintable`

正文

Sankey 图表形容零碎中实体(也称为节点)之间的转移或流,该图能够帮忙您找到对流程最重要的奉献。

下图显示了图元素:

每个链接都连贯源节点和指标节点,并具备调配的值 - 权重,链接的宽度与其分量成正比。

增加到我的项目

将 SankeyDiagramControl 组件从 Toolbox 拖放到窗体中,来将 Sankey 图增加到我的项目中。

这会将对以下程序集的援用增加到我的项目中:

  • DevExpress.Charts.v20.2.Core.dll
  • DevExpress.Data.Desktop.v20.2.dll
  • DevExpress.Data.v20.2.dll
  • DevExpress.Printing.v20.2.Core.dll
  • DevExpress.XtraPrinting.v20.2.dll
  • DevExpress.Utils.v20.2.dll
  • DevExpress.Utils.v20.2.Core.dll
  • DevExpress.XtraBars.v20.2.dll
  • DevExpress.XtraCharts.v20.2.dll
  • DevExpress.XtraCharts.v20.2.UI.dll
  • DevExpress.XtraCharts.v20.2.Wizard.dll
  • DevExpress.XtraEditors.v20.2.dll

绑定到数据

应用 DataSource 属性将控件绑定到数据源,您能够为该属性调配一个实现以下任何接口的对象:IList,IListSource 或 IBindingList。

而后指定存储用于源节点、指标节点和权重数据的数据成员名称:

  • SourceDataMember – 指定蕴含源节点标签的数据成员的名称。
  • TargetDataMember – 指定蕴含指标节点标签数据成员的名称。
  • WeightDataMember (Optional) – 指定蕴含链接权重的数据成员名称,如果未指定 WeightDataMember 属性,则权重等于 1。

C#

`using System;
using System.Collections.Generic;
using System.Windows.Forms;
using DevExpress.XtraCharts.Sankey;
namespace SankeySample {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e) {
sankeyDiagramControl1.DataSource = GetSankeyItems();
sankeyDiagramControl1.SourceDataMember = “Source”;
sankeyDiagramControl1.TargetDataMember = “Target”;
sankeyDiagramControl1.WeightDataMember = “Value”;
sankeyDiagramControl1.Titles.Add(new SankeyTitle { Text = “Export/Import”});
}
List<SankeyItem> GetSankeyItems() {
List<SankeyItem> data = new List<SankeyItem> {
new SankeyItem {Source = “France”, Target = “UK”, Value = 53},
new SankeyItem {Source = “Australia”, Target = “UK”, Value = 72},
new SankeyItem {Source = “France”, Target = “Canada”, Value = 81},
new SankeyItem {Source = “China”, Target = “Canada”, Value = 96},
new SankeyItem {Source = “UK”, Target = “France”, Value = 61},
new SankeyItem {Source = “Canada”, Target = “France”, Value = 89},
};
return data;
}
}
public class SankeyItem {
public string Source {get; set;}
public string Target {get; set;}
public double Value {get; set;}
}
}
`
VB.NET

`Imports System
Imports System.Collections.Generic
Imports System.Windows.Forms
Imports DevExpress.XtraCharts.Sankey

Namespace SankeySample
Public Partial Class Form1
Inherits Form

Public Sub New()
InitializeComponent()
End Sub

Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
sankeyDiagramControl1.DataSource = GetSankeyItems()
sankeyDiagramControl1.SourceDataMember = “Source”
sankeyDiagramControl1.TargetDataMember = “Target”
sankeyDiagramControl1.WeightDataMember = “Value”
sankeyDiagramControl1.Titles.Add(New SankeyTitle With {
.Text = “Export/Import”
})
End Sub

Private Function GetSankeyItems() As List(Of SankeyItem)
Dim data As List(Of SankeyItem) = New List(Of SankeyItem) From {
New SankeyItem With {
.Source = “France”, .Target = “UK”, .Value = 53
},
New SankeyItem With {
.Source = “Australia”, .Target = “UK”, .Value = 72
},
New SankeyItem With {
.Source = “France”, .Target = “Canada”, .Value = 81
},
New SankeyItem With {
.Source = “China”, .Target = “Canada”, .Value = 96
},
New SankeyItem With {
.Source = “UK”, .Target = “France”, .Value = 61
},
New SankeyItem With {
.Source = “Canada”, .Target = “France”, .Value = 89
}
}
Return data
End Function
End Class

Public Class SankeyItem
Public Property Source As String
Public Property Target As String
Public Property Value As Double
End Class
End Namespace`

后果:

正文完
 0