Use NSDate for x-axis


Is there a way to use the NSDate to chart data and use date labels for the x-axis?


Yes there is. Simply create a chart with a date x-axis:

[[ShinobiChart alloc] initWithFrame:frame

Then within your data-source return the required NSDate values:

- (NSArray *)sChart:(ShinobiChart *)chart dataPointsForSeriesAtIndex:(int)seriesIndex
    NSMutableArray *datapointArray = [NSMutableArray array];

    //iterate over your data
    for (MyDataPointType *tdp in _yData) {
        SChartDataPoint *dp = [SChartDataPoint new];
        dp.xValue = // your NSDate goes here
        dp.yValue = // your number that relates to the date goes here
        [datapointArray addObject:dp];
    return [NSArray arrayWithArray:datapointArray];


Hi Colin and anyone who can help me.

Problem: I’m trying to get my xAxis to show on the month from the NSdate that I obtained.

I read throught serveral thread and tried the methods but none is of any help. I understand that I should post a question when I hit the wall and I have just hit it :frowning: been trying out this for a few days.

Here are the resources I tried.

This is my current code for the chart


The chart itself is also set to the follow:

utilitiesBarChart = [[ShinobiChartalloc] initWithFrame:CGRectInset(cell.bounds, margin, margin) withPrimaryXAxisType: SChartAxisTypeDateTime withPrimaryYAxisType:SChartAxisTypeNumber];

And this is my code for xvalue


This is the error


My chart continue to show in epoch time :frowning:


any help would be awesome :smiley:

Thank you people


Hi bosslee,

It looks like the xAxis you are creating is an SChartNumberAxis. This axis type isn’t designed to show/format dates or times, so it’s likely you’re ending up in a situation where the chart shows the number of seconds since 1970. This probably explains the error message too - the number axis is looking for a number formatter, not a date formatter.

Try using an SChartDateTimeAxis in place of you number axis and let us know how you get on.  :laughing: