views:

386

answers:

2

Hi,

I am looking for an graph library for the iPhone which allowes me to set texts as values on the X-axis. After a quick look at core-plot, it seems its uncapable to do so. I stumbled over s7graphview but can't seem to get it working.

Is there anyone who did got it working, and might be able to share it with me? Or any links to some examples? It think my brain just shut off cause its late, but I am giving it a try ;)

Best regards, Paul Peelen

+1  A: 

Hi buddy,

You can change the label names as

-(NSArray *)newAxisLabelsAtLocations:(NSArray *)locations
{
    NSMutableArray *newLabels = [[NSMutableArray alloc] initWithCapacity:locations.count];
    for ( NSDecimalNumber *tickLocation in locations ) {
        NSString *labelString = [self.labelFormatter stringForObjectValue:tickLocation];
        CPAxisLabel *newLabel = [[CPAxisLabel alloc] initWithText:[NSString stringWithFormat:@"Day %@",labelString] textStyle:self.labelTextStyle];
     //[newLabel setTextColor:[CPColor whiteColor]];
        newLabel.tickLocation = [tickLocation decimalValue];
        newLabel.rotation = self.labelRotation;
     switch ( self.tickDirection ) {
      case CPSignNone:
       newLabel.offset = self.labelOffset + self.majorTickLength / 2.0f;
       break;
      case CPSignPositive:
      case CPSignNegative:
       newLabel.offset = self.labelOffset + self.majorTickLength;
       break;
     }
        [newLabels addObject:newLabel];
        [newLabel release];
    }
    return newLabels;
}

in the CPAxis.m in core-plot

Hope this helps... ;)

Madhup
allright... but I still have the following errors:error: incompatible type for argument 1 of 'setMajorIntervalLength:'error: request for member 'axisLabelOffset' in something not a structure or unionerror: incompatible type for argument 1 of 'setMajorIntervalLength:'error: request for member 'axisLabelOffset' in something not a structure or unionerror: request for member 'bounds' in something not a structure or unionerror: request for member 'defaultPlotSymbol' in something not a structure or unionerror: request for member 'bounds' in something not a structure or union:(
Paul Peelen
Added an new question for just those problems: http://stackoverflow.com/questions/1890207/coreplot-problems
Paul Peelen
+2  A: 

Core Plot does indeed support custom tick labels on the X axis: alt text

To produce these custom labels, you just need to set the labeling policy of the X axis to CPAxisLabelingPolicyNone and provide your own. For example, you can do the following to replicate the above drawing (in the Core Plot iPhone test application):

x.labelRotation = M_PI/4;
x.labelingPolicy = CPAxisLabelingPolicyNone;
NSArray *customTickLocations = [NSArray arrayWithObjects:[NSDecimalNumber numberWithInt:1], [NSDecimalNumber numberWithInt:5], [NSDecimalNumber numberWithInt:10], [NSDecimalNumber numberWithInt:15], nil];
NSArray *xAxisLabels = [NSArray arrayWithObjects:@"Label A", @"Label B", @"Label C", @"Label D", @"Label E", nil];
NSUInteger labelLocation = 0;
NSMutableArray *customLabels = [[NSMutableArray alloc] initWithCapacity:[xAxisLabels count]];
for (NSNumber *tickLocation in customTickLocations)
{
 CPAxisLabel *newLabel = [[CPAxisLabel alloc] initWithText: [xAxisLabels objectAtIndex:labelLocation++] textStyle:x.labelTextStyle];
 newLabel.tickLocation = [tickLocation decimalValue];
 newLabel.offset = x.labelOffset + x.majorTickLength;
 newLabel.rotation = M_PI/4;
 [customLabels addObject:newLabel];
 [newLabel release];
}

x.axisLabels =  [NSSet setWithArray:customLabels];

There's no need to subclass CPAxis to add these labels.

Brad Larson
Thanks brad for this great help. May be core-plot will be more helpful for we like newBees, if we get the updated tutorial for some more enhanced functionalities, if we get the picture shown by you in the tutorial, it will be of great help
Madhup
Yes, we need to have some better documentation, but unfortunately the framework is changing fast enough that it might be difficult to keep up to date. We're working on pulling together a stable release, and walkthrough documentation would be part of that package. Also note that this tutorial was written by a third party.
Brad Larson