Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/118.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios CorePlot-CPTTimeFormatter为条形图的每个元素提供相同的时间_Ios_Cocoa Touch_Graph_Core Plot - Fatal编程技术网

Ios CorePlot-CPTTimeFormatter为条形图的每个元素提供相同的时间

Ios CorePlot-CPTTimeFormatter为条形图的每个元素提供相同的时间,ios,cocoa-touch,graph,core-plot,Ios,Cocoa Touch,Graph,Core Plot,我有一个使用Core plot(CPTBarPlot)的图表,我想在X轴上显示几天,每个条的顺序是不同的一天。我已经尝试如下设置CPTTimeFormatter,其中x是我的x轴 NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init] ; dateFormatter.dateStyle = kCFDateFormatterMediumStyle; CPTTimeFormatter *timeForma

我有一个使用Core plot(CPTBarPlot)的图表,我想在X轴上显示几天,每个条的顺序是不同的一天。我已经尝试如下设置CPTTimeFormatter,其中x是我的x轴

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init] ;
    dateFormatter.dateStyle = kCFDateFormatterMediumStyle;
    CPTTimeFormatter *timeFormatter = [[CPTTimeFormatter alloc] initWithDateFormatter:dateFormatter];
    NSDate *refDate = [NSDate date];

    timeFormatter.referenceDate = refDate;
    x.labelFormatter = timeFormatter;
在numbersForPlot中,我返回了一组表示已用秒数的数字,因为我希望有连续的几天,它看起来像0, 86400, 172800, 259200, 345600, 432000, 518400 等等

在本例中,我希望X轴标签是从refDate开始的日期序列列表,在numbersForPlot中按秒数递增。相反,我所看到的是相同的日期在x轴上的每个条上一遍又一遍地重复。有谁能向我解释一下我做错了什么,以及我怎样才能纠正它?谢谢

编辑:这是数据源中my numbersForPlot函数的外观:

-(NSArray *)numbersForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndexRange:(NSRange)indexRange
{   
    NSArray *nums = nil;

    switch ( fieldEnum ) {
        case CPTBarPlotFieldBarLocation:
            nums = [NSMutableArray arrayWithCapacity:indexRange.length];
            for ( NSUInteger i = indexRange.location; i < NSMaxRange(indexRange); i++ ) {
                [(NSMutableArray *)nums addObject :[NSDecimalNumber numberWithUnsignedInteger:i*secondsPerDay]];
            }
            NSLog(@"NUMS  = %@",nums);

            break;

        case CPTBarPlotFieldBarTip:
            nums = [stepsPerDay objectsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:indexRange]];
            break;

        default:
            break;
    }

    return nums;
}
-(NSArray*)数字用于绘图:(CPTPlot*)绘图字段:(NSUInteger)字段枚举记录索引范围:(NSRange)索引范围
{   
NSArray*nums=nil;
交换机(字段枚举){
案例CPTBarPlotFieldBar位置:
nums=[NSMutableArray阵列容量:indexRange.length];
对于(i=indexRange.location;i
相关部分是案例CPTBarPlotFieldBarLocation,它返回n个我认为正确的值数组

NUMS=( 0, 86400, 172800, 259200, 345600, 432000, 518400
)

格式化程序代码看起来正确。确保数据源返回正确的x值,例如,对于相隔一天的值,返回0、86400、172800等。

我找到了答案。我必须把它放好

x.majorIntervalLength = CPTDecimalFromInteger(secondsPerDay);

这个bug让我很困惑,因为除了重复的x标签,所有东西看起来都很完美,所以很难看出有什么不对劲。一旦我将间隔长度设置为正确的值,X轴标签就会正确显示我想要的日期。

这就是数据源中NumberForPlot函数的外观。。。哎呀,我不能在这个评论框中发布,因为它太长了。我已经更新了原始问题以显示数据源。看起来对吗?