I’ve been trying a few ways to get this to work now and I’m still struggling to get a catch-all solution.
My requirements are:
– self-scrolling real-time data series with a fixed-time range (regardless of the number of points)
– y axis should support either fixed or automatic visual range
– support rubber band zoom (and ideally mousewheel too) on both axes
The key problem is that the stock ticker example doesn’t have a fixed time width. The points are added to the chart, and the axis expands until it reaches capacity. It’s also relatively easy to use FifoCapacity (adding a lot of NaN points), but FifoCapacity works on number of points, which isn’t great when you have irregular updates. I’m happy with the chart not scrolling until a new update is received, but the range of the chart must be fixed (say, five minutes), regardless of the number of visible points on the chart.
My current solution involves deriving from XyDataSeries to duplicate the FifoCapacity behaviour for a fixed time:
public class RealTimeXyDataSeries<T> : XyDataSeries<DateTime, T>
where T : IComparable
{
public TimeSpan _limit;
public TimeSpan Limit
{
get { return _limit; }
set
{
_limit = value;
Update();
}
}
public RealTimeXyDataSeries(TimeSpan limit)
{
Limit = limit;
}
public override void Append(DateTime x, T y)
{
base.Append(x, y);
Update();
}
public void Update()
{
if ((DateTime)XMax == DateTime.MinValue) return;
var c = 0;
while (XValues[c] < (DateTime) XMax - Limit) c++;
if (c <= 0) return;
RemoveRange(0, c);
}
}
That takes care of removing points, but doesn’t deal with the range issue. To deal with that, I have some code in my codebehind to set the XAxis VisibleRange on every update, which feels a bit nasty. I wanted to create a RealTimeDateTimeAxis, but none of the relevant functions are override/virtual.
I also took the implementation of RubberBandXyZoomModifierEx from the knowledge base, with some modifications to deal with Y-Axis zoom/reset based on it’s AutoRange setting. However, this involves setting the Y-Axis AutoRange state back to a saved value, and I keep seeing MouseModifierUp events after my DoubleClick events, which resets AutoRange back to Never.
It feels like I’m doing a lot of work in a lot of places to get this to work, and it’s resulting in complex code and buggy behaviours; I’m not comfortable handing this over to another engineer in the current state.
Is there a better way to do this?
- Rick C asked 8 years ago
- You must login to post comments
Hi Rick
Have you also seen our tutorial (which is new!) Adding Realtime Updates.
This presents a way to have realtime + zoom working at the same time as autorange.
Also the final Tutorial Linking Multiple Charts shows how to put it all together with two charts, rollovers, annotations, realtime ranging and mouse-zooming.
Best regards,
Andrew
- Andrew Burnett-Thompson answered 8 years ago
-
Brilliant!
- You must login to post comments
Oh, wait, I just found this: http://support.scichart.com/index.php?/Knowledgebase/Article/View/17223/37/how-to-have-a-fixed-scrolling-time-range-on-the-xaxis-that-works-with-modifiers
Let’s see how this plays out…
- Rick C answered 8 years ago
-
Okay so this sort of seems to handle some questions, but it doesn’t solve the duplicated mouse events issue. This issue also has ramifications for setting the ParentSurface.ZoomState property; it keeps being reset back to UserZooming.
- You must login to post comments
Please login first to submit.