Pre loader

Inserting previous data + keeping position

Welcome to the SciChart Forums!

  • Please read our Question Asking Guidelines for how to format a good question
  • Some reputation is required to post answers. Get up-voted to avoid the spam filter!
  • We welcome community answers and upvotes. Every Q&A improves SciChart for everyone

WPF Forums | JavaScript Forums | Android Forums | iOS Forums

0
0

Hello,
I’m creating a chart where the x-axis are dates. I want to load more (past) data when a button is clicked or when the visible range satisfies some condition. I have been able to do that using the InsertData function with index = 0 (in order to insert in the beginning of the series), but my problem now is how to keep the position I had before inserting the new data. Right now, after the insertion, the x-axis visible range’s indexes are the same instead of being moved to the right in order to show the same part of the data as before.

I have tried different ways to modify the visible range (by moving the range taking into account the new data size) but none of them have performed well.

I would like to display the same before and after inserting the previous data, so when the user scrolls he can find more data on the left but he is shown the same range of data as before.

I’m using the CategoryDateAxis as x-axis and the NumericAxis as y-axis (you can see the configuration of those axis below). The renderable series is a FastCandlestickRenderableSeries and the data series is an OhlcDataSeries<DateTime, double>.

Btw, I’m using the Xamarin wrapper for Android.

Could you help me with this issue?

Thanks!

var yAxis = new NumericAxis(this.Context)
{
        GrowBy = new DoubleRange(0, 0.1),
        AutoRange = AutoRange.Always
};

var xAxis = new CategoryDateAxis(this.Context)
{
       GrowBy = new DoubleRange(0, 0.1),
       VisibleRange = new DoubleRange(dataCount - InitialCandlesShown, dataCount + RightCandlesMargin),
       VisibleRangeLimit = new DoubleRange(-2.0, dataCount + RightCandlesMargin),
       MinimalZoomConstrain = new Java.Lang.Double(MinimumCandlesShown)
 };
Version
2.2.0.788
  • Yura Khariton
    Hi Arnau. Can you post some code sample which shows your configuration of chart ( x and y axis, renderable series which you use, etc )? First of all I’m interested what type of axis you use as xAxis. You mentioned that you use dates but there are two types of axis which support dates ( DateAxis and CategoryDateAxis ) and you didn’t specify which one you use in your application. Thanks in advance.
  • Arnau Blanch
    Hi, I have updated the question with additional information. Thanks
  • You must to post comments
0
0

Hi Arnau,

I don’t have a code sample for you but some advice which should point you in the right direction.

The principle for the CategoryDateTimeAxis is that the axis measures the index of the data you have inserted (ignores the dates), which is useful when plotting stock charts & financial applications where price data might have gaps for overnight or weekends.

In order to preserve the range when inserting data you will need to persist and restore the indices, for example:

  1. Initial data is 100 days from 1st Jan 2018
  2. Initial XAxis.VisibleRange is IndexRange(10,30) (points 10 to 30 in the above data stream)

What you will need to do is to find the dates for points 10,30 (You can access via DataSeries.XValues[i]) and keep hold of those.

Next update your DataSeries by inserting new values.

Work out what should the new IndexRange should be to persist the Date Range on the chart. For example say you inserted 100 points to the start of the data-series, now your XAxis.VisibleRange should be IndexRange(110,130)

Actually … it becomes a lot simpler if you know you are only inserting. If you insert X points then increment XAxis.VisibleRange Min and Max by X right after adding the data.

Let me know if this helps!

Best regards,
Andrew

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.

Try SciChart Today

Start a trial and discover why we are the choice
of demanding developers worldwide

Start TrialCase Studies