Search code examples
iosshinobi

Setting x-axis of bar chart to show month


Hi everyone.

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

Desired output: Under each bar, it will show "Jan", "Feb", "Mar" etc... according to the event time.

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 :( been trying out this for a few days.

Here are the resources I tried.

  • http://www.shinobicontrols.com/forum/shinobicontrols/2013/12/updating-date-format-on-an-axis-fails-except-on-chart-creation
  • http://www.shinobicontrols.com/forum/shinobicontrols/2014/7/x-axis-with-formatted-dates
  • http://stackoverflow.com/questions/13688920/how-to-change-the-xaxis-used-on-my-chart-shinobicharts

This is my current code for the chart

intraix%20%E2%80%94%20UtilitiesDashboardTableViewController.m%20%E2%80%94%20Edited

The chart itself is also set to the follow:

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

And this is my code for xvalue

intraix%20%E2%80%94%20UtilitiesDashboardTableViewController.m%20%E2%80%94%20Edited

This is the error

intraix%20%E2%80%94%20UtilitiesDashboardTableViewController.m

My chart continue to show in epoch time :(

intraix%20%E2%80%94%20UtilitiesDashboardTableViewController.m%20and%20iOS%20Simulator%20-%20iPhone%20Retina%20(4-inch)%20/%20iOS%207.1%20(11D167)

any help would be awesome :D

Thank you people


Solution

  • I have a similar barchart with a date/time x-axis. Here is how I created the x-axis to show dates like "Jun 3":

        // x-axis
        _xAxis = [[SChartDateTimeAxis alloc] init];
        _xAxis.style.lineColor = [UIColor colorWithWhite:0.5f alpha:1.0f];
        _xAxis.style.lineWidth = @1;
        _xAxis.style.majorTickStyle.showLabels = YES;
        _xAxis.style.majorTickStyle.labelFont = [UIFont systemFontOfSize:9];
        _xAxis.style.majorTickStyle.labelColor = [UIColor colorWithWhite:0.5f alpha:1.0f];
        _xAxis.style.majorTickStyle.showTicks = YES;
        _xAxis.style.majorTickStyle.lineWidth = @(1);
        _xAxis.style.majorTickStyle.lineColor = COLOR_BACKGROUND;
    
        _xAxis.labelFormatString = @"MMM d";
    

    You can optionally implement the delegate to do additional formatting (like making the string uppercase in my case):

    -(void)sChart:(ShinobiChart *)chart alterTickMark:(SChartTickMark *)tickMark beforeAddingToAxis:(SChartAxis *)axis {
        tickMark.tickLabel.text = [tickMark.tickLabel.text uppercaseString];
    }