-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm1.vb
68 lines (61 loc) · 2.93 KB
/
Form1.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
Imports System
Imports System.Data
Imports System.Windows.Forms
Imports DevExpress.XtraCharts
' ...
Namespace SideBySideStackedBarChart
Public Partial Class Form1
Inherits Form
Private chart As ChartControl
Public Sub New()
InitializeComponent()
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
' Create a new chart.
chart = New ChartControl()
chart.Dock = DockStyle.Fill
Me.Controls.Add(chart)
' Bind the chart to a data source.
' Specify data members that the series template uses to
' obtain series names, arguments, and values.
chart.DataSource = GetChartData()
chart.SeriesTemplate.SeriesDataMember = "Month"
chart.SeriesTemplate.ArgumentDataMember = "Section"
chart.SeriesTemplate.ValueDataMembers.AddRange(New String() {"Value"})
' Assign the Side-by-Side Stacked Bar series view to generated series.
Dim view As SideBySideStackedBarSeriesView = New SideBySideStackedBarSeriesView()
chart.SeriesTemplate.View = view
view.BarWidth = 0.6
'Enable point labels and format their text.
chart.SeriesTemplate.LabelsVisibility = DevExpress.Utils.DefaultBoolean.True
chart.SeriesTemplate.Label.TextPattern = "{V}"
' Customize axes.
Dim diagram As XYDiagram = TryCast(chart.Diagram, XYDiagram)
diagram.AxisX.Tickmarks.MinorVisible = False
diagram.AxisY.WholeRange.AlwaysShowZeroLevel = False
AddHandler chart.BoundDataChanged, AddressOf Chart_BoundDataChanged
End Sub
Private Sub Chart_BoundDataChanged(ByVal sender As Object, ByVal e As EventArgs)
For Each series As Series In chart.Series
If series.Points.Count > 0 Then
Dim row As DataRowView = TryCast(series.Points(0).Tag, DataRowView)
CType(series.View, ISupportStackedGroup).StackedGroup = row("Group")
End If
Next
End Sub
Public Function GetChartData() As DataTable
Dim table As DataTable = New DataTable()
table.Columns.Add("Month", GetType(String))
table.Columns.Add("Section", GetType(String))
table.Columns.Add("Value", GetType(Integer))
table.Columns.Add("Group", GetType(Integer))
table.Rows.Add(New Object() {"January", "Section1", 10, 1})
table.Rows.Add(New Object() {"January", "Section2", 20, 1})
table.Rows.Add(New Object() {"February", "Section1", 20, 1})
table.Rows.Add(New Object() {"February", "Section2", 30, 2})
table.Rows.Add(New Object() {"March", "Section1", 15, 2})
table.Rows.Add(New Object() {"March", "Section2", 25, 1})
Return table
End Function
End Class
End Namespace