We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to add datapoints to a series manually?

Thread ID:

Created:

Updated:

Platform:

Replies:

149997 Dec 17,2019 12:57 PM UTC Dec 23,2019 06:05 AM UTC WPF 5
loading
Tags: SfChart
Tom
Asked On December 17, 2019 12:57 PM UTC

I have the source data for the series organized in the following fashion:

One list A of date.
One list B of float.
One list C of float.
+ 50 more lists of float

How can I use these lists as the data source for the sfChart series? For example, list A will be used for the X values, and list C will be used for Y values.

I'm aware that an SfChart series requires the source data to be in the format of a list of data objects, where each object contains the X and Y values, which are bound to the series via the XBindingPath and the YBindingPath. However, in my case I have a huge number of lists, which I will add or remove dynamically at run time. Also, separating the data into separate lists greatly improves performance in the application when manipulating the data. Looping through a single list of float is much faster than looping through a list of huge objects.

This is my attempt to set the X and Y values manually:

           'SET X VALUES
      Dim oaDatetimes As New List(Of Double)
      For i = 0 To BaseTicker.MinuteTimeData.DateTimeList.Count - 1
          oaDatetimes.Add(BaseTicker.MinuteTimeData.DateTimeList(i).ToOADate)
      Next
      SeriesPrice.GetType().GetProperty("ActualXValues"BindingFlags.GetProperty Or BindingFlags.NonPublic Or BindingFlags.Instance).SetValue(SeriesPrice, oaDatetimes)
 
      'SET Y VALUES
      Dim yDoubleValues As New List(Of Double)
      For i = 0 To BaseTicker.MinuteTimeData.SingleLists(0).Count - 1
          yDoubleValues.Add(CType(BaseTicker.MinuteTimeData.SingleLists(0)(i), Double))
      Next
      SeriesPrice.GetType().GetProperty("YValues"BindingFlags.GetProperty Or BindingFlags.NonPublic Or BindingFlags.Instance).SetValue(SeriesPrice, yDoubleValues)
However, it does not work. The ActualXValues and YValues get set correctly, but the datapoint count is still zero.

Attached is a sample app. Find the relevant code in the BtLoadData_Click  event handler.
Run the app, click the Create Data button. The series appears as normal.
Now comment out the METHOD 1 region and uncomment the METHOD 2 region. Run the app again, and click the Create Data button. Nothing happens.

How can this be achieved? Thank you.
 


Attachment: sfChartSplitItemsSource_b8abd1ef.rar

Hemalatha Marikumar [Syncfusion]
Replied On December 18, 2019 12:55 PM UTC

Hi Tom, 
  
Greetings from Syncfusion. 
  
We have analysed your query with your sample and you can achieve this requirement by calling the CreateSegments method and the ScheduleUpdate method after setting the ActualXValues and YValues for the series. In addition, you need to override the ClearUnUsedSegments method and remove the base in FastSteplineBitmapSeriesClipExt to render the series. Please refer below code snippet. 
  
Code Snippet [MainWindow.Xaml.vb] 
  
    Private Sub BtLoadData_Click(sender As Object, e As RoutedEventArgs) Handles btLoadData.Click 
#Region "METHOD 2 - SET DATAPOINTS MANUALLY" 
.. 
        SeriesPrice.GetType().GetProperty("YValues", BindingFlags.GetProperty Or BindingFlags.NonPublic Or BindingFlags.Instance).SetValue(SeriesPrice, yDoubleValues) 
  
        SeriesPrice.CreateSegments() 
        Dim method As MethodInfo = GetType(ChartBase).GetMethod("ScheduleUpdate", BindingFlags.NonPublic Or BindingFlags.Instance) 
        method.Invoke(chart, Nothing) 
#End Region 
  
        ZoomX() 
  
    End Sub 
  
  
  
Code Snippet [FastSteplineBitmapSeriesClipExt] 
  
    Public Overrides Sub CreateSegments() 
        Segments.Clear() 
  
        If Segments.Count = 0 Then '60 
  
            ……… 
            GetType(ChartSeriesBase).GetProperty("DataCount", BindingFlags.GetProperty Or BindingFlags.Instance Or BindingFlags.Public).SetValue(Me, YValues.Count) 
        End If 
  
    End Sub 
  
    Protected Overrides Sub ClearUnUsedSegments(startIndex As Integer) 
    End Sub 
  
  
Note: You have set series rendering values (XValues and YValues) alone in sample level. So, the interactive features like Tooltip, Trackball, Adornments and ChartSelectionBehavior aren’t active for this series. 
  
We have modified the sample based on your requirement and you can download the sample from the below link. 
  
  
Please let us know if need any further assistance on this. 
 
Regards, 
Hemalatha M. 
 


Tom
Replied On December 18, 2019 04:05 PM UTC

Thank you so much. Setting the series data now works, and is also very fast. However, there are 2 issues remaining.

Issue 1: The CreateSegments method is called quite often when scrolling the chart. Every time, the segment is re-created, which takes 25-35 ms, which I want to avoid. Originally this was solved by checking the number of segments, and only creating a new segment if there are zero segments. For example, run the sample, create data, click the 1 day zoom button and scroll the chart by dragging the chart area with the mouse. You'll notice that the CreateSegments method is called often and re-creating the segment every time, which is unnecessary. This can also be seen by checking the immediate window. How can this be prevented?

Issue 2: I will use a crosshair behaviour with the chart to display the y-axis value of the cursor position. This seems to work fine with the GenerateLabel method in the ChartCrossHairBehaviorEx class. However, I also want to display the date and value for the datapoint the cursor is over, which can be found if the nearest chart point can be extracted, and use the resulting x value (converted to int) as the index for the original data source of the series. However, the line

chart.Series(0).FindNearestChartPoint(New Point(point.X, point.Y), xystackedYValue)

fails with an exception. How can the nearest datapoint be found?

Attached is an updated sample, with the crosshairbehaviour.

Thank you.



Attachment: 149997_FastStepLine11986090992_ce8f21a9.rar

Hemalatha Marikumar [Syncfusion]
Replied On December 19, 2019 12:30 PM UTC

Hi Tom, 
  
Thanks for the update. 
  
Query1:.How can this be prevented the recreation of segment. 
  
You can resolve this by calling SetRange with the help of reflection in the FastSteplineBitmapSeriesClipExt class and removing the Segments.Clear method as per in the below code snippet.  
 
Code Snippet [ FastSteplineBitmapSeriesClipExt] 
  
Public Overrides Sub CreateSegments() 
       Segments.Clear();'Remove this code 
        ……. 
       Dim method As MethodInfo = GetType(FastStepLineBitmapSegment).GetMethod("SetRange", BindingFlags.NonPublic Or BindingFlags.Instance) 
       method.Invoke(customSegment, Nothing) 
        ….. 
  
    End Sub 
  
  
Query2: chart.Series(0).FindNearestChartPoint(New Point(point.X, point.Y), x, y, stackedYValue) 
fails with an exception. How can the nearest datapoint be found? 
  
You can resolve this issue by setting the values for ActualSeriesYValues property in ChartSeriesBase as per the below code snippet. 
  
Code Snippet [ FastSteplineBitmapSeriesClipExt] 
  
Public Overrides Sub CreateSegments() 
  
         …… 
            Dim seriesYValues As IList(Of Double)() = New IList(Of Double)() {YValues} 
  
            GetType(ChartSeriesBase).GetProperty("ActualSeriesYValues", BindingFlags.GetProperty Or BindingFlags.Instance Or BindingFlags.NonPublic).SetValue(Me, seriesYValues) 
    
        ….. 
  
    End Sub 
  
And we have modified a sample and you can download the sample from the below link. 
  
 
Please let us know if you have any other concern. 
 
Regards, 
Hemalatha M. 


Tom
Replied On December 20, 2019 04:20 PM UTC

The issues have been resolved, with good performance. Thank you for excellent service.

Hemalatha Marikumar [Syncfusion]
Replied On December 23, 2019 06:05 AM UTC

Hi Tom, 
 
Thanks for your update. 
 
We are glad to hear that given solution works.  
 
Please let us know if you need any further assistance. 
 
Regards, 
Hemalatha M. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon