[FullBindable] How to trigger View XY ZoomToFit when BarSeries Changed

A forum dedicated to WPF version of LightningChart Ultimate.

Moderator: Queue Moderators

Post Reply
UnityRT
Posts: 2
Joined: Mon Sep 12, 2016 4:05 pm

[FullBindable] How to trigger View XY ZoomToFit when BarSeries Changed

Post by UnityRT » Tue Nov 05, 2019 2:40 pm

Hello,

I am using full bindable v8.4.3 WPF Ligthing ultimate chart.

I have a "histogram like" view (barseries ViewXY chart) displayed, bind to a BarSeriesCollection VM object member. Barseries could be added,removed or modified at any time. Collection are modified within VM.

How to perform a ZoomToFit action in View each time this collection is changing ?

I have already tried to bind Minimum and Maximum from axes but the result obtain is not as fancy as a ZoomToFit action.
I also did not manage to use CollectionChanged event correctly.

Any help will be greatly appreciated.

Arction_LasseP
Posts: 141
Joined: Wed Mar 27, 2019 1:05 pm

Re: [FullBindable] How to trigger View XY ZoomToFit when BarSeries Changed

Post by Arction_LasseP » Wed Nov 06, 2019 11:27 am

Hello,

The CollectionChanged -event is usually the correct way to handle cases where a collection is changed regardless of its contents (a collection of BarSeries or some other objects not related to LightningChart work similarly). However, this event doesn't always trigger when you change a value inside your collection. Therefore you probably need to modify the event a bit. We suggest checking for example these two threads which explain pretty well how to make this to work (at least better that us trying to explain the event here):

https://stackoverflow.com/questions/142 ... notifyprop

https://stackoverflow.com/questions/849 ... em-changes


To call the ZoomToFit action in code, there are two methods:

ChartTools.ZoomToDataAndLabelsArea(_chart);

_chart.ViewXY.ZoomToFit();

It shouldn't matter which one of these you call inside the CollectionChanged -event as both of these zoom the chart similarly. However, the downside is that you need to implement some logic to access the LightningChart object (or its ViewXY) from the ViewModel in order to use them. If this is not possible, then binding the axis ranges is the way to go, for example set the Y-axis maximum to be the largest BarSeries value of the collection whenever the collection is changed.

Hope this helps.
Best regards,
Lasse

Post Reply