I'm a beginner in core-plot. I want to use core-plot in my app, to display datas that I get from a distant database. I can put the datas I want to use in Arrays, but I don't know how to use this Arrays to modify my graphic.
I have watch on the core-plot google site (http://code.google.com/p/core-plot/) and on stack overflow but I couldn't find something that help me.
This is what the graphic is displaying, and I want to use my Arrays to insert my datas in the graph-plot.
EDITED:
-(NSNumber *)numberForPlot:(CPPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index
{
NSDecimalNumber *num = nil;
if ( [plot isKindOfClass:[CPBarPlot class]] ) {
switch ( fieldEnum ) {
case CPBarPlotFieldBarLocation:
num = (NSDecimalNumber *)[NSDecimalNumber numberWithUnsignedInteger:index];
break;
case CPBarPlotFieldBarLength:
//num = (NSDecimalNumber *)[NSDecimalNumber numberWithUnsignedInteger:(index+10)+15];
//num = [NSNumber numberWithInt:values];
//num = (NSDecimalNumber *)[arrayTemperature objectAtIndex:index];
num =[ NSDecimalNumber numberWithInt:arrayTemperature ];
if ( [plot.identifier isEqual:@"Ba开发者_如何学JAVAr Plot 2"] )
num = [num decimalNumberBySubtracting:[NSDecimalNumber decimalNumberWithString:@"10"]];
break;
}
}
return num;
}
I also tried:
case CPBarPlotFieldBarLength:
//num = (NSDecimalNumber *)[NSDecimalNumber numberWithUnsignedInteger:(index+20)];
//num = [NSNumber numberWithInt:values];
//num = (NSDecimalNumber *)[arrayTemperature objectAtIndex:index]
num=nil;
int i=0;
for (i=0; i=9;i++){
num = [arrayTemperature objectAtIndex:i];
}
If someone has an idea about how to use Arrays, or an other idea to deal with this please let me know.
Assuming arrayTemperature is an array of NSNumbers (or NSDecimalNumbers), this will work. Your array can contain [NSNull null] to represent missing values as well.
-(NSNumber *)numberForPlot:(CPPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index
{
NSDecimalNumber *num = nil;
if ( [plot isKindOfClass:[CPBarPlot class]] ) {
switch ( fieldEnum ) {
case CPBarPlotFieldBarLocation:
num = (NSDecimalNumber *)[NSDecimalNumber numberWithUnsignedInteger:index];
break;
case CPBarPlotFieldBarLength:
num = [arrayTemperature objectAtIndex:index];
break;
}
}
return num;
}
So i finally solved my problem If anyone is interesting here is how I did:
NSURL *getTemperature = [NSURL URLWithString:@"http://.....php"];
arrayTemperature = [[NSArray alloc] initWithContentsOfURL:getTemperature ];
NSLog(@"Températures Array :%@",arrayTemperature);
NSURL *getTemps = [NSURL URLWithString:@"http://....php"];
arrayTemps = [[NSArray alloc] initWithContentsOfURL:getTemps ];
NSLog(@"Temps Array : %@",arrayTemps);
and in my function:
-(NSNumber *)numberForPlot:(CPPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index
{
NSNumber *num = nil;
if ( [plot isKindOfClass:[CPBarPlot class]] ) {
switch ( fieldEnum ) {
case CPBarPlotFieldBarLocation:
//num = [NSNumber numberWithUnsignedInteger:index];
num = (NSNumber *)[NSNumber numberWithUnsignedInteger:[[arrayTemps objectAtIndex:index] unsignedIntegerValue]];
break;
case CPBarPlotFieldBarLength:
num = (NSNumber *)[NSNumber numberWithUnsignedInteger:[[arrayTemperature objectAtIndex:index] unsignedIntegerValue]];
break;
}
}
return num;
}
精彩评论