CorePlot:majorTickLocations(图形)和setYRange(绘图空间)之间有什么区别?
我想在我的图表中创建3个色带 ,但我认为我做错了。 y值的范围应为0到1024 ,我希望第一个颜色带从0到300,第二个从300到600,第三个从600到1024.但是我写的代码创建了6个波段而不是3它似乎忽略了1024的限制 。 这是结果图和我使用的代码:
图形:
它应该只有3个波段 ,而且似乎忽略了我在绘图空间中设置1024范围的事实。 但是我不确定majorTickLocations的含义和用法 。 我开始认为与绘图空间范围没有直接关联。
码:
self.graph = [[CPTXYGraph alloc] initWithFrame:self.graphHostView.bounds]; self.graphHostView.hostedGraph = self.graph; CPTMutableTextStyle *titleStyle = [CPTMutableTextStyle textStyle]; titleStyle.color = [CPTColor blackColor]; titleStyle.fontName = @"Helvetica"; titleStyle.fontSize = 12.0f; // Axes // Label x axis with a fixed interval policy CPTXYAxisSet *axisSet = (CPTXYAxisSet *)self.graph.axisSet; CPTXYAxis *x = axisSet.xAxis; x.separateLayers = NO; x.minorTicksPerInterval = 4; x.minorTickLength = 8.0; x.title = @"X Axis"; x.titleTextStyle = titleStyle; x.delegate = self; CPTXYAxis *y = axisSet.yAxis; y.labelingPolicy = CPTAxisLabelingPolicyAutomatic; y.separateLayers = YES; y.majorTickLocations = [NSSet setWithObjects: [NSDecimalNumber numberWithDouble:0], [NSDecimalNumber numberWithDouble:300], [NSDecimalNumber numberWithDouble:600], [NSDecimalNumber numberWithDouble:1024], nil]; y.title = @"Y Axis"; y.titleTextStyle = titleStyle; y.alternatingBandFills = [NSArray arrayWithObjects: [CPTColor whiteColor], [[CPTColor greenColor] colorWithAlphaComponent:CPTFloat(0.3)], [[CPTColor redColor] colorWithAlphaComponent:CPTFloat(0.3)], nil]; y.delegate = self; // Add the y2 axis to the axis set self.graph.axisSet.axes = @[x, y]; self.graph.title = @"My graph"; self.graph.titleDisplacement = CGPointMake(0.0f, -68.0f); self.graph.titleTextStyle = titleStyle; CPTMutableLineStyle *axisLineStyle = [CPTMutableLineStyle lineStyle]; axisLineStyle.lineWidth = 2.0f; axisLineStyle.lineColor = [[CPTColor blackColor] colorWithAlphaComponent:1]; // Get the (default) plotspace from the graph so we can set its x/y ranges CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *) self.graph.defaultPlotSpace; // Note that these CPTPlotRange are defined by START and LENGTH (not START and END) !! [plotSpace setYRange: [CPTPlotRange plotRangeWithLocation:[NSNumber numberWithInt:0] length:[NSNumber numberWithInt:1024]]]; [plotSpace setXRange: [CPTPlotRange plotRangeWithLocation:[NSNumber numberWithInt:0] length:[NSNumber numberWithInt:100]]]; // Create the plot (we do not define actual x/y values yet, these will be supplied by the datasource...) self.plot = [[CPTScatterPlot alloc] initWithFrame:CGRectZero]; // Let's keep it simple and let this class act as datasource (therefore we implemtn ) self.plot.dataSource = self; // Finally, add the created plot to the default plot space of the CPTGraph object we created before [self.graph addPlot:self.plot toPlotSpace:self.graph.defaultPlotSpace];
尝试设置此政策:
y.labelingPolicy = CPTAxisLabelingPolicyNone;