Search code examples
iosshinobi

iOS: ShinobiChart: Continious display for discontinuous data


I'm using ShinobiChart to draw candlestick stock chart. My data is discontinuous, so that there will gaps on chart.

Anybody knows how can I make it show continuously? Cannot find it in documentation...enter image description here


Solution

  • Ok, I have found it. For your reference: Instead of adding SChartDateTimeAxis you instead should add SChartDiscontiniousDateTimeAxis.

    Then for any gap in dataSeries you have to explicitly exclude time period with addExcludedTimePeriod:. (You can do it my checking whether next day is the same a next date in the 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;