【问题标题】:CorePlot: what is the difference between majorTickLocations (graph) and setYRange (plot space)?CorePlot:majorTickLocations(图形)和 setYRange(绘图空间)有什么区别?
【发布时间】:2015-08-25 08:58:04
【问题描述】:

我想在我的图表中创建 3 个色带,但我认为我做错了。 y 值的范围应为 0 到 1024,我希望第一个色带从 0 到 300,第二个色带从 300 到 600,第三个色带从 600 到 1024。但是代码我写了创建 6 个波段而不是 3 个波段,它似乎 忽略了 1024 限制。这是结果图和我使用的代码:

图表:

它应该只有 3 个波段,而且它似乎忽略了我在绘图空间中设置的范围为 1024 的事实。但是我不确定 ma​​jorTickLocations 的含义和用法。我开始认为与情节空间范围没有直接关系。

代码:

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];

【问题讨论】:

    标签: ios objective-c graph customization core-plot


    【解决方案1】:

    尝试设置此政策:

    y.labelingPolicy = CPTAxisLabelingPolicyNone;
    

    【讨论】:

      猜你喜欢
      • 2012-01-15
      • 1970-01-01
      • 2010-11-01
      • 1970-01-01
      • 2021-06-19
      • 1970-01-01
      • 2013-12-30
      • 2011-11-16
      • 1970-01-01
      相关资源
      最近更新 更多