SciChart iOS v2.x API > Axis APIs > Axis Ranging - Setting and Getting VisibleRange
Axis Ranging - Setting and Getting VisibleRange

How to Modify VisibleRange for different Axis Types

To programmatically range an axis, set the property SCIAxisCore.visibleRange.

The type of object to apply to the Axis VisibleRange changes depending on the axis type. Please see the examples below for guidance:

// 1.) SCINumericAxis
// SCINumericAxis  accepts types Double, Int, Long, Float, Short for data and SCIDoubleRange for VisibleRange.
// SCIGeneric is used to marshal between iOS types and faster SciChart primitive types
SCINumericAxis * xAxis = [[SCINumericAxis alloc] init];
[xAxis setVisibleRange: [[SCIDoubleRange alloc]initWithMin:SCIGeneric(0.0) Max:SCIGeneric(100.0)]];

// 2.) SCIDateTimeAxis
// SCIDateTimeAxis accepts type DateTime for data and SCIDateRange for VisibleRange.
// SCIGeneric is used to marshal between iOS types and faster SciChart primitive types
SCIDateTimeAxis * xAxis = [[SCIDateTimeAxis alloc] init];
NSDate * minXRange = [[NSDate alloc] init];
NSDate * maxXRange = [minXRange dateByAddingTimeInterval: 86400];
[xAxis setVisibleRange: [[SCIDateRange alloc]initWithDateMin:minXRange Max:maxXRange]];

// 3.) SCILogarithmicNumericAxis
// SCILogarithmicNumericAxis accepts types Double, Int, Long, Float, Short for data and SCIDoubleRange for VisibleRange.
// SCIGeneric is used to marshal between iOS types and faster SciChart primitive types
// Note that both Min and Max visible range must be the same sign. Zero values are not allowed
SCILogarithmicNumericAxis * yAxis = [[SCILogarithmicNumericAxis alloc] init];
[yAxis setVisibleRange: [[SCIDoubleRange alloc]initWithMin:SCIGeneric(0.001) Max:SCIGeneric(100.0)]];

// 4.) SCICategoryDateTimeAxis
// SCICategoryDateTimeAxis accepts type DateTime for data
// and SCIIndexRange for VisibleRange (specifyng the index to the data)
// SCIGeneric is used to marshal between iOS types and faster SciChart primitive types
SCICategoryDateTimeAxis * xAxis = [[SCICategoryDateTimeAxis alloc] init];
[xAxis setVisibleRange: [[SCIIndexRange alloc]initWithMin:SCIGeneric(0) Max:SCIGeneric(100)]];

// 5.) SCICategoryNumericAxisaccepts
// SCICategoryNumericAxisaccepts type Double, Long, Int, Float for data
// and SCIIndexRange for VisibleRange (specifyng the index to the data)
// SCIGeneric is used to marshal between iOS types and faster SciChart primitive types
SCICategoryNumericAxis* xAxis = [[SCICategoryNumericAxis alloc] init];
[xAxis setVisibleRange: [[SCIIndexRange alloc]initWithMin:SCIGeneric(0) Max:SCIGeneric(100)]];
// 1.) SCINumericAxis
// SCINumericAxis  accepts types Double, Int, Long, Float, Short for data and SCIDoubleRange for VisibleRange.
// SCIGeneric is used to marshal between iOS types and faster SciChart primitive types
var xAxis = SCINumericAxis()
xAxis.visibleRange = SCIDoubleRange(min: SCIGeneric(0.0), max: SCIGeneric(100.0))

// 2.) SCIDateTimeAxis
//  SCIDateTimeAxis accepts type DateTime for data and SCIDateRange for VisibleRange.
// SCIGeneric is used to marshal between iOS types and faster SciChart primitive types
var xAxis = SCIDateTimeAxis()
var minXRange = Date()
var maxXRange = minXRange.addingTimeInterval(86400) as? Date
xAxis.visibleRange = SCIDateRange(dateMin: minXRange, max: maxXRange)

// 3.) SCILogarithmicNumericAxis
// SCILogarithmicNumericAxis accepts types Double, Int, Long, Float, Short for data and SCIDoubleRange for VisibleRange.
// SCIGeneric is used to marshal between iOS types and faster SciChart primitive types
// Note that both Min and Max visible range must be the same sign. Zero values are not allowed
var yAxis = SCILogarithmicNumericAxis()
yAxis.visibleRange = SCIDoubleRange(min: SCIGeneric(0.001), max: SCIGeneric(100.0))

// 4.) SCICategoryDateTimeAxis
// SCICategoryDateTimeAxis accepts type DateTime for data
// and SCIIndexRange for VisibleRange (specifyng the index to the data)
// SCIGeneric is used to marshal between iOS types and faster SciChart primitive types
var xAxis = SCICategoryDateTimeAxis()
xAxis.visibleRange = SCIIndexRange(min: SCIGeneric(0), max: SCIGeneric(100))

// 5.) SCICategoryNumericAxisaccepts
// SCICategoryNumericAxisaccepts type Double, Long, Int, Float for data
// and SCIIndexRange for VisibleRange (specifyng the index to the data)
// SCIGeneric is used to marshal between iOS types and faster SciChart primitive types
var xAxis = SCICategoryNumericAxis()
xAxis.visibleRange = SCIIndexRange(min: SCIGeneric(0), max: SCIGeneric(100))
// 1.) SCINumericAxis
// SCINumericAxis  accepts types Double, Int, Long, Float, Short for data and SCIDoubleRange for VisibleRange.
// SCIGeneric is used to marshal between iOS types and faster SciChart primitive types
var xAxis = new SCINumericAxis();
xAxis.VisibleRange = new SCIDoubleRange(0, 100.0);

// 2.) SCIDateTimeAxis
//  SCIDateTimeAxis accepts type DateTime for data and SCIDateRange for VisibleRange.
// SCIGeneric is used to marshal between iOS types and faster SciChart primitive types
var xAxis = new SCIDateTimeAxis();           
xAxis.VisibleRange = new SCIDateRange(DateTime.Now, DateTime.Now.AddDays(1));

// 3.) SCILogarithmicNumericAxis
// SCILogarithmicNumericAxis accepts types Double, Int, Long, Float, Short for data and SCIDoubleRange for VisibleRange.
// SCIGeneric is used to marshal between iOS types and faster SciChart primitive types
// Note that both Min and Max visible range must be the same sign. Zero values are not allowed
var yAxis = new SCILogarithmicNumericAxis();
yAxis.VisibleRange = new SCIDoubleRange(0.001, 100.0);

// 4.) SCICategoryDateTimeAxis
// SCICategoryDateTimeAxis accepts type DateTime for data
// and SCIIndexRange for VisibleRange (specifyng the index to the data)
// SCIGeneric is used to marshal between iOS types and faster SciChart primitive types
var xAxis = new SCICategoryDateTimeAxis();
xAxis.VisibleRange = new SCIIndexRange(0, 100);

// 5.) SCICategoryNumericAxis
// SCICategoryNumericAxis accepts type Double, Long, Int, Float for data
// and SCIIndexRange for VisibleRange (specifyng the index to the data)
// SCIGeneric is used to marshal between iOS types and faster SciChart primitive types
var xAxis = new SCICategoryNumericAxis();
xAxis.VisibleRange = new SCIIndexRange(0, 100);

 

Getting Axis VisibleRange for different Axis types

All Axis.VisibleRange objects are of type SCIRangeProtocol. If you wish to do some manipulations on these ranges (such as calculations, etc..) you will need to convert them to the desired type.

NOTE: For info on usage of the SCIGenericType macro please see the article SCIGenericType, SCIGenericDouble and SCIGenericDate.

 

// 1.) NumericAxis or LogarithmicNumericAxis: VisibleRange is of type SCIDoubleRange
// and contains double values
SCINumericAxis * numericAxis = [[SCINumericAxis alloc] init];
SCIDoubleRange * visibleRange = (SCIDoubleRange*) [numericAxis visibleRange];
double max = SCIGenericDouble(visibleRange.Max);
double min = SCIGenericDouble(visibleRange.Min);

// 2.) DateTimeAxis: VisibleRange is of type SCIDateRange and contains NSDate values
SCIDateTimeAxis * dateTimeAxis = [[SCIDateTimeAxis alloc] init];
SCIDateRange * visibleRange = (SCIDateRange *) [dateTimeAxis visibleRange];
NSDate * max = SCIGenericDate(visibleRange.Max);
NSDate * min = SCIGenericDate(visibleRange.Min);

// 3.) CategoryDateTimeAxis or CategoryNumericAxis: VisibleRange is of type SCIIndexRange and contains
// integer indices to the data
SCICategoryDateTimeAxis * categoryAxis = [[SCICategoryDateTimeAxis alloc] init];
SCIIndexRange * visibleRange = (SCIIndexRange *) [categoryAxis visibleRange];
int max = SCIGenericInt(visibleRange.Max);
int min = SCIGenericInt(visibleRange.Min);
// 1.) NumericAxis or LogarithmicNumericAxis: VisibleRange is of type SCIDoubleRange
// and contains double values
var numericAxis = SCINumericAxis()
var visibleRange = numericAxis.visibleRange() as? SCIDoubleRange
var max = SCIGenericDouble(visibleRange?.max)
var min = SCIGenericDouble(visibleRange?.min)

// 2.) DateTimeAxis: VisibleRange is of type SCIDateRange and contains NSDate values
var dateTimeAxis = SCIDateTimeAxis()
var visibleRange = dateTimeAxis.visibleRange() as? SCIDateRange
var max = SCIGenericDate(visibleRange?.max)
var min = SCIGenericDate(visibleRange?.min)

// 3.) CategoryDateTimeAxis or CategoryNumericAxis: VisibleRange is of type SCIIndexRange and contains
// integer indices to the data
var categoryAxis = SCICategoryDateTimeAxis()
var visibleRange = categoryAxis.visibleRange() as? SCIIndexRange
var max = SCIGenericInt(visibleRange?.max)
var min = SCIGenericInt(visibleRange?.min)
// 1.) NumericAxis or LogarithmicNumericAxis: VisibleRange is of type SCIDoubleRange
// and contains double values
var numericAxis = new SCINumericAxis();
var visibleRange = numericAxis.VisibleRange;
double max = visibleRange.Max_native.doubleData;
double min = visibleRange.Min_native.doubleData;


// 2.) DateTimeAxis: VisibleRange is of type SCIDateRange and contains DateTime values
var numericAxis = new SCIDateTimeAxis();
var visibleRange = numericAxis.VisibleRange;
DateTime max = visibleRange.Max_native.dateTimeData;
DateTime min = visibleRange.Min_native.dateTimeData;

// 3.) CategoryDateTimeAxis or CategoryNumericAxis: VisibleRange is of type SCIIndexRange and contains
// integer indices to the data
var numericAxis = new SCICategoryDateTimeAxis();
var visibleRange = numericAxis.VisibleRange;
int max = visibleRange.Max_native.intData;
int min = visibleRange.Min_native.intData;

 

Once you have the Min, Max values you can now manipulate them and apply ranges programmatically to the axis.

See Also