SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, and iOS Chart & Android Chart Components

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
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
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
    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
Showing 2 results
Your Answer

Please first to submit.