Trading Chart Time Range Selection: Click Notifications?

A forum dedicated to WPF version of LightningChart Ultimate.

Moderator: Arction_LasseP

User avatar
Posts: 9
Joined: Wed Oct 07, 2020 1:25 am

Trading Chart Time Range Selection: Click Notifications?

Post by JeffFerguson » Thu Oct 15, 2020 9:09 pm

I have a Trading Chart instance with ShowTimeRangeSelection set to true. Is there any way to be notified when one of those buttons are clicked? Alternatively, is there any way to be notified when the visible time range changes on the chart? How can I find out, for example, when the Trading Chart moves from displaying one year of data to three months of data?

Posts: 105
Joined: Wed Mar 27, 2019 1:05 pm

Re: Trading Chart Time Range Selection: Click Notifications?

Post by Arction_LasseP » Fri Oct 16, 2020 8:50 am

Hello Jeff,

Currently, the easiest way to do this is to subscribe to RangeChanged -event for the internal X-axis. As the name implies, this event triggers when you change the axis range, also when using the time range buttons. Inside the event you can do whatever you like, for instance check the current time range via GetTimeRange() as in the following example.

Code: Select all

_chart.GetInternalChart().ViewXY.XAxes[0].RangeChanged += Xaxis_RangeChanged;

        private void Xaxis_RangeChanged(object sender, Arction.Wpf.Charting.Axes.RangeChangedEventArgs e)
            DateTime start, end;
            _chart.GetTimeRange(out start, out end);
Getting a notification when a time range button is clicked is a bit trickier. Technically you need to subscribe to Click event for the buttons. To do this you would have to find all the buttons for example via VisualTreeHelper.GetChild method. The time range buttons themselves are actually custom buttons called ToggleButtons. There is also a method called GetAllRangeButtons() but it is currently only used internally. If you have source code, you could change that to public method and subscribe to Click easily via that (we might also do that in the next release as well).

Hope this is helpful.
Best regards,