iOS:ShinobiChart:持续显示不连续数据

时间:2015-05-08 07:12:23

标签: ios shinobi

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

有人知道如何让它显示持续?在文档中找不到它...... enter image description here

1 个答案:

答案 0 :(得分:0)

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

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

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;