Pre loader

ZoomOut in SciChartSurface.Rendered

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 would like to ZoomOut immedeatly after new data is rendered.
I would like to have flexibility in Zooming Out, therefore I cannot use AutoRange.Always.
I have implemented ZoomOut in SciChartSurface.Rendered, but that seems to be too early, as it doesnt react on the new data, instead zooms out based on the old data.
I have to wait 100 ms, then it works and it zooms out based on the new data.
Is there an event even after SciChartSurface.Rendered that is better suited to call the ZoomOut function?

I have used the technique described in the answer below. However, I am awaiting the dataChange and then call ZoomOut. It still doesnt work.

In my Code behind:

            await viewModel.DisplayData();
            viewModel.ZoomOut();

DisplayData adds LineRenderableSeriesViewModel with DataSeries to the RenderableSeries Observable Collection.

And in my ViewModel:

    internal void ZoomOut()
    {
        if (RenderableSeries.Count() > 0)
        {
            var parentSurface = ((LineRenderableSeriesViewModel)RenderableSeries.ElementAt(0)).DataSeries.ParentSurface;
            var viewportManager = parentSurface.ViewportManager;
            viewportManager.BeginInvoke(() =>
                {
                    viewportManager.AnimateZoomExtents(TimeSpan.FromMilliseconds(250));
                });

        }
    }

This way it works:

            await viewModel.DisplayData();
            await Task.Run(()=>System.Threading.Thread.Sleep(TimeSpan.FromMilliseconds(500)));
            viewModel.ZoomOut();

But that can’t be the solution – I need an event that fires when all the data is known to sciChartSurface.

Thanks,
Holger

Version
newest
  • You must to post comments
1
1

Not enough info here to fully understand the problem. However, some observations.

1.) SciChartSurface.Rendered fires whenever the chart is rendered. This could be resized, mouse-move with a tooltip, data changed, property changed, anything. If you zoom when rendered then you’ll zoom + render in a loop because zoom triggers render.

2.) If you change data in a DataSeries in a ViewModel then immediately try to zoom to fit, there will be some latency as WPF has not evaluated the bindings yet. To workaround this you can use this technique.

Best regards,
Andrew

  • Holger Schlüter
    I have changed my question to reflect your answer.
  • Andrew Burnett-Thompson
    Got it. There is no such event sadly. DataSeries.DataSeriesChanged is fired by DataSeries when its data changes, not when a chart has drawn with its data. I will have to have a think about how best to do this. Until then the best workaround I’m afraid is the one you have.
  • You must to post comments
2
1

Hacked, but working very nice without fixed delay:

async Task ZoomOutDelayed()
{
    if (RenderableSeries.Count() > 0)
    {
        SciChart.Charting.Visuals.ISciChartSurface parentSurface = null;
        //While parentSurface is null
        var task = Task.Run(() =>
        {
            while (parentSurface == null)
            {
                parentSurface = ((LineRenderableSeriesViewModel)RenderableSeries.ElementAt(0)).DataSeries.ParentSurface;
            }
        });
        //Wait until timeout
        if (await Task.WhenAny(task, Task.Delay(2000)) == task)
        {
            parentSurface.ViewportManager.AnimateZoomExtents(TimeSpan.FromMilliseconds(250));
        }
    }
}
  • You must to post comments
Showing 2 results
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