/
MainWindow.xaml.vb
85 lines (76 loc) · 4.03 KB
/
MainWindow.xaml.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
Imports DevExpress.DashboardCommon
Imports DevExpress.DashboardCommon.ViewerData
Imports DevExpress.Xpf.Charts
Imports System
Imports System.Data
Imports System.Windows
Namespace Dashboard_ClientDataCards_Wpf
''' <summary>
''' Interaction logic for MainWindow.xaml
''' </summary>
Public Partial Class MainWindow
Inherits Window
Public Sub New()
Me.InitializeComponent()
End Sub
' Handles the DashboardControl_DashboardItemMouseUp event.
Private Sub DashboardControl_DashboardItemMouseUp(ByVal sender As Object, ByVal e As DevExpress.DashboardWpf.DashboardItemMouseActionWpfEventArgs)
If Equals(e.DashboardItemName, "cardDashboardItem1") And e.GetAxisPoint() IsNot Nothing Then
' Obtains client data related to the clicked card.
Dim clickedItemData As MultiDimensionalData = e.GetSlice()
Dim delta As DeltaDescriptor = e.GetDeltas()(0)
' Creates a data table that will be used to hold client data.
Dim dataSource As DataTable = New DataTable()
dataSource.Columns.Add("Argument", GetType(Date))
dataSource.Columns.Add("Actual", GetType(Double))
dataSource.Columns.Add("Target", GetType(Double))
' Saves values of axis points placed on the "sparkline" axis and corresponding
' actual/target values to the data table.
For Each point As AxisPoint In clickedItemData.GetAxisPoints(DashboardDataAxisNames.SparklineAxis)
Dim row As DataRow = dataSource.NewRow()
Dim deltaValue As DeltaValue = clickedItemData.GetSlice(point).GetDeltaValue(delta)
If deltaValue.ActualValue.Value IsNot Nothing AndAlso deltaValue.TargetValue.Value IsNot Nothing Then
row("Argument") = point.Value
row("Actual") = deltaValue.ActualValue.Value
row("Target") = deltaValue.TargetValue.Value
Else
row("Argument") = DBNull.Value
row("Actual") = DBNull.Value
row("Target") = DBNull.Value
End If
dataSource.Rows.Add(row)
Next
DisplayDetailedChart(GetFormTitle(clickedItemData), dataSource)
End If
End Sub
' Creates a new form that is invoked on the card click and
' shows the chart displaying client data.
Private Sub DisplayDetailedChart(ByVal title As String, ByVal dataSource As DataTable)
Dim detailWindow As DetailedChart = New DetailedChart()
detailWindow.Title = title
Dim chart As ChartControl = detailWindow.detailedChartControl
Dim diagram As XYDiagram2D = New XYDiagram2D()
chart.Diagram = diagram
Dim series1 As SplineAreaSeries2D = New SplineAreaSeries2D()
series1.DisplayName = "Actual"
Dim series2 As SplineAreaSeries2D = New SplineAreaSeries2D()
series2.DisplayName = "Target"
diagram.Series.AddRange(New Series() {series1, series2})
For Each series As Series In diagram.Series
series.DataSource = dataSource
series.ArgumentDataMember = "Argument"
series.ValueScaleType = ScaleType.Numerical
Next
series1.ValueDataMember = "Actual"
series2.ValueDataMember = "Target"
detailWindow.ShowDialog()
End Sub
' Obtains a value of the axis point placed on the "default" axis
' to display this value in the invoked form title.
Private Function GetFormTitle(ByVal clickedItemData As MultiDimensionalData) As String
Dim clickedPoint As AxisPoint = clickedItemData.GetAxisPoints(DashboardDataAxisNames.DefaultAxis)(0)
Dim clickedPointValue As String = clickedPoint.Value.ToString()
Return clickedPointValue
End Function
End Class
End Namespace