Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
232 views
in Technique[技术] by (71.8m points)

graph - how to plot months of the year on x-axis using core plot in iphone

how to plot months of the year on x-axis using core plot and on y-axis i need multiples of 200 morever this data i used to get from an excel sheet.can anyone help me out from this. Thanks in advance....

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Here is some sample code taken from a recent project. My x-axis data was an array of NSDates. I set up my axisSet as normal, and then added the following code below:

axisSet.xAxis.labelingPolicy = CPTAxisLabelingPolicyNone;

NSMutableArray *countingXPoints=[[NSMutableArray alloc] init];
NSMutableArray *datesAsStrings=[[NSMutableArray alloc] init];

NSDateFormatter *df=[[NSDateFormatter alloc] init];
[df setDateFormat:@"MM-yy"];

for(int i=0; i<[self.xAxisData count]; i++)
{
    [countingXPoints addObject:[NSNumber numberWithInt:i]];
    [datesAsStrings addObject:[df stringFromDate:[self.xAxisData objectAtIndex:i]]];
}

NSArray *xCustomTickLocations = [NSArray arrayWithArray:(NSArray *)countingXPoints];
NSArray *xAxisLabels = [NSArray arrayWithArray:(NSArray *) datesAsStrings];
NSUInteger xLabelLocation = 0;
NSMutableArray *xCustomLabels = [[NSMutableArray alloc] initWithCapacity:[xAxisLabels count]];
for (NSNumber *xTickLocation in xCustomTickLocations)
{
    CPTAxisLabel *newXLabel = [[CPTAxisLabel alloc] initWithText: [xAxisLabels objectAtIndex:xLabelLocation++] textStyle:axisSet.xAxis.labelTextStyle];

    newXLabel.tickLocation = [xTickLocation decimalValue];
    newXLabel.offset = 0.0f;
    newXLabel.rotation = M_PI/4.0;
    [xCustomLabels addObject:newXLabel];
}

axisSet.xAxis.axisLabels=[NSSet setWithArray:xCustomLabels];

For the y-axis part of your question, you can adjust the tick intervals (attributes of CPTXYAxis). To achieve the correct axis height/length, take a look at the xRange, yRange, globalXRange, and globalYRance attributes of your plotspace.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...