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
- Holger Schlüter asked 5 years ago
- last edited 5 years ago
- You must login to post comments
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));
}
}
}
- John Flemmer answered 5 years ago
- That is a hack lol – but it’s given me an idea. We could have a callback or event on DataSeries called OnAttached… I’ll float it to the team
- Thanks. But this post (https://www.scichart.com/questions/question/zoomextents-on-mvvm) led me to a more clean solution by using a Dispatcher with DispatcherPriority.Render.
- You must login to post comments
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
- Andrew Burnett-Thompson answered 5 years ago
- I have changed my question to reflect your answer.
- 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 login to post comments
Please login first to submit.