Reputation: 176
How can i create dynamic y axis by only passing yMin and yMax graph plot automatically and display very clear.
For Example my Data is for Y axis 99.7, 99.3, 99.2, 99.0 ,100 .
so i want to y axis min start from 99 to 100 with 0.1 increment by which graph will display very clear.
my code snippet is bellow // 4 - Configre the y-axis
y_monthly.title = lbl_M_HasDelay.text;
y_monthly.labelAlignment = CPTAlignmentCenter;
y_monthly.titleTextStyle = axisTitleStyle;
y_monthly.titleOffset = -30.0f;
y_monthly.axisLineStyle = axisLineStyle;
y_monthly.majorGridLineStyle = gridLineStyle;
y_monthly.labelingPolicy = CPTAxisLabelingPolicyNone;
y_monthly.labelTextStyle = axisTextStyle;
y_monthly.labelOffset = 16.0f;
y_monthly.majorTickLineStyle = axisLineStyle;
y_monthly.majorTickLength = 4.0f;
y_monthly.minorTickLength = 2.0f;
y_monthly.tickDirection = CPTSignPositive;
NSMutableSet *yLabels = [NSMutableSet set];
NSMutableSet *yMajorLocations = [NSMutableSet set];
NSMutableSet *yMinorLocations = [NSMutableSet set];
float minorIncrement=month_MaxY1/10;
float majorIncrement = minorIncrement*2;
float yMax = month_MaxY1;
for (float j = minorIncrement; j <= yMax; j += minorIncrement)
{
float mod = fmodf(j, majorIncrement);
if (mod == 0) {
CPTAxisLabel *label = [[CPTAxisLabel alloc] initWithText:[NSString stringWithFormat:@""]textStyle:y_monthly.labelTextStyle];
[label setAlignment:CPTAlignmentTop];
NSDecimal location = CPTDecimalFromFloat(j);
label.tickLocation = location;
label.offset = -y_monthly.majorTickLength - y_monthly.labelOffset;
if (label) {
[yLabels addObject:label];
}
[yMajorLocations addObject:[NSDecimalNumber decimalNumberWithDecimal:location]];
} else {
[yMinorLocations addObject:[NSDecimalNumber decimalNumberWithDecimal:CPTDecimalFromFloat(j)]];
}
}
y_monthly.axisLabels = yLabels;
y_monthly.majorTickLocations = yMajorLocations;
y_monthly.minorTickLocations = yMinorLocations;
where month_MaxY1 =100 , and month_MinY1 =90.0. Please help me
Upvotes: 2
Views: 1166
Reputation: 27381
Set the range of the y-axis using the plot space:
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(99.0)
length:CPTDecimalFromDouble(1.0)];
Label the axis:
y_monthly.labelingPolicy = CPTAxisLabelingPolicyFixedInterval;
y_monthly.majorIntervalLength = CPTDecimalFromDouble(0.1);
This will make ticks and labels every 0.1 unit along the y-axis. Set the labelFormatter
and labelTextStyle
to control the appearance of the labels.
Upvotes: 2
Reputation: 100581
I guess your problem is to make your X axis to be displayed at the yMin position of your graph. What you need to do is:
x_axis.orthogonalCoordinateDecimal = CPTDecimalFromDouble(yMin);
Upvotes: 1