Page 1 of 1

Trading Chart Time Range Selection: Click Notifications?

Posted: Thu Oct 15, 2020 9:09 pm
by JeffFerguson
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?

Re: Trading Chart Time Range Selection: Click Notifications?

Posted: Fri Oct 16, 2020 8:50 am
by Arction_LasseP
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,
Lasse