0

ShinobiChart用来绘制烛台股票图表。我的数据是不连续的,所以图表上会有差距。

有谁知道我怎样才能让它连续显示?在文档中找不到...在此处输入图像描述

4

1 回答 1

0

好的,我找到了。供您参考:而不是添加SChartDateTimeAxis您应该添加SChartDiscontiniousDateTimeAxis.

然后对于 dataSeries 中的任何间隙,您必须明确排除时间段addExcludedTimePeriod:。(您可以检查下一天是否与数据系列中的下一个日期相同)。

SChartDiscontinuousDateTimeAxis *xAxis = [[SChartDiscontinuousDateTimeAxis alloc] init];
for (NSUInteger iter = 0; iter < self.quotes.count - 1; iter++) {

    NSDate* thisDate = ((TBHistoricQuote*)self.quotes[iter]).date;
    NSDate* nextDate = [[NSCalendar currentCalendar] dateByAddingUnit:NSCalendarUnitDay
                                                                   value:1
                                                                  toDate:thisDate
                                                                 options:0];
    NSDate* nextSeriesElementDate = ((TBHistoricQuote*)self.quotes[iter+1]).date;


    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];


    if ([nextDate compare:nextSeriesElementDate] == NSOrderedAscending ) {

        NSDateComponents *components = [calendar components:NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay
                                                   fromDate:nextDate
                                                     toDate:nextSeriesElementDate
                                                    options:0];

        [xAxis addExcludedTimePeriod:[[SChartTimePeriod alloc] initWithStart:nextDate andLength:[[SChartDateFrequency alloc] initWithDay:components.day]]];
    }

}

self.chart.xAxis = xAxis;
于 2015-05-08T07:59:35.777 回答