Aligning multiple series with mis-matching DateTime source

Hi, I need to visually compare a "base" series with a "comparison" series with differing DateTime values. However, they need to be aligned so that the DateTime values of both series lie in the same location on the primary axis. For example, the datapoint in the base series with the time value of 1/12/2000 13:02 must be on the same location on the primary axis as the same time value of the compare series.

  • Both series contain price data for every minute during different business hours, starting and ending at different dates, with different holidays.
  • The primary and secondary axis belongs to the base series, the comparison series has it's own secondary axis. 
  • When zooming and scrolling, both series Y zoom independently so that they both fill the available space.
  • The X values for the primary axis are those of the base series, so the comparison series X values need to be modified, by either deleting, or adding empty points, to a new temporary data source to match the base series X values. 

The attached sample is working exactly as intended. The problem is that converting the comparison series to match the base series takes too long.

This is where the time is spent:
The algorithm in the GetCompareData function loops through every X value (DateTime) in the base series and tries to find a Minute object in the compare data source with the same DateTime value. If a match is found, that Minute object is placed into a temporary data source list. If not, a new Minute object is added with empty price data. Lastly, that temporary data source is used as ItemsSource for the compare series.

Using series A as base and series B as comparison, this function takes 1.76 seconds, and 2.68 seconds when B is the base series (because B has more data). The data for this sample is relatively small.

To test, run the sample and select B as the comparison series, or vice versa.

Does sfChart have features which can speed up this process, or is there a better, faster method?

Thank you.


Attachment: sfChartCompareTest_999fd161.rar

7 Replies

MK Muneesh Kumar G Syncfusion Team May 11, 2018 12:24 PM UTC

Hi Tom,

Thanks for using Syncfusion products.
 
 
We have analyzed your requirement and resolved the performance issue by comparing the holidays in another data set instead of comparing the whole data in the loop. 
 
Code Snippet 
 
 
    Function GetCompareData(inBaseTicker As Ticker, inCompareTicker As Ticker) As List(Of Minute) 
 
        Dim ReturnList As New List(Of Minute) 
 
        Dim actualSeries As Object = TryCast(BaseSeries, XyDataSeries) 
 
        If Not actualSeries Is Nothing Then 'if series is XyDataSeries 
 
            Dim XValues = CType(actualSeries.GetType().GetProperty("XValues", BindingFlags.GetProperty Or BindingFlags.NonPublic Or BindingFlags.Instance).GetValue(actualSeries), IList(Of Double)) 
 
            For i As Integer = 0 To XValues.Count - 1 
 
                Dim searchDateTime = DateTime.FromOADate(XValues(i)) 
 
                Dim isHoliday As Boolean = False 
 
                For Each holiday In inCompareTicker.Holidays 
                    If (holiday.Day = searchDateTime.Day) Then 
                        isHoliday = True 
                    End If 
                Next 
 
                If (isHoliday) Then 
                    Dim NaNMinute As New Minute 
                    NaNMinute.DateTime = searchDateTime 
                    NaNMinute.Ticker = inCompareTicker 
                    ReturnList.Add(NaNMinute) 
                Else 
                    ReturnList.Add(inCompareTicker.Minutes(i)) 
                End If 
 
            Next 
 
        End If 
 
        Return ReturnList 
 
    End Function 
 
We have modified your sample based on above solution, please find the sample from the below location.   
 
 
Please let us know if you have any queries.   

Regards,
 
Muneesh Kumar G. 
 



TO Tom May 11, 2018 05:06 PM UTC

Hi Muneesh, your solution is not correct. The requirement is that the DateTime for both series are aligned. You can check this with the trackball. If you run your sample, and use A as base series and B as compare series, then move the trackball to where A is 1/7/2000 13:57, you will see that B is 1/4/2000 04:58. The times are different, they are not aligned. But if you run my original sample you will see that both A and B are 1/7/2000 13:57, which means they are aligned.


MK Muneesh Kumar G Syncfusion Team May 11, 2018 05:34 PM UTC

Hi Tom,

We have resolved this problem by using series ItemsSource instead of XValues in comparision as per the below code snippet.
 
 
Code Snippet 
 
 
     Function GetCompareData(inBaseTicker As Ticker, inCompareTicker As Ticker) As List(Of Minute) 
 
        Dim ReturnList As New List(Of Minute) 
 
        Dim actualSeries As Object = TryCast(BaseSeries, XyDataSeries) 
 
        If Not actualSeries Is Nothing Then 'if series is XyDataSeries 
 
            Dim values = CType(CType(actualSeries, XyDataSeries).ItemsSource, ObservableCollection(Of Minute)) 
 
            For i As Integer = 0 To values.Count - 1 
 
                Dim searchDateTime = values(i).DateTime 
 
                Dim isHoliday As Boolean = False 
 
                For Each holiday In inCompareTicker.Holidays 
                    If (holiday.Day = searchDateTime.Day) Then 
                        isHoliday = True 
                    End If 
                Next 
 
                If (isHoliday) Then 
                    Dim NaNMinute As New Minute 
                    NaNMinute.DateTime = searchDateTime 
                    NaNMinute.Ticker = inCompareTicker 
                    ReturnList.Add(NaNMinute) 
                Else 
                    ReturnList.Add(values(i)) 
                End If 
 
            Next 
 
        End If 
 
        Return ReturnList 
 
    End Function 
 
 
We have modified your sample based on above solution, please find the sample from the below location.   
 
 
Please let us know if you have any queries.   

Regards,
 
Muneesh Kumar G. 
 



TO Tom May 12, 2018 03:01 AM UTC

Hi Muneesh, this solution is also not correct. What you've done is simply creating a duplicate of the A series, thereby comparing A with itself. If you check the trackball using your sample, you will see that both datapoints belong to A.


MK Muneesh Kumar G Syncfusion Team May 14, 2018 09:17 AM UTC

Hi Tom, 
 
We have resolved the performance issue in data generation by reducing data region by index as per the below code snippet.  
 
Code Snippet 
 
 
    Function GetCompareData(inBaseTicker As Ticker, inCompareTicker As Ticker) As List(Of Minute) 
 
        Dim ReturnList As New List(Of Minute) 
 
        Dim actualSeries As Object = TryCast(BaseSeries, XyDataSeries) 
 
        If Not actualSeries Is Nothing Then 'if series is XyDataSeries 
 
            Dim XValues = CType(actualSeries.GetType().GetProperty("XValues", BindingFlags.GetProperty Or BindingFlags.NonPublic Or BindingFlags.Instance).GetValue(actualSeries), IList(Of Double)) 
            Dim j As Integer = 0 
 
            For i As Integer = 0 To XValues.Count - 1 
 
                Dim searchDateTime = DateTime.FromOADate(XValues(i)) 
 
                While (j < inCompareTicker.Minutes.Count) 
 
                    Dim compareMinute = inCompareTicker.Minutes(j) 
 
                    If (compareMinute.DateTime = searchDateTime) Then 
 
                        ReturnList.Add(compareMinute) 
                        j = j + 1 
                        Exit While 
 
                    ElseIf (searchDateTime < compareMinute.DateTime) Then 
 
                        Dim NaNMinute As New Minute 
                        NaNMinute.DateTime = searchDateTime 
                        NaNMinute.Ticker = inCompareTicker 
                        ReturnList.Add(NaNMinute) 
                        Exit While 
 
                    End If 
                    j = j + 1 
 
                End While 
            Next 
 
        End If 
 
        Return ReturnList 
 
    End Function 
 
 
We have checked the performance and trackball data, it works fine. We have modified your sample based on the above solution, please find the sample from the below location.   
 
 
Please let us know if you have any queries.  
 
Thanks,
Muneesh Kumar G
 



TO Tom May 14, 2018 11:29 AM UTC

Thank you so much, this works great.


MK Muneesh Kumar G Syncfusion Team May 15, 2018 04:09 AM UTC

Hi Tom, 

Thanks for the update.

We are glad to know that the given solution works. Please let us know if you need any further assistance.

Thanks,
Muneesh Kumar G.

Loader.
Up arrow icon