我有这样的数据
(@"jan", @"feb", @"mar", @"apr", @"may", @"jun", @"jul", @"aug", @"sep", @"oct", @"nov", @"dec")
我需要将以下数据添加到 x轴,间隔为2。
`( @"jan", @"mar", @"may", , @"jul", @"sep", @"nov")`
如何在核心情节折线图中实现这一目标。
答案 0 :(得分:0)
我得到了解决方案
`NSMutableArray *monthLabelset = [[NSMutableArray alloc]init];
NSMutableArray *monthsDataset = [[NSMutableArray alloc]init];
NSArray *months = [[NSArray alloc]initWithObjects:@"jan",@"feb",@"mar",@"apr",@"may",@"jun",@"jul",@"aug",@"sep",@"oct",@"nov",@"dec", nil];
for (int i = 0; i<months.count; i++)
{
CPTAxisLabel *monthsLabel = [[CPTAxisLabel alloc]initWithText:[months objectAtIndex:i] textStyle:xAxis.labelTextStyle];
monthsLabel.tickLocation = [NSNumber numberWithInt:i];
monthsLabel.offset = 3.0;
NSString *month = [months objectAtIndex:i];
if (monthsLabel)
{
if(i%2 == 0)
{
[monthLabelset addObject:monthsLabel];
[monthsDataset addObject:month];
}
}
}
NSMutableSet *monthLabels = [[NSMutableSet alloc]initWithArray:monthLabelset];
NSMutableSet *monthsData = [[NSMutableSet alloc]initWithArray:monthsDataset];
xAxis.labelingPolicy = CPTAxisLabelingPolicyNone;
xAxis.axisLabels = monthLabels;
xAxis.majorTickLocations = monthsData;
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:[NSNumber numberWithInt:0] length:[NSNumber numberWithInt:11]];
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:[NSNumber numberWithInt:(yAxisMin)] length:[NSNumber numberWithInt:(yAxisMax - yAxisMin)]];
[xAxis setMajorIntervalLength:[NSNumber numberWithInt:2]];
[yAxis setMajorIntervalLength:[NSNumber numberWithInt:1]];
[yAxis setLabelFormatter:axisFormatter];
CPTMutablePlotRange *xRange = [plotSpace.xRange mutableCopy];
CPTMutablePlotRange *yRange = [plotSpace.yRange mutableCopy];
[xRange expandRangeByFactor:[NSNumber numberWithDouble:1.06]];
[yRange expandRangeByFactor:[NSNumber numberWithDouble:1.06]];
plotSpace.xRange = xRange;
plotSpace.yRange = yRange;
`
我在下面添加了代码
if(i%2 == 0)
{
[monthLabelset addObject:monthsLabel];
[monthsDataset addObject:month];
}