Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何仅为核心图在轴外侧放置间隔线_Ios_Core Plot - Fatal编程技术网

Ios 如何仅为核心图在轴外侧放置间隔线

Ios 如何仅为核心图在轴外侧放置间隔线,ios,core-plot,Ios,Core Plot,我现在有一个图形显示在同一个y轴在左侧和右侧。在代码中的某个地方,我告诉x轴和左y轴的轴间隔保持在绘图空间/图形区域之外 我在放屁,你能说出明显的情况吗 我的代码: if ((int)[[UIScreen mainScreen] bounds].size.height == 568) { self.hostView = [(CPTGraphHostingView *) [CPTGraphHostingView alloc] initWithFrame:CGRectMake(0, 190,

我现在有一个图形显示在同一个y轴在左侧和右侧。在代码中的某个地方,我告诉x轴和左y轴的轴间隔保持在绘图空间/图形区域之外

我在放屁,你能说出明显的情况吗

我的代码:

if ((int)[[UIScreen mainScreen] bounds].size.height == 568) {
    self.hostView = [(CPTGraphHostingView *) [CPTGraphHostingView alloc] initWithFrame:CGRectMake(0, 190, 320, 265)];
}
else {
    self.hostView = [(CPTGraphHostingView *) [CPTGraphHostingView alloc] initWithFrame:CGRectMake(0, 190, 320, 178)];
}
self.hostView.allowPinchScaling = NO;
[self.view addSubview:self.hostView];

graph = [[CPTXYGraph alloc] initWithFrame:self.hostView.bounds];
self.hostView.hostedGraph = graph;
CPTGradient *gradient = [CPTGradient gradientWithBeginningColor:[CPTColor colorWithCGColor:[UIColorFromRGB(0x2468d8)CGColor]]
                                                    endingColor:[CPTColor colorWithCGColor:[UIColorFromRGB(0xa4bbe0)CGColor]]];
gradient.angle     = 90.0;
graph.plotAreaFrame.fill = [CPTFill fillWithGradient:gradient];
CPTMutableLineStyle *borderLineStyle = [CPTMutableLineStyle lineStyle];
borderLineStyle.lineColor = [CPTColor colorWithCGColor:[UIColorFromRGB(0x717a72)CGColor]];
borderLineStyle.lineWidth = 4.0;
graph.plotAreaFrame.borderLineStyle = borderLineStyle;
graph.plotAreaFrame.cornerRadius        = 10.0;
[graph.plotAreaFrame setPaddingLeft:21.0f];
[graph.plotAreaFrame setPaddingRight:21.0f];
[graph.plotAreaFrame setPaddingBottom:18.0f];
graph.paddingLeft   = 3.0;
graph.paddingTop    = 3.0;
graph.paddingRight  = 3.0;
graph.paddingBottom = 3.0;
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]];
[dateFormatter setDateFormat:@"yyy-MM-dd HH:mm:ss"];
NSDate *firstDate = [dateFormatter dateFromString:[[changedArray objectAtIndex:0]objectForKey:@"date"]];
NSDate *lastDate = [dateFormatter dateFromString:[[changedArray objectAtIndex:changedArray.count-1]objectForKey:@"date"]];
NSNumber *difference = [NSDecimalNumber numberWithDouble:[lastDate timeIntervalSinceDate:firstDate]];

CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *) graph.defaultPlotSpace;
plotSpace.allowsUserInteraction = NO;
plotSpace.delegate = self;
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0) length:CPTDecimalFromFloat([difference integerValue]*1.05)];
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0) length:CPTDecimalFromFloat([yMaxValue integerValue]+5)];
plotSpace.globalXRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(0) length:CPTDecimalFromFloat([difference integerValue]*1.05)];
plotSpace.globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(0) length:CPTDecimalFromDouble([yMaxValue doubleValue]*1.23)];

CPTMutableLineStyle *graphLineStyle = [CPTMutableLineStyle lineStyle];
graphLineStyle.lineCap   = kCGLineCapRound;
graphLineStyle.lineColor = [CPTColor whiteColor];
graphLineStyle.lineWidth = 1.0;

CPTXYAxisSet *axisSet = (CPTXYAxisSet *)graph.axisSet;
CPTXYAxis *x = axisSet.xAxis;
x.axisLineStyle = graphLineStyle;
x.axisLineStyle = graphLineStyle;
x.axisConstraints = [CPTConstraints constraintWithLowerOffset:0];
x.minorTickLength = 3.0f;
x.majorTickLength = 5.0f;

CPTMutableTextStyle *labelStyle = [CPTMutableTextStyle textStyle];
labelStyle.color = [[CPTColor whiteColor] colorWithAlphaComponent:1];
labelStyle.fontName = @"Helvetica-Bold";
labelStyle.fontSize = 9.0f;

xFirstEntry = [[[changedArray objectAtIndex:0]objectForKey:@"date"] substringFromIndex:11];
xFirstEntry = [xFirstEntry substringToIndex:[xFirstEntry length] - 6];
xLastEntry = [[[changedArray objectAtIndex:changedArray.count-1]objectForKey:@"date"] substringFromIndex:11];
xLastEntry = [xLastEntry substringToIndex:[xLastEntry length] - 6];

NSMutableArray *xMajorLocations = [[NSMutableArray alloc]init];
NSMutableArray *xMinorLocations = [[NSMutableArray alloc]init];
NSMutableArray *xLabels = [[NSMutableArray alloc]init];
int newValue = [xFirstEntry integerValue];
NSNumber *xMajorDataPoint = [NSNumber numberWithInt:(newValue)];
NSNumber *xMinorDataPoint = [NSNumber numberWithInt:(newValue)];
if ([xFirstEntry integerValue] > [xLastEntry integerValue]) {
    while (newValue <= 24) {
        xMinorDataPoint = @([xMajorDataPoint integerValue] + 1800);
        NSNumber *x2LabelValue = [NSNumber numberWithInt:newValue];
        CPTAxisLabel *label = [[CPTAxisLabel alloc] initWithText:[x2LabelValue stringValue] textStyle:labelStyle];
        label.tickLocation = CPTDecimalFromInt([xMajorDataPoint intValue]);
        label.offset = 5;
        [xLabels addObject:label];
        [xMajorLocations addObject:xMajorDataPoint];
        [xMinorLocations addObject:xMinorDataPoint];
        newValue++;
        xMajorDataPoint = @([xMajorDataPoint integerValue] + 3600);
    }
    newValue = 1;
    xMinorDataPoint = @([xMajorDataPoint integerValue] + 1800);
    NSNumber *x2LabelValue = [NSNumber numberWithInt:newValue];
    CPTAxisLabel *label = [[CPTAxisLabel alloc] initWithText:[x2LabelValue stringValue] textStyle:labelStyle];
    label.tickLocation = CPTDecimalFromInt([xMajorDataPoint intValue]);
    label.offset = 5;
    [xLabels addObject:label];
    [xMajorLocations addObject:xMajorDataPoint];
    [xMinorLocations addObject:xMinorDataPoint];
    newValue++;
    xMajorDataPoint = @([xMajorDataPoint integerValue] + 3600);
    while (newValue <= [xLastEntry integerValue]+1) {
        xMinorDataPoint = @([xMajorDataPoint integerValue] + 1800);
        NSNumber *x2LabelValue = [NSNumber numberWithInt:newValue];
        CPTAxisLabel *label = [[CPTAxisLabel alloc] initWithText:[x2LabelValue stringValue] textStyle:labelStyle];
        label.tickLocation = CPTDecimalFromInt([xMajorDataPoint intValue]);
        label.offset = 5;
        [xLabels addObject:label];
        [xMajorLocations addObject:xMajorDataPoint];
        [xMinorLocations addObject:xMinorDataPoint];
        newValue++;
        xMajorDataPoint = @([xMajorDataPoint integerValue] + 3600);
    }
}
else {
    while (newValue <= [xLastEntry integerValue]+1) {
        xMinorDataPoint = @([xMajorDataPoint integerValue] + 1800);
        NSNumber *xLabelValue = [NSNumber numberWithInt:newValue];
        CPTAxisLabel *label = [[CPTAxisLabel alloc] initWithText:[xLabelValue stringValue] textStyle:labelStyle];
        label.tickLocation = CPTDecimalFromInt([xMajorDataPoint intValue]);
        label.offset = 5;
        [xLabels addObject:label];
        [xMajorLocations addObject:xMajorDataPoint];
        [xMinorLocations addObject:xMinorDataPoint];
        newValue++;
        xMajorDataPoint = @([xMajorDataPoint integerValue] + 3600);
    }
}
x.labelingPolicy = CPTAxisLabelingPolicyNone;
x.axisLabels = [NSSet setWithArray:xLabels];
x.majorTickLocations = [NSSet setWithArray:xMajorLocations];
x.minorTickLocations = [NSSet setWithArray:xMinorLocations];
x.majorTickLineStyle = graphLineStyle;
x.minorTickLineStyle = graphLineStyle;

CPTXYAxis *y = axisSet.yAxis;
y.axisLineStyle = graphLineStyle;
y.majorIntervalLength = CPTDecimalFromDouble(10);
y.minorTicksPerInterval = 9;
y.minorTickLength = 3;
y.majorTickLength = 5;
y.labelOffset = 0;
y.orthogonalCoordinateDecimal = CPTDecimalFromDouble(0);
y.labelTextStyle = labelStyle;
y.majorTickLineStyle = graphLineStyle;
y.minorTickLineStyle = graphLineStyle;
NSNumberFormatter *Yformatter = [[NSNumberFormatter alloc] init];
[Yformatter setGeneratesDecimalNumbers:NO];
[Yformatter setNumberStyle:NSNumberFormatterDecimalStyle];
y.labelFormatter = Yformatter;
y.axisConstraints = [CPTConstraints constraintWithLowerOffset:0];

CPTXYAxis *y2 = [(CPTXYAxis *)[CPTXYAxis alloc] initWithFrame:CGRectZero];
y2.coordinate = CPTCoordinateY;
y2.plotSpace = plotSpace;
y2.axisLineStyle = graphLineStyle;
y2.majorIntervalLength = CPTDecimalFromDouble(10);
y2.minorTicksPerInterval = 9;
y2.minorTickLength = 3;
y2.majorTickLength = 5;
y2.labelOffset = -20;
y2.labelTextStyle = labelStyle;
y2.majorTickLineStyle = graphLineStyle;
y2.minorTickLineStyle = graphLineStyle;
y2.labelFormatter = Yformatter;
y2.axisConstraints = [CPTConstraints constraintWithUpperOffset:0];

graph.axisSet.axes = @[x, y, y2];
if((int)[[UIScreen mainScreen]界限].size.height==568){
self.hostView=[(CPTGraphHostingView*)[CPTGraphHostingView alloc]initWithFrame:CGRectMake(0190320265)];
}
否则{
self.hostView=[(CPTGraphHostingView*)[CPTGraphHostingView alloc]initWithFrame:CGRectMake(0190320178)];
}
self.hostView.allowPinchScaling=否;
[self.view addSubview:self.hostView];
graph=[[CPTXYGraph alloc]initWithFrame:self.hostView.bounds];
self.hostView.hostedGraph=图形;
CPTGradient*gradient=[CPTGradient gradientwithbeginingcolor:[CPTColor colorWithCGColor:[UIColorFromRGB(0x2468d8)CGColor]]
endingColor:[CPTColor colorWithCGColor:[UIColorFromRGB(0xa4bbe0)CGColor]];
梯度角=90.0;
graph.plotAreaFrame.fill=[CPTFill fillWithGradient:gradient];
CPTMutableLineStyle*borderLineStyle=[CPTMutableLineStyle];
borderLineStyle.lineColor=[CPTColor colorWithCGColor:[UIColorFromRGB(0x717a72)CGColor]];
borderLineStyle.lineWidth=4.0;
graph.plotAreaFrame.borderLineStyle=borderLineStyle;
graph.plotAreaFrame.cornerRadius=10.0;
[graph.plotAreaFrame setpadding left:21.0f];
[graph.plotAreaFrame setPaddingRight:21.0f];
[graph.PlotArea框架设置填充底部:18.0f];
graph.paddingLeft=3.0;
graph.paddingTop=3.0;
graph.paddingRight=3.0;
graph.paddingBottom=3.0;
NSDateFormatter*dateFormatter=[[NSDateFormatter alloc]init];
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@“GMT”];
[dateFormatter setDateFormat:@“yyy-MM-dd HH:MM:ss”];
NSDate*firstDate=[dateFormatter dateFromString:[[changedArray objectAtIndex:0]objectForKey:@“date”];
NSDate*lastDate=[dateFormatter dateFromString:[[changedArray对象索引:changedArray.count-1]objectForKey:@“日期”];
NSNumber*差=[NSDecimalNumber numberWithDouble:[lastDate timeIntervalSinceDate:firstDate]];
CPTXYPlotSpace*plotSpace=(CPTXYPlotSpace*)graph.defaultPlotSpace;
plotSpace.allowUserInteraction=否;
plotSpace.delegate=self;
plotSpace.xRange=[CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0)长度:CPTDecimalFromFloat([difference integerValue]*1.05)];
plotSpace.yRange=[CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0)长度:CPTDecimalFromFloat([yMaxValue integerValue]+5)];
plotSpace.globalXRange=[CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(0)长度:CPTDecimalFromFloat([difference integerValue]*1.05)];
plotSpace.globalYRange=[CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(0)长度:CPTDecimalFromDouble([yMaxValue doubleValue]*1.23)];
CPTMutableLineStyle*graphLineStyle=[CPTMutableLineStyle];
graphLineStyle.lineCap=kCGLineCapRound;
graphLineStyle.lineColor=[CPTColor whiteColor];
graphLineStyle.lineWidth=1.0;
CPTXYAxisSet*axisSet=(CPTXYAxisSet*)graph.axisSet;
CPTXYAxis*x=axisSet.xAxis;
x、 axisLineStyle=graphLineStyle;
x、 axisLineStyle=graphLineStyle;
x、 axisConstraints=[CPTCConstraints ConstraintsWithLowerofSet:0];
x、 minorTickLength=3.0f;
x、 majorTickLength=5.0f;
CPTMutableTextStyle*标签样式=[CPTMutableTextStyle textStyle];
labelStyle.color=[[CPTColor whiteColor]colorWithAlphaComponent:1];
labelStyle.fontName=@“Helvetica Bold”;
labelStyle.fontSize=9.0f;
xFirstEntry=[[changedArray objectAtIndex:0]objectForKey:@“date”]substringFromIndex:11];
xFirstEntry=[xFirstEntry substringToIndex:[xFirstEntry length]-6];
xlasentry=[[changedArray objectAtIndex:changedArray.count-1]objectForKey:@“date”]substringfromfromindex:11];
xLastEntry=[xLastEntry substringToIndex:[xLastEntry length]-6];
NSMutableArray*xMajorLocations=[[NSMutableArray alloc]init];
NSMutableArray*xMinorLocations=[[NSMutableArray alloc]init];
NSMutableArray*xLabels=[[NSMutableArray alloc]init];
int newValue=[xFirstEntry integerValue];
NSNumber*xMajorDataPoint=[NSNumber numberwhithint:(newValue)];
NSNumber*xMinorDataPoint=[NSNumber numberwhithint:(newValue)];
if([xFirstEntry integerValue]>[xLastEntry integerValue]){

而(newValue您可以按如下方式设置刻度的方向:

y.tickDirection = CPTSignPositive;
您还可以选择
CPTSignNegative
,具体取决于要相对于轴放置记号的方向

在你的代码中,我认为你看到的是

CPTAxisLabel *label = [[CPTAxisLabel alloc] initWithText:[x2LabelValue stringValue] textStyle:labelStyle];
label.tickLocation = CPTDecimalFromInt([xMajorDataPoint intValue]);
label.offset = 5;