We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

How to stop Primary and Secondary Axis changes when zoomed

Thread ID:

Created:

Updated:

Platform:

Replies:

117239 Sep 12,2014 02:02 PM Sep 25,2014 12:14 AM WinRT 6
loading
Tags: Chart
Michael Hamilton
Asked On September 12, 2014 02:02 PM

I have a LineChart that uses the FastLineBitmapSeries and is updated with new data every 5 seconds.  My question is how do I stop the axis from being scaled for the new data when the user has the graph zoomed into a specific point.   Currently if the user zooms in and new data is added to the chart then the desired zoom position changes even though the ZoomFactor and ZoomPosition have not changed.  I want the axis to stay at its current scaling when zoomed so that the zoomed point does not move off the screen as new data is added.

Any help or hints would be great!  Thanks

Suresh S [Syncfusion]
Replied On September 16, 2014 05:07 AM

Hi Michael,


Thanks for using Syncfusion products.


We have prepared the sample based on your requirement. Please download it from the given below location.


Please let us know if you request further assistance on this.


Regards,

Suresh S


Attachment: RealtimeUpdate_2720b28f.zip

Michael Hamilton
Replied On September 17, 2014 01:36 PM

Thank you so much!

Michael Hamilton
Replied On September 18, 2014 02:58 PM

Hello,

I took the example from the previous reply and changed some things.  I wanted to throw these changes out to see if anyone thinks this is good or not.  It seems to be working but I'm still testing .  The LimitAxisZoom call just limits the value to 0 and 1.   Is this needed, or will the ZoomFactor and ZoomPosition automatically limit to 0 and 1?

private void NumericalAxis_ActualRangeChanged(object sender, Syncfusion.UI.Xaml.Charts.ActualRangeChangedEventArgs e)
{
    if (_graph != null)
    {
if (!e.IsScrolling && _graph.SecondaryAxis.ZoomFactor < 1 && _lastNumericalAxis != null)
{
   // Determine the range of the new axis
   Double newRange = (Double)e.ActualMaximum - (Double)e.ActualMinimum;

   // Determine the change for the max and min
   Double deltaMax = (Double)e.ActualMaximum - (Double)_lastNumericalAxis.ActualMaximum;
   Double deltaMin = (Double)e.ActualMinimum - (Double)_lastNumericalAxis.ActualMinimum;

   // Determine the total percent change in relation to the new range
   Double totalPercentChange = (deltaMax + deltaMin) / newRange;

   // Adjust the zoom factor based on the percent change of the total range
   _graph.SecondaryAxis.ZoomFactor = LimitAxisZoom(_graph.SecondaryAxis.ZoomFactor - (totalPercentChange * _graph.SecondaryAxis.ZoomFactor));

   // Determine the max and min percent change in relation to the new range
   Double maxPercentChange = deltaMax / newRange;
   Double minPercentChange = deltaMin / newRange;

   // Adjust the zoom position based on the max and min percent change of the total range
   _graph.SecondaryAxis.ZoomPosition =  LimitAxisZoom(_graph.SecondaryAxis.ZoomPosition + (minPercentChange * _graph.SecondaryAxis.ZoomPosition) - (maxPercentChange * _graph.SecondaryAxis.ZoomPosition));

}

// Remember for next time
_lastNumericalAxis = e;

    }
}


Michael Hamilton
Replied On September 18, 2014 06:57 PM

I think I made that way harder than it should have been.  This is my new approach and it seems to be working great for the X axis.


if (!e.IsScrolling && _graph.PrimaryAxis.ZoomFactor < 1 && _lastDateTimeAxis != null)
{
    // Determine the range of the new and old axis
    TimeSpan newRange = (DateTime)e.ActualMaximum - (DateTime)e.ActualMinimum;
    TimeSpan oldRange = (DateTime)_lastDateTimeAxis.ActualMaximum - (DateTime)_lastDateTimeAxis.ActualMinimum;

    // Adjust the zoom factor and position
    _graph.PrimaryAxis.ZoomFactor = LimitAxisZoom((_graph.PrimaryAxis.ZoomFactor * oldRange.TotalMilliseconds) / newRange.TotalMilliseconds);

    _graph.PrimaryAxis.ZoomPosition = LimitAxisZoom((_graph.PrimaryAxis.ZoomPosition * oldRange.TotalMilliseconds) / newRange.TotalMilliseconds);
}

// Remember for next time
_lastDateTimeAxis = e;


Michael Hamilton
Replied On September 19, 2014 03:22 PM

Ok, I don't think changing the ZoomFactor or ZoomPosition within the Axis_ActualRangeChanged event is working very well.  

I do have one request for a possible improvement.  That request would be to add the last ActualMinimum and last ActualMaximum to the ActualRangeChangedEventArgs class.  These would be the values that they were before the range changed.


All in all this is what I ended up with:

    if (_lastNumericalAxis != null && _graph.SecondaryAxis.ZoomFactor < 1.0)
    {
// Determine the range of the last axis and calculate the new visible minimum and maximum values
Double range = (Double)_lastNumericalAxis.ActualMaximum - (Double)_lastNumericalAxis.ActualMinimum;
Double minPosition = (Double)_lastNumericalAxis.ActualMinimum + (_graph.SecondaryAxis.ZoomPosition * range);
Double maxPosition = minPosition + (_graph.SecondaryAxis.ZoomFactor * range);

// Set the new visible minimum and maximum values
e.VisibleMinimum = minPosition;
e.VisibleMaximum = maxPosition;

    }

    // Remember for next time
    _lastNumericalAxis = new AxisRange { ActualMaximum = e.ActualMaximum, ActualMinimum = e.ActualMinimum };

Suresh S [Syncfusion]
Replied On September 25, 2014 12:14 AM

Hi Michael,


Sorry for the inconvenience caused.


Axis default ZoomPosition will be 0 and ZoomFactor is 1. Whenever chart zooming happens their limit will be changed between 0 to 1.


We have analysed your previous code snippet, we have acheived your requirement axis being scaled when adding new data. Also, we have prepared the sample based on your requirement. Please download it from the given below location.



Please let us know if you request further assistance on this.


Regards,
Suresh S

Attachment: AxisChanged_ddfcecb1.zip

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;