This is a migrated thread and some comments may be shown as answers.

[Solved] Running code after vertical axis automatically adjusts

3 Answers 81 Views
Chart for XAML
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Chris
Top achievements
Rank 1
Chris asked on 22 Apr 2013, 04:12 AM
I am looking for a way to run some code when a vertical axis (which does not have an explicitly specified min and max value) adjusts itself due to new data points in a series.

Specifically, I have a chart with a single series, and that series is bound to at ObservableCollection (although it looks like the ItemsSource of the chart is actually IEnumerable, so I question how accurately it will reflect changes to the collection as they happed, but that's perhaps an independent issue). I also have a linear gradient background brush set on the plot area which indicates out-of-range values on the high and\or low end of the range. When the actual display range of the vertical axis changes based on the data points in the series, I need to adjust the gradient stops in this brush so that they accurately indicate the new range.

I don't see an event on the vertical axis indicating "range changed". I could adjust the values in the brush whenever I know the underlying collection changed in the assumption that it changed the range of the axis, but I don't know when (or if) the axis changes based on the new values (so I could end up operating on the old values if I do things at the wrong time).

Anybody have any ideas?

-Chris

3 Answers, 1 is accepted

Sort by
0
Accepted
Ivaylo Gergov
Telerik team
answered on 24 Apr 2013, 07:57 AM
Hello Chris,

Thank you for contacting us.

At this moment I must confirm that there is no easy way to track the changes in the Vertical Axis and I have logged it as a feature request. For now, what I can suggest you is to keep in a variable the current ActualRange before modifying the Series.ItemsSource. Then you can handle the DataBindingComplete event and run asynchronously (using the Windows.UI.Core.Dispatcher) a method which gets the new value of the Axis.ActualRange and check if it is different from the previous one.
Here's an example where I track the ActualRange.Maximum property:

double previousMax;
double newMax;
Before modifying the ItemsSource:
previousMax = (this.Chart.Series[0].VerticalAxis as LinearAxis).ActualRange.Maximum;
Here's the handler for Series.DataBindingComplete event:
private void LineSeries_DataBindingComplete_1(object sender, EventArgs e)
{
    var axis = ((sender as LineSeries).VerticalAxis as LinearAxis);
  
    this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
    {
         newMax = axis.ActualRange.Maximum;
         if (previousMax != newMax)
         {
            //put your logic here
         }
   
         
    });
     
}

I hope this helps. I have also updated your Telerik points for your valuable feedback.


Greetings,
Ivaylo Gergov
the Telerik team
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
0
Chris
Top achievements
Rank 1
answered on 24 Apr 2013, 06:34 PM
Thanks for the answer. I should be able to modify this idea enough to plug into my architecture.

It would also be great if the horizontal Axis fired similar "range changed" events for pan\zoom behaviors to reflect the actual range of the visible portion of the axis. I have different datapoint templates (verbose large vs brief small) based on number of points actually visible vs the size of the plot area, and currently the only way I have found to handle pans\zooms on the X axis is performing logic similar to your example when whenever the layout code on the horizontal axis runs.
0
Ivaylo Gergov
Telerik team
answered on 29 Apr 2013, 04:32 PM
Hello Chris,

Thank you for elaborating on this.

We will forward your feedback to our developers for further consideration. Currently you should be able to track the pan/zoom changes via the changes in the RadCartesianChart.Zoom / ScrollOffset dependency properties.


I hope this helps.

 

Regards,
Ivaylo Gergov
the Telerik team
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
Tags
Chart for XAML
Asked by
Chris
Top achievements
Rank 1
Answers by
Ivaylo Gergov
Telerik team
Chris
Top achievements
Rank 1
Share this question
or