/
Form1.vb
66 lines (58 loc) · 2.08 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
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Threading.Tasks
Imports System.Windows.Forms
Imports System.Xml.Linq
Imports DevExpress.XtraCharts
Namespace ColorObjectColorizerExample
Partial Public Class Form1
Inherits Form
Private Const filepath As String = "..\..\Data\GDP.xml"
Public Sub New()
InitializeComponent()
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
' #Region "#BarSeries"
' Create and customize a bar series.
Dim barSeries As New Series() With {
.DataSource = LoadData(filepath),
.ArgumentDataMember = "Country",
.ColorDataMember = "NationalColor",
.View = New SideBySideBarSeriesView()
}
barSeries.View.Colorizer = New ColorObjectColorizer()
barSeries.ValueDataMembers.AddRange(New String() { "Product" })
' #End Region ' #BarSeries
' Add the series to the ChartControl's Series collection.
chartControl1.Series.Add(barSeries)
' Show a title for the values axis.
CType(chartControl1.Diagram, XYDiagram).AxisY.Title.Text = "GDP per capita, $"
CType(chartControl1.Diagram, XYDiagram).AxisY.Title.Visibility = DevExpress.Utils.DefaultBoolean.True
End Sub
#Region "#DataLoad"
Private Class HpiPoint
Public Property Country() As String
Public Property Product() As Double
Public Property NationalColor() As String
End Class
' Loads data from an XML data source.
Private Shared Function LoadData(ByVal filepath As String) As List(Of HpiPoint)
Dim doc As XDocument = XDocument.Load(filepath)
Dim points As New List(Of HpiPoint)()
For Each element As XElement In doc.Element("G20HPIs").Elements("CountryStatistics")
points.Add(New HpiPoint() With {
.Country = element.Element("Country").Value,
.Product = Convert.ToDouble(element.Element("Product").Value),
.NationalColor = element.Element("NationalColor").Value
})
Next element
Return points
End Function
#End Region ' #DataLoad
End Class
End Namespace