Pre loader

Auto ZoomExtent the chart surface when the SeriesSource is updated

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

1
0

Hi there,

I bind the SeriesSource property of the ChartSurface to an ObservableCollection in my ViewModel, the chart is updated whenever the collection is updated. This has been working OK.

The feature I want to implement is to ZoomExtent the chart surface whenever the SeriesSource is updated. Since the length of my series are different, when I switch from one series to another, the chart only displays a part of the new series if the new series is longer than the old one.

My initial attempt was creating an Eventhandler in Viewmodel and register it to the  CollectionChanged event of the ObservableCollection. Then I got stuck there.

How do I trigger the ZoomExtent function in the eventhandler?

I notice that SciChartSurface class exposes two Commands “AnimateZoomExtentsCommand” and “ZoomExtentsCommand“. Can I invoke these two commands in my event handler though some magic binding? 

Or I am on the wrong track completely? Thank you for you help.

Frank

  • You must to post comments
0
0

Hi Frank,

Thanks for the inquiry! SciChart provides several ways of achieving this, and most of them are convenient for your particular case. Here they are:

  1. ISciChartSurface.ZoomExtentsCommand/AnimateZoomExtentsCommand
  2. IDataSeries.InvalidateParentSurface(RangeMode)
  3. IViewPortManager.InvalidateParentSurface(RangeMode)
  4. ISciChartSurface.ZoomExtents()/ZoomExtentsY()/ZoomExtentsX()
  5. ZoomExtentsModifier

So I would suggest you calling IDataSeries.InvalidateParentSurface(RangeMode.ZoomToFit) in the handler, because you can easily access DataSeries inside the VM. Alternatively, you can add magic Two-way binding on SciChart’s ZoomExtentsCommand or ViewportManager to corresponding properties in the VM and use them instead.

Please, feel free to ask if you need more assistance with this.

Best regards,
Yuriy

  • keke8273
    Hi Yuriy, Thanks for the reply! I am afraid that some more assistance is indeed needed here. 1. ZoomExtents/AnimateZoomExtents Command I declared a plain CLR property named ZoomExtentsCommand in my VM public ICommand ZoomExetensCommand { get; set; } I bind the property to the ISciChartSurface.ZoomExtentsCommand in XAML, then I execute the command in the eventhandler like so private void ChartSeriesOnCollectionChanged(object sender, NotifyCollectionChangedEventArgs notifyCollectionChangedEventArgs) { ZoomExetensCommand.Execute(null); } But I got a runtime exception System.NullReferenceException indicating that the property in VM is null. Then I tried to change the ICommand property in the VM to a DP, but got the same exception. Any thoughts? 2. IDataSeries.InvalidateParentSurface(RangeMode) This is not really suitable for my application, where the user can select multiple series to plot. If user deselect a series from the selected group, I would have to find the longest remaining series and zoomExtend based on that. It doesnt seem to be a clean solution to me. 3. I implemented a boolean attached property which is attached to the SciChartSurface in XAML. When the property is set, I wanted to registere an event handler to the CollectionChanged event of the SeriesSource collection. But the SeriesSource collection is NULL. It has to be bound to the collection in my VM. Why it is null? On the other hand, the RenderableSeries is instantiated. What is the relationship between the RenderableSeries and the SeriesSource? I also found that if I register the following handler to the CollectionChanged event of the SeriesSource(via some doggy wiring), the application does exactly what I wanted to do. private static void OnDataCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e) { chartSurface.AnimateZoomExtents(TimeSpan.FromMilliseconds(500)); } Frank
  • Yuriy Zadereckiy
    Hi there, Please, check the Output window for binding errors. Also ensure that you calls ZoomExetensCommand.Execute(null) after the view is created and the binding evaluated. Try also "OneWayToSource" binding mode. Regarding the SeriesSource property, it seems to me you don't need that attached property, you should subscribe to CollectionChanged of the collection you creates in the VM. SeriesSource is null probably because of wrong binding. RenderableSeries collection is filled by series which originates from SeriesSource. We have many examples which uses SeriesSource, here is one of them: RealTime ticking StockChart. Hope this helps! Best regards, Yuriy
  • keke8273
    Thank you Yuriy. I have to say my clients are very impressed with the performance of SciChart. I have a question regarding the license. If I buy one copy of the license, can I generated unlimited number of application that reference to your dll? Thanks Frank
  • Yuriy Zadereckiy
    Hi Frank, Sorry for the delay in answering! It's great news that your clients are pleased by our charts! So don't hesitate to ask if any further questions arise during evaluation/development, either here or by email - we are always glad to help :) ..and you could find more info on licensing topic here. As you can learn from this document, SciChart is licensed as a per-developer, perpetual, royalty free license, therefore as long as you purchase one license for each developer who debugs the code, you are free to redistribute as many applications that reference SciChart at runtime. Best regards, Yuriy
  • 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