Private XRangeSelector As C1.Win.Chart.Interaction.RangeSelector
Public Sub New()
InitializeComponent()
SetupCharts()
End Sub
Public Sub SetupRangeSelector()
If XRangeSelector IsNot Nothing Then
Return
End If
' add X-RangeSelector
XRangeSelector = New C1.Win.Chart.Interaction.RangeSelector(FlexChart2)
AddHandler XRangeSelector.ValueChanged, AddressOf XRangeSelector_ValueChanged
End Sub
Private Sub XRangeSelector_ValueChanged(sender As Object, e As EventArgs)
FlexChart1.AxisX.Min = XRangeSelector.LowerValue
FlexChart1.AxisX.Max = XRangeSelector.UpperValue
End Sub
Private Sub SetupCharts()
Dim rnd = New Random()
Dim pointsCount = rnd.[Next](1, 30)
Dim temperaturePoints = New List(Of DataItem)()
Dim [date] As New DateTime(2016, 1, 1)
While [date].Year = 2016
Dim newItem = New DataItem()
newItem.[Date] = [date]
If [date].Month <= 8 Then
newItem.MaxTemp = rnd.[Next](3 * [date].Month, 4 * [date].Month)
Else
newItem.MaxTemp = rnd.[Next]((13 - [date].Month - 2) * [date].Month, (13 - [date].Month) * [date].Month)
End If
newItem.MinTemp = newItem.MaxTemp - rnd.[Next](6, 8)
newItem.MeanTemp = (newItem.MaxTemp + newItem.MinTemp) / 2
newItem.MeanPressure = rnd.[Next](980, 1050)
newItem.Presipitation = If(rnd.[Next](5) = 1, rnd.[Next](0, 20), 0)
temperaturePoints.Add(newItem)
[date] = [date].AddDays(1)
End While
'Setup flexChart1
FlexChart1.BeginUpdate()
FlexChart1.ChartType = C1.Chart.ChartType.Line
FlexChart1.Series.Clear()
FlexChart1.BindingX = "Date"
FlexChart1.Series.Add(New Series() With {
.Name = "MeanTemp",
.Binding = "MeanTemp"
})
FlexChart1.Series.Add(New Series() With {
.Name = "MaxTemp",
.Binding = "MaxTemp"
})
FlexChart1.Series.Add(New Series() With {
.Name = "MinTemp",
.Binding = "MinTemp"
})
FlexChart1.DataSource = temperaturePoints.ToArray()
FlexChart1.EndUpdate()
'Setup flexChart2
FlexChart2.BeginUpdate()
FlexChart2.ChartType = C1.Chart.ChartType.Line
FlexChart2.Series.Clear()
FlexChart2.BindingX = "Date"
FlexChart2.Series.Add(New Series() With {
.Name = "MeanTemp",
.Binding = "MeanTemp"
})
FlexChart2.DataSource = temperaturePoints.ToArray()
FlexChart2.EndUpdate()
End Sub
Class DataItem
Public Property MaxTemp() As Integer
Get
Return m_MaxTemp
End Get
Set
m_MaxTemp = Value
End Set
End Property
Private m_MaxTemp As Integer
Public Property MinTemp() As Integer
Get
Return m_MinTemp
End Get
Set
m_MinTemp = Value
End Set
End Property
Private m_MinTemp As Integer
Public Property MeanTemp() As Integer
Get
Return m_MeanTemp
End Get
Set
m_MeanTemp = Value
End Set
End Property
Private m_MeanTemp As Integer
Public Property MeanPressure() As Integer
Get
Return m_MeanPressure
End Get
Set
m_MeanPressure = Value
End Set
End Property
Private m_MeanPressure As Integer
Public Property Presipitation() As Integer
Get
Return m_Presipitation
End Get
Set
m_Presipitation = Value
End Set
End Property
Private m_Presipitation As Integer
Public Property [Date]() As DateTime
Get
Return m_Date
End Get
Set
m_Date = Value
End Set
End Property
Private m_Date As DateTime
End Class
Private Sub FlexChart2_Rendered(sender As Object, e As RenderEventArgs)
SetupRangeSelector()
FlexChart1_Rendered(sender, e)
End Sub
Private Sub FlexChart1_Rendered(sender As Object, e As RenderEventArgs)
Dim flexChart = TryCast(sender, FlexChart)
If flexChart Is Nothing Then
Return
End If
Using pen = New Pen(New SolidBrush(Color.LightGray))
Dim rect = New Rectangle(CInt(flexChart.PlotRect.X), CInt(flexChart.PlotRect.Y), CInt(flexChart.PlotRect.Width), CInt(flexChart.PlotRect.Height))
e.Graphics.DrawRectangle(pen, rect)
End Using
End Sub