【问题标题】:CorePlot, change number of tick marks on x-axis (to avoid an overabundance of tick marks)CorePlot,更改 x 轴上的刻度线数量(以避免过多的刻度线)
【发布时间】:2018-03-22 13:37:37
【问题描述】:

我的绘图范围是 160.5,绘图结果有 2 条大水平线...实际上只是刻度线和刻度线名称挤压在一起 160 多次,以形成两条大线的外观。

我想知道如何更改主要刻度线,以便 x 轴长度之间可能有 4-5 个偶数刻度线。

我附上了一张情况图片,并在下面放了一些代码(如果有帮助....或者您需要更多信息,我会提供。)我正在使用 XCode 9.2 和 iOS 11.2。

#import "ViewController.h"

@interface ViewController ()

@property (nonatomic, readwrite, strong) CPTGraph *graph;
@property (nonatomic, readwrite, strong, nonnull) CPTMutableNumberArray *plotData;
@property (nonatomic, readwrite, strong) CPTScatterPlot* plot;

@end

@implementation ViewController

@synthesize plotData;

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.graph = [[CPTXYGraph alloc] initWithFrame:self.graphView.bounds];
    [self.graph applyTheme:[CPTTheme themeNamed:kCPTSlateTheme]];

    self.graphView.hostedGraph = self.graph;

    CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)self.graph.defaultPlotSpace;

    [plotSpace setYRange: [CPTPlotRange plotRangeWithLocation:@(-2.0) length:@(6.00)]];
    [plotSpace setXRange: [CPTPlotRange plotRangeWithLocation:@(-30.5) length:@(160.5)]];

    self.plot = [[CPTScatterPlot alloc] initWithFrame:self.graphView.frame];

    self.plot.dataSource = self;

    [self.graph addPlot:self.plot toPlotSpace:self.graph.defaultPlotSpace];

}

// bunch of other methods

@end

【问题讨论】:

  • 所以补充一点,如果我将 x 轴长度从 160.5 更改为 10.5,刻度线和刻度线值会出现在轴上。这告诉我生成了 -10.5 和 160.5 之间的每个刻度线,从而产生了 2 条大水平线的错觉。仍然无法找到问题的根源,但这是一个开始。

标签: xcode graph core-plot


【解决方案1】:

对于任何人,直接更改源文件(CorePlot.xcodeproj 下拉选项下的文件夹)。具体来说,我更改了 Stocks Theme x 轴对象中的一些参数。

【讨论】:

    【解决方案2】:

    默认标签策略会在每个单元上放置一个主要的刻度线和标签,因此您试图将 160 个标签压缩到一个非常小的空间中。您需要调整 x 轴的标签属性。您需要使用labelingPolicypreferredNumberOfMajorTicks 和/或minorTicksPerInterval 的某种组合,具体取决于您想要的外观。

    【讨论】:

      猜你喜欢
      • 2016-06-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多