[英]CorePlot: what is the difference between majorTickLocations (graph) and setYRange (plot space)?
我想在图表中创建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 <CPTPlotDataSource>)
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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.