Iphone 如何在散点图中将日期更改为轴标签

Iphone 如何在散点图中将日期更改为轴标签,iphone,core-plot,Iphone,Core Plot,使用coreplot时,如何将日期作为轴标签放置在散点图中 我在示例中找到了如何更改条形图中的AxisLabel 这不起作用。它起作用。您需要遵循条形图绘图示例中使用的相同代码。我在散点图中做了这件事。这里有一个方法,我是怎么做的 - (void) setRangeForGraph { //Customize x and y axis CPLineStyle *lineStyle = [CPLineStyle lineStyle]; lineSt

使用coreplot时,如何将日期作为轴标签放置在散点图中

我在示例中找到了如何更改条形图中的AxisLabel


这不起作用。

它起作用。您需要遵循条形图绘图示例中使用的相同代码。我在散点图中做了这件事。这里有一个方法,我是怎么做的

- (void) setRangeForGraph {

        //Customize x and y axis
        CPLineStyle *lineStyle = [CPLineStyle lineStyle];
        lineStyle.lineColor = [CPColor colorWithCGColor:((UIColor*)kProtienColor).CGColor];
        lineStyle.lineWidth = 1.0f;

        CPTextStyle *whiteText = [CPTextStyle textStyle];
        whiteText.color = [CPColor grayColor];              


        CPXYAxisSet *axisSet = (CPXYAxisSet *)graph.axisSet;

        //Customize x axis
        CPXYAxis *x = axisSet.xAxis;

        //x.title = @"Date";
        x.majorIntervalLength = CPDecimalFromInteger(1);

        x.axisLineStyle = lineStyle;
        x.minorTickLineStyle = lineStyle;

        x.titleOffset = 0;
        x.labelOffset = 5;
        x.titleLocation = CPDecimalFromFloat(0);

        x.titleTextStyle=whiteText;
        x.labelTextStyle=whiteText;
        x.orthogonalCoordinateDecimal = CPDecimalFromString(@"0");
        x.titleOffset = 0.0f;


        // Define some custom labels for the data elements
        x.labelRotation = M_PI/4;
        x.labelingPolicy = CPAxisLabelingPolicyNone;

        NSMutableArray *ticks = [[[NSMutableArray alloc] initWithCapacity:[self.weightEntries count]] autorelease];

        for(unsigned int counter = 0; counter < [self.weightEntries count];counter++){
            [ticks addObject:[NSNumber numberWithInt:counter]];
        }

        NSUInteger labelLocation = 0;

        NSArray *xAxisLabels = [self createDateAxisLabels];

        NSMutableArray *customLabels = [NSMutableArray arrayWithCapacity:[xAxisLabels count]];

        @try {

            for (NSNumber *tickLocation in ticks) {
                CPAxisLabel *newLabel = [[CPAxisLabel alloc] initWithText: [xAxisLabels objectAtIndex:labelLocation++] textStyle:x.labelTextStyle];
                newLabel.tickLocation = [tickLocation decimalValue];
                newLabel.offset = 0;//x.labelOffset + x.majorTickLength;
                newLabel.rotation = M_PI/4;
                [customLabels addObject:newLabel];
                [newLabel release];
            }

        }
        @catch (NSException * e) {
            NSLog(@"An exception occured while creating date labels for x-axis");
        }
        @finally {
            x.axisLabels =  [NSSet setWithArray:customLabels];  
        }


        //Customize y axis

        CPXYAxis *y = axisSet.yAxis;

        //y.title = @"Weight";
        y.majorIntervalLength   = CPDecimalFromFloat([high floatValue]/7);

        y.orthogonalCoordinateDecimal = CPDecimalFromString(@"0");

        y.titleOffset           = 35.0f;
        y.titleLocation         = CPDecimalFromFloat([high floatValue]/2);
        y.paddingLeft           = 0;
        //y.majorIntervalLength = CPDecimalFromString(@"150");
        y.minorTicksPerInterval = 5;
        y.axisLineStyle         = lineStyle;
        y.titleTextStyle        = whiteText;
        y.minorTickLineStyle    = lineStyle;
        y.labelTextStyle        = whiteText;
        y.orthogonalCoordinateDecimal = CPDecimalFromString(@"0");

    }
}
-(void)setRangeForGraph{
//自定义x轴和y轴
CPLineStyle*lineStyle=[CPLineStyle lineStyle];
lineStyle.lineColor=[CPColor colorWithCGColor:((UIColor*)kprotectioncolor.CGColor];
lineStyle.lineWidth=1.0f;
CPTextStyle*白色文本=[CPTextStyle textStyle];
whiteText.color=[CPColor grayColor];
CPXYAxisSet*axisSet=(CPXYAxisSet*)graph.axisSet;
//自定义x轴
CPXYAxis*x=axisSet.xAxis;
//x、 标题=@“日期”;
x、 majorIntervalLength=CPDecimalFromInteger(1);
x、 axisLineStyle=线条样式;
x、 minorTickLineStyle=线条样式;
x、 titleOffset=0;
x、 labelOffset=5;
x、 titleLocation=cpdecimalfloat(0);
x、 titleTextStyle=白色文本;
x、 labelTextStyle=白文本;
x、 正交坐标CIMAL=CPDecimalFromString(@“0”);
x、 标题偏移=0.0f;
//为数据元素定义一些自定义标签
x、 labelRotation=M_PI/4;
x、 labelingPolicy=CPAxisLabelingPolicyOne;
NSMutableArray*ticks=[[NSMutableArray alloc]initWithCapacity:[self.weightEntries count]]autorelease];
for(无符号整数计数器=0;计数器<[self.weightEntries计数];计数器++){
[ticks addObject:[NSNumber numberwhithint:counter]];
}
NSU整数标签位置=0;
NSArray*xAxisLabels=[self-createDateAxisLabels];
NSMutableArray*customLabels=[NSMutableArray阵列容量:[XaxiLabels计数]];
@试一试{
用于(NSNumber*勾号位置){
CPAxisLabel*newLabel=[[CPAxisLabel alloc]initWithText:[xAxisLabels对象索引:labelLocation++]textStyle:x.labelTextStyle];
newLabel.tickLocation=[tickLocation decimalValue];
newLabel.offset=0;//x.labelOffset+x.majorTickLength;
newLabel.rotation=M_PI/4;
[customLabels addObject:newLabel];
[新标签发布];
}
}
@捕获(N例外*e){
NSLog(@“为x轴创建日期标签时发生异常”);
}
@最后{
x、 axisLabels=[NSSet setWithArray:customLabels];
}
//自定义y轴
CPXYAxis*y=axisSet.yAxis;
//y、 标题=@“重量”;
y、 majorIntervalLength=CPDecimalFloat([high floatValue]/7);
y、 正交坐标CIMAL=CPDecimalFromString(@“0”);
y、 标题偏移=35.0f;
y、 titleLocation=cpdecimalfloat([高浮点值]/2);
y、 paddingLeft=0;
//y、 majorIntervalLength=CPDecimalFromString(@“150”);
y、 minorTicksPerInterval=5;
y、 axisLineStyle=线条样式;
y、 titleTextStyle=白色文本;
y、 minorTickLineStyle=线条样式;
y、 labelTextStyle=白文本;
y、 正交坐标CIMAL=CPDecimalFromString(@“0”);
}
}

谢谢,我错过了这个东西'x.labelingPolicy=cpaxislabelingpolicyne;'它允许放置自定义标签