0

我正在使用 coreplot 来显示条形图。

我希望在 X 轴上显示日期,我像这样使用 labelFormatter

    NSDate *refDate = [NSDate date];
    NSTimeInterval oneHour =  60*60;

    CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *) self.hostView.hostedGraph.defaultPlotSpace;
    plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(xMin) length:CPTDecimalFromFloat(oneHour*24.0f)];
    plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(yMin) length:CPTDecimalFromFloat(yMax)];

    CPTXYAxisSet *axisSet = (CPTXYAxisSet *)barChart.axisSet;

    CPTMutableLineStyle *lineStyle = [CPTMutableLineStyle lineStyle];
    lineStyle.lineColor=[CPTColor grayColor];
    CPTXYAxis *x          = axisSet.xAxis;
    x.axisLineStyle               = lineStyle;
    x.majorTickLineStyle          = lineStyle;
    x.minorTickLineStyle          = lineStyle;
    x.minorTickLength = 1.0f;
    x.majorIntervalLength         = CPTDecimalFromFloat(oneHour*2);
    x.orthogonalCoordinateDecimal = CPTDecimalFromString(@"0");
    x.title                       = @"Hour";
    x.titleLocation               = CPTDecimalFromFloat(12.0f);
    x.titleOffset                 = 33.0f;
//    x.labelRotation  = M_PI / 4;
    // added for date
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"HH"];
    CPTTimeFormatter *timeFormatter = [[CPTTimeFormatter alloc] initWithDateFormatter:dateFormatter] ;
    timeFormatter.referenceDate = refDate;
    x.labelFormatter = timeFormatter;

到目前为止一切运行良好,Coreplot 数据源方法被正确调用,它们甚至返回数据。X 轴标签正确显示。

但问题是,只显示了 1 个条形图,我猜所有条形图都在显示,但它们相互重叠。

#pragma mark -
#pragma mark Plot Data Source Methods

-(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot
{

        return 24;

}

-(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index{
....
}
4

1 回答 1

0

确保返回的酒吧位置-numberForPlot:field:recordIndex:oneHour分开的。

于 2013-09-17T00:03:24.210 回答