Michael Young
Michael Young

Reputation: 414

Core-Plot: x-axis labels as yearly quarters

I have plots where the x-axis is defined as a number of yearly quarters as follows:

1978.1 1978.2 1978.3 1978.4 1979.1 1979.2 etc

I just want to map the object numbers of an array of quarterly dates (NSMutableArray * yyyyQ) to the points along the x-axis that are 0, 1, 2, 3, etc. In other words, 0 is 1978.1, 1 is 1978.2, 2 is 1978.3, etc. Seems like a simple task, but using custom labels seems like overkill and NSDateFormatter doesn't seem suited to yearly quarters because the length of quarters varies (with or without a leap year).

In my simple-minded approach, the answer would be something like this:

x.labelTextStyle = axisTitleTextStyle;
x.labelRotation = M_PI/2;
x.axisLabels = [NSSet setWithArray:yyyyQ];

Upvotes: 2

Views: 357

Answers (1)

Eric Skroch
Eric Skroch

Reputation: 27381

You'll need to create a custom number formatter to do that. Look at the source code for CPTTimeFormatter to see the basic structure needed. You'll need to write a -stringForObjectValue: method that converts your coded numbers into the desired format.

Upvotes: 1

Related Questions