Core Plot- How can we change the x Axis class length without changing the data plot values
Well i tried to manage this issue passing the NSTimeInterval(double) values. But let say
X: May 01 2010 01:03:55 PM Y:32
X: May 05 2010 07:02:55 PM Y:20 Now, if try to display the day wise its shows the accurate results. My code snippet isxRange=[CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(min) length:CPDecimalFromFlo开发者_如何学Cat(maxValue-min)];
xClassLength=[[NSString alloc]initWithFormat:@"%f",length]; //length=1
//here the max & min values are NSTimeInterval
CPXYAxis *x2 = [[(CPXYAxis *)[CPXYAxis alloc] initWithFrame:CGRectZero] autorelease];
x2.labelingPolicy = CPAxisLabelingPolicyAutomatic;
x2.orthogonalCoordinateDecimal=CPDecimalFromInteger(startPointY);
x2.minorTicksPerInterval = 0;
x2.majorTickLength=[xClassLength intValue];
x2.preferredNumberOfMajorTicks = 5;
x2.labelOffset = 10.0;
x2.coordinate = CPCoordinateX;
x2.plotSpace = graph.defaultPlotSpace;
x2.axisLineStyle = redLineStyle;
x2.majorTickLineStyle = redLineStyle;
x2.labelingPolicy=CPAxisLabelingPolicyAutomatic;
CPTimeFormatter *timeFormatter = [[[CPTimeFormatter alloc] initWithDateFormatter:xDateFormatter] autorelease];
timeFormatter.referenceDate = refDate; //refDate=May 01 2010 12:00 PM
x2.labelFormatter=timeFormatter;
x2.labelTextStyle=axisTitleTextStyle;
x2.visibleRange =xRange;
CPConstraints x2Constraints = {CPConstraintFixed, CPConstraintNone};
x2.isFloatingAxis = YES;
x2.constraints = x2Constraints;
//End of code Well here i get confused , that if i want to show the same data but with different the X class-length; let say 3 hrs. Where I should make the changes. Please guide me for the same. Regards Zahur.
I know its pretty old post. Still, this may help some one or the other. You can always change the X axis length by changing the plot range. This is well explained in the CPTestApp-iPhone-SpeedTest which is present in the examples of CorePlot.
By, changing the values for the length of the axis, we can see the same graph in more detail manner or the other way around.
CPXYPlotSpace *plotSpace = (CPXYPlotSpace *)graph.defaultPlotSpace;
float ylen = NUM_POINTS*(rand()/(float)RAND_MAX) ;
plotSpace.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(0.0) length:CPDecimalFromFloat(NUM_POINTS)];
plotSpace.yRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(0.0) length:CPDecimalFromFloat(ylen)];
Hope, this helps.
精彩评论