iphone - 更改核心图中的 y 轴标签间隔

标签 iphone objective-c ios xcode core-plot

我在我的应用程序中实现了散点图的核心绘图库。但我想显示 Y 轴标签,如 1.0、2.0、3.0、4.0、5.0,.. 并相应地绘制图表。

当我如下所示乘以 25 来更改 y 标签的间隔时

NSInteger majorIncrement = 2;

NSInteger minorIncrement = 1;   

CGFloat yMax = 10.0f;// should determine dynamically based on max price    
NSMutableSet *yLabels = [NSMutableSet set];
NSMutableSet *yMajorLocations = [NSMutableSet set];
NSMutableSet *yMinorLocations = [NSMutableSet set];
for (NSInteger j = minorIncrement; j <= yMax; j += minorIncrement) {
    NSUInteger mod = j % majorIncrement;


    if (mod == 0) {
        CPTAxisLabel *label = [[CPTAxisLabel alloc] initWithText:[NSString stringWithFormat:@"%i", j] textStyle:y.labelTextStyle];
        NSDecimal location = CPTDecimalFromInteger(j*25);  **//multiply with 25**`



       label.tickLocation = location;
        label.offset = -y.majorTickLength - y.labelOffset;

        if (label) {

            [yLabels addObject:label];
        }
        [yMajorLocations addObject:[NSDecimalNumber decimalNumberWithDecimal:location]];

    } else {
        [yMinorLocations addObject:[NSDecimalNumber decimalNumberWithDecimal:CPTDecimalFromInteger(j)]];

    }
}
y.axisLabels = yLabels;    
y.majorTickLocations = yMajorLocations;
y.minorTickLocations = yMinorLocations;

但是当绘制图表时,它显示我错了。

例如如果我的分数是 150,那么它开始绘制为 150/25=第 6 分。

最佳答案

您可以设置 orthogonalCoordinateDecimal,以确定图形开始的点

 CPTXYAxis *y = axisSet.yAxis;
   y.orthogonalCoordinateDecimal = CPTDecimalFromFloat(150/25);

进一步,设置plotRange,

 CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace;   
   plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:(150/25) length:25];

关于iphone - 更改核心图中的 y 轴标签间隔,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13305116/

相关文章:

objective-c - float uiview subview 在滚动时消失

ios - 在IOS本地保存pdf

iphone - 是否有任何 Bayeux 协议(protocol)的 iOS 实现(COMET,服务器推送到客户端)?

iphone - Objective C - 将 NSString 写入 plist

iphone - Objective C - 如何使用 OC Mock?

ios - 类型 "ViewController"不符合协议(protocol) 'UITableViewDataSource"

objective-c - 添加 Cocoa Touch 静态库作为子项目

iPhone RESTful Web 服务

ios - Swift 是 "porting iOS app to OSX"的解决方案吗?

ios - dequeueReusableCellWithIdentifier :forIndexPath: 中的断言失败