Imports System.Collections.ObjectModel Imports System.ComponentModel Imports System.Runtime.CompilerServices Imports OxyPlot Imports OxyPlot.Series Imports Prism.Mvvm Imports RMG_Strategist Public Class StrategyViewModel : Implements INotifyPropertyChanged Dim _model As PlotModel Dim _ReferenceCar As Car Public Property Model As PlotModel Get Return _model End Get Set(value As PlotModel) _model = value NotifyPropertyChanged() Model.InvalidatePlot(True) End Set End Property Public Property ReferenceCar As Car Get Return _ReferenceCar End Get Set(value As Car) _ReferenceCar = value NotifyPropertyChanged() End Set End Property #Region "INotifyPropertyChanged Implementation" Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged Private Sub NotifyPropertyChanged( ByVal Optional propertyName As String = Nothing) RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName)) End Sub #End Region Public Sub New() Model = New PlotModel() ReferenceCar = New Car() InitilaizePlotModel(Model) RefreshPlot() End Sub Public Sub RefreshPlot() Try Dim NewModel As PlotModel = Model NewModel.Series.Clear() For Each carObject As Car In LstCars Dim Ser As New LineSeries() Ser.Title = carObject.StartNo For Each LapObject As Lap In carObject.LstLaps Ser.Points.Add(New DataPoint(LapObject.LapNo, LapObject.LapTime)) Next NewModel.Series.Add(Ser) Next Model = NewModel Catch ex As Exception LogMessage("Error on assigning laptimes to data series: " & ex.Message) End Try End Sub Private Sub InitilaizePlotModel(ByRef plotModel As PlotModel) Dim XAxis As New Axes.LinearAxis() With XAxis .Title = "Lap [-]" .MajorGridlineColor = OxyColors.Gray .MajorGridlineStyle = LineStyle.Solid .MajorGridlineThickness = 1 .MajorStep = 1 .MinorStep = 0.33333 .Position = Axes.AxisPosition.Bottom End With Dim YAxis As New Axes.LinearAxis() With YAxis .Title = "Laptime" .MajorGridlineColor = OxyColors.Gray .MajorGridlineStyle = LineStyle.Solid .MajorGridlineThickness = 1 .Position = Axes.AxisPosition.Left .LabelFormatter = AddressOf AxesTimeFormatter End With With plotModel .Title = "Test Plot" .TextColor = OxyColors.White .LegendBackground = OxyColors.White .LegendPosition = LegendPosition.RightTop .LegendTitle = "Legend" .Axes.Add(XAxis) .Axes.Add(YAxis) .PlotAreaBorderColor = OxyColors.Gray End With End Sub Private Function AxesTimeFormatter(ByVal value As Integer) As String Dim time As New TimeSpan(10000 * value) Dim stringTime As String If value < 60000 Then stringTime = time.ToString("s\.fff") Else stringTime = time.ToString("m\:ss\.fff") End If Return stringTime End Function End Class