BEMSimpleLineGraph X-Axis标签未显示比iPhone 5更新的手机

时间:2015-06-04 15:18:06

标签: graph bemsimplelinegraph

我已经使用BEMSimpleLineGraph Pod创建了一个折线图,但是,就我而言,无法弄清楚为什么x-Axis标签不会出现在任何更新的设备上iPhone 5。

编辑:我应该在默认情况下提及enableXAxisLabel = YES。

以下是布置图表的代码:

#import "WeightChartCell.h"

@implementation WeightChartCell

@synthesize viewCell, arrayPlots, myGraph, labelWeightHistory;

- (void)awakeFromNib {
}

- (void)layoutSubviews {
    [super layoutSubviews];

    float width = viewCell.bounds.size.width;

    self.myGraph = [[BEMSimpleLineGraphView alloc] initWithFrame:CGRectMake(-20, 40, width+20, 150.0)];
    self.myGraph.dataSource = self;
    self.myGraph.delegate = self;
    self.myGraph.colorTop = [UIColor whiteColor];
    self.myGraph.colorBottom = [UIColor colorWithRed:190/255.0 green:218/255.0 blue:246/255.0 alpha:1];
    self.myGraph.colorLine = [UIColor colorWithRed:124/255.0 green:181/255.0 blue:236/255.0 alpha:1];
    self.myGraph.colorPoint = [UIColor colorWithRed:124/255.0 green:181/255.0 blue:236/255.0 alpha:1];
    self.myGraph.widthLine = 3;
    self.myGraph.sizePoint = 10;
    self.myGraph.alwaysDisplayDots = YES;
    self.myGraph.colorXaxisLabel = [UIColor lightGrayColor];
    self.myGraph.colorBackgroundXaxis = [UIColor clearColor];
    self.myGraph.enableYAxisLabel = YES;
    self.myGraph.colorYaxisLabel = [UIColor clearColor];
    self.myGraph.colorBackgroundYaxis = [UIColor clearColor];
    self.myGraph.enableReferenceYAxisLines = YES;
    self.myGraph.colorReferenceLines = [UIColor lightGrayColor];
    self.myGraph.enableLeftReferenceAxisFrameLine = NO;
    self.myGraph.enablePopUpReport = YES;
    self.myGraph.enableReferenceAxisFrame = YES;

    [viewCell addSubview:self.myGraph];

    labelWeightHistory.text = NSLocalizedString(@"Progress", nil);
    [self sendSubviewToBack:self.myGraph];

}

- (NSInteger)numberOfPointsInLineGraph:(BEMSimpleLineGraphView *)graph {
    return [arrayPlots count];
}

- (NSInteger)numberOfGapsBetweenLabelsOnLineGraph:(BEMSimpleLineGraphView *)graph {
    return 1;
}

- (NSString *)lineGraph:(BEMSimpleLineGraphView *)graph labelOnXAxisForIndex:(NSInteger)index {
    NSString *dateStr = [[arrayPlots objectAtIndex:index] valueForKey:@"created_at"];
    // Convert string to date object
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
    [dateFormat setDateFormat:@"yyyy-MM-dd"];
    NSDate *date = [dateFormat dateFromString:dateStr];

    // Convert date object to desired output format
    [dateFormat setDateFormat:@"d.MMM"];
    dateStr = [dateFormat stringFromDate:date];
    return dateStr;
}

- (CGFloat)lineGraph:(BEMSimpleLineGraphView *)graph valueForPointAtIndex:(NSInteger)index {
    NSInteger yPoint = [[[arrayPlots objectAtIndex:index] valueForKey:@"weight"] floatValue];
    return yPoint;
}

@end

它在iPhone 5设备和iPhone 5模拟器上按预期出现: iPhone 5

但他们根本不会出现比iPhone 5更新的东西。这适用于iPhone 5s: iPhone 5s

1 个答案:

答案 0 :(得分:5)

请参阅this issue on github。在我们处理官方修复时,它包含一个临时修复。

谢谢!