Shinobicharts crash (NSInvalidArgumentException)


#1

Hi,

I’m testing out Shinobicharts to see if it’s something we can use in the company (instead of using CorePlot). To test ShinobiControls i’m trying to recreate the graph below. I’m just getting started with Shinobicontrols (checked all the sample projects to get started).

Graph

But it seems i’m doing something wrong, i’m getting the following error:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDictionaryI sChartXValue]: unrecognized selector sent to instance 0x7f8da1c3b5e0'

My ShinobiCharts code:

-(void)GraphSettings
{
    NSLog(@"%@", [ShinobiCharts getInfo]);
    
    graph = [[ShinobiChart alloc] initWithFrame:self.GraphView.frame];
    
    //License key for ShinobiCharts
    graph.licenseKey = @"Not sharing :)";
    
    graph.datasource = self;
}

-(void)GraphAxisSettings
{
    //Set ranges
    SChartDateRange *xRange = [[SChartDateRange alloc] initWithDateMinimum:[self dateFromString:@"21-11-2014"] andDateMaximum:[self dateFromString:@"24-11-2014"]];
    SChartNumberRange *yRange = [[SChartNumberRange alloc] initWithMinimum:[NSNumber numberWithInt:0] andMaximum:[NSNumber numberWithInt:35]];
    
    //Set axis
    SChartDateTimeAxis *xAxis = [[SChartDateTimeAxis alloc] initWithRange:xRange];
    SChartNumberAxis *yAxis = [[SChartNumberAxis alloc] initWithRange:yRange];
   
    //Add axises to Graph
    graph.xAxis = xAxis;
    graph.yAxis = yAxis;
}

#pragma mark - Utility methods
- (NSDate*) dateFromString:(NSString*)date {
    static NSDateFormatter *dateFormatter;
    if (!dateFormatter) {
        dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat:@"dd-MM-yyyy"];
    }
    return [dateFormatter dateFromString:date];
}

#pragma mark - SChartDatasource methods
- (NSInteger)numberOfSeriesInSChart:(ShinobiChart *)chart
{
    return 3;
}

-(SChartSeries *)sChart:(ShinobiChart *)chart seriesAtIndex:(NSInteger)index
{
    SChartLineSeries *lineSeries = [[SChartLineSeries alloc] init];
    
    if(index == 0)
    {
        lineSeries.title = @"Totaal";
    
        //Style of this line
        SChartLineSeriesStyle *style = [[SChartLineSeriesStyle alloc] init];
        style.lineColor = [UIColor colorWithRed:0.141 green:0.765 blue:0.831 alpha:1.000];
        style.lineWidth = [NSNumber numberWithFloat:1.0];
        
        //Set point style of line
        SChartPointStyle *pStyle = [[SChartPointStyle alloc] init];
        pStyle.texture = [UIImage imageNamed:@"IPSS_GraphIcon"];
        
        style.pointStyle = pStyle;
        lineSeries.style = style;
    }
    
    if(index == 1)
    {
        lineSeries.title = @"Irritatie";
        
        //Style of this line
        SChartLineSeriesStyle *style = [[SChartLineSeriesStyle alloc] init];
        style.lineColor = [UIColor colorWithRed:0.000 green:0.294 blue:0.529 alpha:1.000];
        style.lineWidth = [NSNumber numberWithFloat:1.0];
        
        //Set point style of line
        SChartPointStyle *pStyle = [[SChartPointStyle alloc] init];
        pStyle.texture = [UIImage imageNamed:@"Irritatief_GraphIcon"];
        
        style.pointStyle = pStyle;
        lineSeries.style = style;
    }
    
    if(index == 2)
    {
        lineSeries.title = @"Obstructie";
        
        //Style of this line
        SChartLineSeriesStyle *style = [[SChartLineSeriesStyle alloc] init];
        style.lineColor = [UIColor colorWithRed:0.000 green:0.294 blue:0.529 alpha:1.000];
        style.lineWidth = [NSNumber numberWithFloat:1.0];
        
        //Set point style of line
        SChartPointStyle *pStyle = [[SChartPointStyle alloc] init];
        pStyle.texture = [UIImage imageNamed:@"Obstructief_GraphIcon"];
        
        style.pointStyle = pStyle;
        lineSeries.style = style;
    }
    
    return lineSeries;
}

- (NSInteger)sChart:(ShinobiChart *)chart numberOfDataPointsForSeriesAtIndex:(NSInteger)seriesIndex
{
    return [ipssScores count];
}

- (id<SChartData>)sChart:(ShinobiChart *)chart dataPointAtIndex:(NSInteger)dataIndex forSeriesAtIndex:(NSInteger)seriesIndex
{
    if(seriesIndex == 0)
    {
        return [[ipssScores objectAtIndex:dataIndex]objectForKey:@"score"];
        
    }
    else if(seriesIndex == 1)
    {
        return [[scoresi objectAtIndex:dataIndex]objectForKey:@"score"];
    }
    else
    {
        return [[scoreso objectAtIndex:dataIndex]objectForKey:@"score"];
    }
}

I checked if the arrays are filled with data, and thats happening so that couldn’t be the problem.


#2

Hmm it seems I forgot to add datapoints! But now a new error rises:

ShinobiCharts: Datapoint cannot be nil. (series 0, index 0)

DOH forgot to init the datapoints arrays

Here’s my new code:

-(void)viewDidAppear:(BOOL)animated
{
    [self GraphSettings];
    [self GraphAxisSettings];
    [self GraphDataPoints];
    
    [self.GraphView addSubview:graph];
}

-(void)GraphSettings
{
    graph = [[ShinobiChart alloc] initWithFrame:self.GraphView.frame];
    
    //License key for ShinobiCharts
    graph.licenseKey = @"Not sharing :)";
    
    graph.datasource = self;
}

-(void)GraphAxisSettings
{
    //Set ranges
    SChartDateRange *xRange = [[SChartDateRange alloc] initWithDateMinimum:minDate andDateMaximum:maxDate];
    SChartNumberRange *yRange = [[SChartNumberRange alloc] initWithMinimum:[NSNumber numberWithInt:0] andMaximum:[NSNumber numberWithInt:35]];
    
    //Set axis
    SChartDateTimeAxis *xAxis = [[SChartDateTimeAxis alloc] initWithRange:xRange];
    SChartNumberAxis *yAxis = [[SChartNumberAxis alloc] initWithRange:yRange];
   
    //Add axises to Graph
    graph.xAxis = xAxis;
    graph.yAxis = yAxis;
}

-(void)GraphDataPoints
{
    NSLog(@"Adding datapoints");
    for(int x = 0; x < [scoresi count]; x++)
    {
        [ipssscoresDataPoints addObject:[self dataPointForDate:[[ipssScores objectAtIndex:x]objectForKey:@"date"] andValue:[[ipssScores objectAtIndex:x]objectForKey:@"score"]]];
        [scoresiDataPoints addObject:[self dataPointForDate:[[scoresi objectAtIndex:x]objectForKey:@"date"] andValue:[[scoresi objectAtIndex:x]objectForKey:@"score"]]];
        [scoresoDataPoints addObject:[self dataPointForDate:[[scoreso objectAtIndex:x]objectForKey:@"date"] andValue:[[scoreso objectAtIndex:x]objectForKey:@"score"]]];
    }
}

#pragma mark - Utility methods
- (NSDate*) dateFromString:(NSString*)date {
    static NSDateFormatter *dateFormatter;
    if (!dateFormatter) {
        dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat:@"dd-MM-yyyy"];
    }
    
    NSLog(@"date: %@", date);
    
    return [dateFormatter dateFromString:date];
}

-(SChartDataPoint *)dataPointForDate:(NSDate *)date andValue:(NSNumber *)value
{
    SChartDataPoint *dataPoint = [SChartDataPoint new];
    dataPoint.xValue = @"21-11-2014";
    dataPoint.yValue = value;
    return dataPoint;
}

#pragma mark - SChartDatasource methods
- (NSInteger)numberOfSeriesInSChart:(ShinobiChart *)chart
{
    return 3;
}

-(SChartSeries *)sChart:(ShinobiChart *)chart seriesAtIndex:(NSInteger)index
{
    SChartLineSeries *lineSeries = [[SChartLineSeries alloc] init];
    
    if(index == 0)
    {
        lineSeries.title = @"Totaal";
    
        //Style of this line
        SChartLineSeriesStyle *style = [[SChartLineSeriesStyle alloc] init];
        style.lineColor = [UIColor colorWithRed:0.141 green:0.765 blue:0.831 alpha:1.000];
        style.lineWidth = [NSNumber numberWithFloat:1.0];
        
        //Set point style of line
        SChartPointStyle *pStyle = [[SChartPointStyle alloc] init];
        pStyle.texture = [UIImage imageNamed:@"IPSS_GraphIcon"];
        
        style.pointStyle = pStyle;
        lineSeries.style = style;
    }
    
    if(index == 1)
    {
        lineSeries.title = @"Irritatie";
        
        //Style of this line
        SChartLineSeriesStyle *style = [[SChartLineSeriesStyle alloc] init];
        style.lineColor = [UIColor colorWithRed:0.000 green:0.294 blue:0.529 alpha:1.000];
        style.lineWidth = [NSNumber numberWithFloat:1.0];
        
        //Set point style of line
        SChartPointStyle *pStyle = [[SChartPointStyle alloc] init];
        pStyle.texture = [UIImage imageNamed:@"Irritatief_GraphIcon"];
        
        style.pointStyle = pStyle;
        lineSeries.style = style;
    }
    
    if(index == 2)
    {
        lineSeries.title = @"Obstructie";
        
        //Style of this line
        SChartLineSeriesStyle *style = [[SChartLineSeriesStyle alloc] init];
        style.lineColor = [UIColor colorWithRed:0.000 green:0.294 blue:0.529 alpha:1.000];
        style.lineWidth = [NSNumber numberWithFloat:1.0];
        
        //Set point style of line
        SChartPointStyle *pStyle = [[SChartPointStyle alloc] init];
        pStyle.texture = [UIImage imageNamed:@"Obstructief_GraphIcon"];
        
        style.pointStyle = pStyle;
        lineSeries.style = style;
    }
    
    return lineSeries;
}

- (NSInteger)sChart:(ShinobiChart *)chart numberOfDataPointsForSeriesAtIndex:(NSInteger)seriesIndex
{
    NSLog(@"Numbers of datapoints: %lu", (unsigned long)[ipssScores count]);
    return [ipssScores count];
}

- (id<SChartData>)sChart:(ShinobiChart *)chart dataPointAtIndex:(NSInteger)dataIndex forSeriesAtIndex:(NSInteger)seriesIndex
{
    NSLog(@"Series: %ld", (long)seriesIndex);
    if(seriesIndex == 0)
    {
        return ipssscoresDataPoints[dataIndex];
    }
    else if(seriesIndex == 1)
    {
        return scoresiDataPoints[dataIndex];
    }
    else
    {
        return scoresoDataPoints[dataIndex];
    }
}

#3

Greetings Program!

What values are you using for the data?

    NSMutableArray *ipssScores;
    NSMutableArray *scoresi;
    NSMutableArray *scoreso;

    Min and Max dates.

Here’s what I got with your code (I replaced the code in the Labelled Datapoints sampe app) and the values I guessed at.

Wg

https://www.dropbox.com/s/ffmd85bbwwkxirn/screenshot.png?dl=0

//
// ViewController.m
// Labelled Datapoints
//
// Created by Thomas Kelly on 27/11/2013.
// Copyright (c) 2013 Scott Logic. All rights reserved.
//

#import "ViewController.h"
#import <QuartzCore/QuartzCore.h>

@implementation ViewController
{
    NSMutableArray *scoresiDataPoints;
    NSMutableArray *scoresoDataPoints;
    NSMutableArray *ipssscoresDataPoints;
    NSArray *ipssScores;
    NSArray *scoresi;
    NSArray *scoreso;
    ShinobiChart *graph;
}

-(void)viewDidAppear:(BOOL)animated
{
    [self GraphSettings];
    [self GraphAxisSettings];
    [self GraphDataPoints];
    
    [self.view addSubview:graph];
}

-(void)GraphSettings
{
    graph = [[ShinobiChart alloc] initWithFrame:self.view.frame];
    
    //License key for ShinobiCharts
    graph.licenseKey = @"Not sharing :)";
    
    graph.datasource = self;
}

-(void)GraphAxisSettings
{
    //Set ranges
    SChartDateRange *xRange = [[SChartDateRange alloc] initWithDateMinimum:[self dateFromString:@"24/07/2014"] andDateMaximum:[self dateFromString:@"28/7/2014"]];
    SChartNumberRange *yRange = [[SChartNumberRange alloc] initWithMinimum:[NSNumber numberWithInt:0] andMaximum:[NSNumber numberWithInt:35]];
    
    //Set axis
    SChartDateTimeAxis *xAxis = [[SChartDateTimeAxis alloc] initWithRange:xRange];
    SChartNumberAxis *yAxis = [[SChartNumberAxis alloc] initWithRange:yRange];
    
    //Add axises to Graph
    graph.xAxis = xAxis;
    graph.yAxis = yAxis;
}

-(void)GraphDataPoints
{
    NSLog(@"Adding datapoints");
    scoresiDataPoints = [[NSMutableArray alloc] init];
    scoresoDataPoints = [[NSMutableArray alloc] init];
    ipssscoresDataPoints = [[NSMutableArray alloc] init];
    ipssScores = [[NSArray alloc] init];
    scoresi = [[NSArray alloc] init];
    scoreso = [[NSArray alloc] init];
    
    ipssScores = @[
                @{ @"date": [self dateFromString:@"24/07/2014"], @"score": @12 },
                @{ @"date": [self dateFromString:@"25/07/2014"], @"score": @20 },
                @{ @"date": [self dateFromString:@"25/07/2014"], @"score": @23 },
                @{ @"date": [self dateFromString:@"26/07/2014"], @"score": @15 },
                @{ @"date": [self dateFromString:@"28/07/2014"], @"score": @16 }
                ];
    
    scoresi = @[
               @{ @"date": [self dateFromString:@"24/07/2014"], @"score": @5 },
               @{ @"date": [self dateFromString:@"25/07/2014"], @"score": @7 },
               @{ @"date": [self dateFromString:@"25/07/2014"], @"score": @5 },
               @{ @"date": [self dateFromString:@"26/07/2014"], @"score": @4 },
               @{ @"date": [self dateFromString:@"28/07/2014"], @"score": @6 }
               ];
    
    scoreso = @[
                @{ @"date": [self dateFromString:@"24/07/2014"], @"score": @9 },
                @{ @"date": [self dateFromString:@"25/07/2014"], @"score": @10 },
                @{ @"date": [self dateFromString:@"25/07/2014"], @"score": @20 },
                @{ @"date": [self dateFromString:@"26/07/2014"], @"score": @8 },
                @{ @"date": [self dateFromString:@"28/07/2014"], @"score": @9 }
                ];
    
    for(int x = 0; x < [scoresi count]; x++)
    {
        [ipssscoresDataPoints addObject:[self dataPointForDate:[[ipssScores objectAtIndex:x]objectForKey:@"date"] andValue:[[ipssScores objectAtIndex:x]objectForKey:@"score"]]];
        [scoresiDataPoints addObject:[self dataPointForDate:[[scoresi objectAtIndex:x]objectForKey:@"date"] andValue:[[scoresi objectAtIndex:x]objectForKey:@"score"]]];
        [scoresoDataPoints addObject:[self dataPointForDate:[[scoreso objectAtIndex:x]objectForKey:@"date"] andValue:[[scoreso objectAtIndex:x]objectForKey:@"score"]]];
    }
}

#pragma mark - Utility methods
- (NSDate*) dateFromString:(NSString*)date {
    static NSDateFormatter *dateFormatter;
    if (!dateFormatter) {
        dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat:@"dd-MM-yyyy"];
    }
    
    NSLog(@"date: %@", date);
    
    return [dateFormatter dateFromString:date];
}

-(SChartDataPoint *)dataPointForDate:(NSDate *)date andValue:(NSNumber *)value
{
    SChartDataPoint *dataPoint = [SChartDataPoint new];
    dataPoint.xValue = date;
    dataPoint.yValue = value;
    return dataPoint;
}

#pragma mark - SChartDatasource methods
- (NSInteger)numberOfSeriesInSChart:(ShinobiChart *)chart
{
    return 3;
}

-(SChartSeries *)sChart:(ShinobiChart *)chart seriesAtIndex:(NSInteger)index
{
    SChartLineSeries *lineSeries = [[SChartLineSeries alloc] init];
    
    if(index == 0)
    {
        lineSeries.title = @"Totaal";
        
        //Style of this line
        SChartLineSeriesStyle *style = [[SChartLineSeriesStyle alloc] init];
        style.lineColor = [UIColor colorWithRed:0.141 green:0.765 blue:0.831 alpha:1.000];
        style.lineWidth = [NSNumber numberWithFloat:1.0];
        
        //Set point style of line
        SChartPointStyle *pStyle = [[SChartPointStyle alloc] init];
        pStyle.texture = [UIImage imageNamed:@"IPSS_GraphIcon"];
        
        style.pointStyle = pStyle;
        lineSeries.style = style;
    }
    
    if(index == 1)
    {
        lineSeries.title = @"Irritatie";
        
        //Style of this line
        SChartLineSeriesStyle *style = [[SChartLineSeriesStyle alloc] init];
        style.lineColor = [UIColor colorWithRed:0.000 green:0.294 blue:0.529 alpha:1.000];
        style.lineWidth = [NSNumber numberWithFloat:1.0];
        
        //Set point style of line
        SChartPointStyle *pStyle = [[SChartPointStyle alloc] init];
        pStyle.texture = [UIImage imageNamed:@"Irritatief_GraphIcon"];
        
        style.pointStyle = pStyle;
        lineSeries.style = style;
    }
    
    if(index == 2)
    {
        lineSeries.title = @"Obstructie";
        
        //Style of this line
        SChartLineSeriesStyle *style = [[SChartLineSeriesStyle alloc] init];
        style.lineColor = [UIColor colorWithRed:0.000 green:0.294 blue:0.529 alpha:1.000];
        style.lineWidth = [NSNumber numberWithFloat:1.0];
        
        //Set point style of line
        SChartPointStyle *pStyle = [[SChartPointStyle alloc] init];
        pStyle.texture = [UIImage imageNamed:@"Obstructief_GraphIcon"];
        
        style.pointStyle = pStyle;
        lineSeries.style = style;
    }
    
    return lineSeries;
}

- (NSInteger)sChart:(ShinobiChart *)chart numberOfDataPointsForSeriesAtIndex:(NSInteger)seriesIndex
{
    NSLog(@"Numbers of datapoints: %lu", (unsigned long)[ipssScores count]);
    return [ipssScores count];
}

- (id<SChartData>)sChart:(ShinobiChart *)chart dataPointAtIndex:(NSInteger)dataIndex forSeriesAtIndex:(NSInteger)seriesIndex
{
    NSLog(@"Series: %ld", (long)seriesIndex);
    if(seriesIndex == 0)
    {
        return ipssscoresDataPoints[dataIndex];
    }
    else if(seriesIndex == 1)
    {
        return scoresiDataPoints[dataIndex];
    }
    else
    {
        return scoresoDataPoints[dataIndex];
    }
}

@end

#4

HI,

Thanks for the reply! The values in the arrays are @Score between 0 and 35 and @Date NSDate object. The min and max date are the min date for the graph and the max date for the graph. On the screen before the graph shows the user can select an amount of datapoints to show in the graph. So I need to calculate the min date and the max date for the datapoints.

I’ve added some stuff and it seems to be working quite well. I only can’t seem to get the x-axis dates right. I get the following warning:

ShinobiCharts: Ignoring range with 0.000000 span
From: SChartDateTimeAxis at 0x7ff4a09c7ba0, axisRange = { 0.000000, 1.000000 }, defaultRange = { 2014-11-21 08:43:11 +0000, 2014-11-21 08:43:11 +0000 }, maxRange = { 1970-01-01 00:00:00 +0000, 2014-11-21 08:43:11 +0000 }

I guess it’s because sometimes the user can select datapoints for the same date.

Code:

@interface OverViewController () <SChartDatasource, SChartDelegate>
{
    NSMutableArray *scoresi;
    NSMutableArray *scoreso;
    NSMutableArray *ipssScores;
    NSMutableArray *newData;
    NSMutableArray *TableScores;
    NSMutableArray *BotherScores;
    
    NSMutableArray *scoresiDataPoints;
    NSMutableArray *scoresoDataPoints;
    NSMutableArray *ipssscoresDataPoints;
    
    NSDateFormatter *dateFormat;
    
    NSDate *minDate,
            *maxDate;
    
    ShinobiChart *graph;
    
    int maxNumber;
}

@end

@implementation OverViewController

@synthesize events;


- (void)viewDidLoad {
    [super viewDidLoad];
}

-(void)viewWillAppear:(BOOL)animated
{
    self.title = NSLocalizedString(@"Overzicht", @"");
    [self.barButtonAction setTintColor:[UIColor whiteColor]];
    
    scoresi = [NSMutableArray new];
    scoreso = [NSMutableArray new];
    ipssScores = [NSMutableArray new];
    TableScores = [NSMutableArray new];
    BotherScores = [NSMutableArray new];
    
    maxNumber = 0;
    minDate = [NSDate date];
    maxDate = [NSDate date];
    
    for (Event *ev in events)
    {
        int irritative = 0;
        int obstructive = 0;
        
        NSMutableArray *eventQuestions = [[NSMutableArray alloc]initWithArray:[[ev recorded] allObjects]];
        for (RecordedQuestions *rquestion in eventQuestions)
        {
            Answers *answer = [rquestion answers];
            
            switch ([[rquestion questionNumber]intValue]) {
                case 1:
                    obstructive = obstructive + [[answer points]intValue];
                    break;
                case 2:
                    irritative = irritative + [[answer points]intValue];
                    break;
                case 3:
                    irritative = irritative + [[answer points]intValue];
                    break;
                case 4:
                    irritative = irritative + [[answer points]intValue];
                    break;
                case 5:
                    obstructive = obstructive + [[answer points]intValue];
                    break;
                case 6:
                    obstructive = obstructive + [[answer points]intValue];
                    break;
                case 7:
                    irritative = irritative + [[answer points]intValue];
                    break;
                    
                case 8: [BotherScores addObject:[NSNumber numberWithInt:[[answer points] intValue]]];
                    break;
            }
        }
        
        [scoreso addObject:@{@"score":[NSNumber numberWithInt:obstructive],@"date":[ev finished]}];
        [scoresi addObject:@{@"score":[NSNumber numberWithInt:irritative],@"date":[ev finished]}];
        [ipssScores addObject:@{@"score":[NSNumber numberWithInt:(irritative + obstructive)],@"date":[ev finished]}];
        
        [TableScores addObject:[NSNumber numberWithInt:irritative]];
        [TableScores addObject:[NSNumber numberWithInt:obstructive]];
        [TableScores addObject:[NSNumber numberWithInt:(irritative + obstructive)]];
        
        if (obstructive>maxNumber) maxNumber = obstructive+1;
        if (irritative>maxNumber) maxNumber = irritative+1;
        
        if ([ev finished]<minDate) minDate = [ev finished];
        if ([ev finished]<maxDate) maxDate = [ev finished];
    }
    
    [self.BottomViewClass TableSettings:TableScores];
    
    dateFormat = [[NSDateFormatter alloc] init];
    [dateFormat setDateFormat:@"dd-MM-yy"];
}

-(void)viewDidAppear:(BOOL)animated
{
    [self.BottomViewClass CreateTableObjects:BotherScores];
    
    [self GraphSettings];
    [self GraphAxisSettings];
    [self GraphDataPoints];
    
    [self.GraphView addSubview:graph];
}

-(void)GraphSettings
{
    graph = [[ShinobiChart alloc] initWithFrame:CGRectMake(self.GraphView.frame.origin.x,
                                                           self.GraphView.frame.origin.y + 10,
                                                           self.GraphView.frame.size.width - 10,
                                                           self.GraphView.frame.size.height - 10)];
    
    
    //License key for ShinobiCharts
    graph.licenseKey = @"Not sharing";
    
    [graph setBackgroundColor:[UIColor whiteColor]];
    
    graph.datasource = self;
    graph.delegate = self;
}


-(void)GraphAxisSettings
{
    NSLog(@"MinDate: %@", minDate);
    NSLog(@"MaxDate: %@", maxDate);
    
    //Set axis
    SChartDateTimeAxis *xAxis = [[SChartDateTimeAxis alloc] initWithRange:[[SChartDateRange alloc] initWithDateMinimum:minDate andDateMaximum:maxDate]];
    SChartNumberAxis *yAxis = [[SChartNumberAxis alloc] initWithRange:[[SChartNumberRange alloc] initWithMinimum:@0 andMaximum:@35]];
    
    //xAxis style
    SChartAxisStyle *xStyle = [[SChartAxisStyle alloc] init];
    [xStyle setLineColor:[UIColor colorWithRed:0.902 green:0.973 blue:0.980 alpha:1.000]];
    [xStyle setLineWidth:[NSNumber numberWithFloat:1.0f]];
    
    //yAxis style
    SChartAxisStyle *yStyle = [[SChartAxisStyle alloc] init];
    [yStyle setLineColor:[UIColor colorWithRed:0.902 green:0.973 blue:0.980 alpha:1.000]];
    [yStyle setLineWidth:[NSNumber numberWithFloat:1.0f]];
    
    //Tick style
    SChartTickStyle *tickStyle = [[SChartTickStyle alloc] init];
    [tickStyle setLabelColor:[UIColor colorWithRed:0.000 green:0.294 blue:0.529 alpha:1.000]];
    [tickStyle setLineColor:[UIColor colorWithRed:0.902 green:0.973 blue:0.980 alpha:1.000]];
    [tickStyle setLineWidth:[NSNumber numberWithFloat:1.0f]];
    
    [xStyle setMajorTickStyle:tickStyle];
    [yStyle setMajorTickStyle:tickStyle];
    
    //Tick frequency
    [yAxis setMinorTickFrequency:[NSNumber numberWithInt:1]];
    
    //Major Gridline style
    SChartMajorGridlineStyle *gStyle = [[SChartMajorGridlineStyle alloc] init];
    [gStyle setLineColor:[UIColor colorWithRed:0.902 green:0.973 blue:0.980 alpha:1.000]];
    gStyle.showMajorGridLines = YES;
    
    yStyle.majorGridLineStyle = gStyle;
    
    xAxis.style = xStyle;
    yAxis.style = yStyle;
    
    //Add axises to Graph
    graph.xAxis = xAxis;
    graph.yAxis = yAxis;
}

-(void)GraphDataPoints
{
    ipssscoresDataPoints = [[NSMutableArray alloc] init];
    scoresiDataPoints = [[NSMutableArray alloc] init];
    scoresoDataPoints = [[NSMutableArray alloc] init];
    
    for(int x = 0; x < [scoresi count]; x++)
    {
        [ipssscoresDataPoints addObject:[self dataPointForDate:[[ipssScores objectAtIndex:x]objectForKey:@"date"] andValue:[[ipssScores objectAtIndex:x]objectForKey:@"score"]]];
        [scoresiDataPoints addObject:[self dataPointForDate:[[scoresi objectAtIndex:x]objectForKey:@"date"] andValue:[[scoresi objectAtIndex:x]objectForKey:@"score"]]];
        [scoresoDataPoints addObject:[self dataPointForDate:[[scoreso objectAtIndex:x]objectForKey:@"date"] andValue:[[scoreso objectAtIndex:x]objectForKey:@"score"]]];
    }
}

#pragma mark - Utility methods
-(SChartDataPoint *)dataPointForDate:(NSDate *)date andValue:(NSNumber *)value
{
    SChartDataPoint *dataPoint = [SChartDataPoint new];
    dataPoint.xValue = [dateFormat stringFromDate:date];
    dataPoint.yValue = value;
    return dataPoint;
}

#pragma mark - SChartDelegate methods

-(void)sChart:(ShinobiChart *)chart alterTickMark:(SChartTickMark *)tickMark beforeAddingToAxis:(SChartAxis *)axis
{
    if(axis == chart.yAxis)
    {
        if(tickMark.value != 0.f && tickMark.value != 7.f && tickMark.value != 19.f && tickMark.value != 35.f)
        {
            tickMark.tickLabel.text = @"";
        }
    }
}

#pragma mark - SChartDatasource methods
- (NSInteger)numberOfSeriesInSChart:(ShinobiChart *)chart
{
    return 3;
}

-(NSArray *)sChart:(ShinobiChart *)chart majorTickValuesForAxis:(SChartAxis *)axis
{
    if(axis == chart.yAxis)
    {
        return [NSArray arrayWithObjects:@0, @7, @19, @35, nil];
    }
    else
    {
        return nil;
    }
}

-(SChartSeries *)sChart:(ShinobiChart *)chart seriesAtIndex:(NSInteger)index
{
    SChartLineSeries *lineSeries = [[SChartLineSeries alloc] init];
    
    if(index == 0)
    {
        lineSeries.title = @"Totaal";
    
        //Style of this line
        SChartLineSeriesStyle *style = [[SChartLineSeriesStyle alloc] init];
        style.lineColor = [UIColor colorWithRed:0.141 green:0.765 blue:0.831 alpha:1.000];
        style.lineWidth = [NSNumber numberWithFloat:1.0];
        
        //Set point style of line
        SChartPointStyle *pStyle = [[SChartPointStyle alloc] init];
        pStyle.texture = [UIImage imageNamed:@"IPSS_GraphIcon"];
        [pStyle setRadius:[NSNumber numberWithFloat:20.0f]];
        
        style.pointStyle = pStyle;
        lineSeries.style = style;
    }
    
    if(index == 1)
    {
        lineSeries.title = @"Irritatie";
        
        //Style of this line
        SChartLineSeriesStyle *style = [[SChartLineSeriesStyle alloc] init];
        style.lineColor = [UIColor colorWithRed:0.000 green:0.294 blue:0.529 alpha:1.000];
        style.lineWidth = [NSNumber numberWithFloat:1.0];
        
        //Set point style of line
        SChartPointStyle *pStyle = [[SChartPointStyle alloc] init];
        pStyle.texture = [UIImage imageNamed:@"Irritatief_GraphIcon"];
        [pStyle setRadius:[NSNumber numberWithFloat:20.0f]];
        
        style.pointStyle = pStyle;
        lineSeries.style = style;
    }
    
    if(index == 2)
    {
        lineSeries.title = @"Obstructie";
        
        //Style of this line
        SChartLineSeriesStyle *style = [[SChartLineSeriesStyle alloc] init];
        style.lineColor = [UIColor colorWithRed:0.000 green:0.294 blue:0.529 alpha:1.000];
        style.lineWidth = [NSNumber numberWithFloat:1.0];
        
        //Set point style of line
        SChartPointStyle *pStyle = [[SChartPointStyle alloc] init];
        pStyle.texture = [UIImage imageNamed:@"Obstructief_GraphIcon"];
        [pStyle setRadius:[NSNumber numberWithFloat:20.0f]];
        
        style.pointStyle = pStyle;
        lineSeries.style = style;
    }
    
    return lineSeries;
}

- (NSInteger)sChart:(ShinobiChart *)chart numberOfDataPointsForSeriesAtIndex:(NSInteger)seriesIndex
{
    return [ipssScores count];
}

- (id<SChartData>)sChart:(ShinobiChart *)chart dataPointAtIndex:(NSInteger)dataIndex forSeriesAtIndex:(NSInteger)seriesIndex
{
    if(seriesIndex == 0)
    {
        return ipssscoresDataPoints[dataIndex];
    }
    else if(seriesIndex == 1)
    {
        return scoresiDataPoints[dataIndex];
    }
    else
    {
        return scoresoDataPoints[dataIndex];
    }
}

@end

#5

Hi Tripwire,

Regarding your issue with getting the X-Axis dates right, you can add a simple check to see if the min and max dates are the same to create an axis without a date range to provide the default range given by your chart using the data you’ve supplied.

If the default range doesn’t meet your requirements you can easily create your own range with custom dates surrounding your datapoints.

Let me know if you have any questions.

Kind regards,
Andrew Polkinghorn