Reputation: 821
I have implemented core plot graph using link http://www.johnwordsworth.com/2011/10/adding-charts-to-your-iphone-ipad-app-using-core-plot/
In this example author used both float values for x,y points
but now i need to use time values for y axis points how should i wrote code to assign x,y points
AppDelegate *app = (AppDelegate*)[[UIApplication sharedApplication] delegate];
NSMutableArray * times = app.timesArray;
NSMutableArray * painlevels = app.PainlevelsArray;
[super viewWillAppear:animated];
//Xand y Points to draw a graph
NSMutableArray *data = [NSMutableArray array];
for(int i=0 ; i< [painlevels count]; i++)
{
[data addObject:[NSValue valueWithCGPoint:CGPointMake([[painlevels objectAtIndex:i]floatValue] , [[times objectAtIndex:i]floatValue])]];
}
//X,y points for previous values float values in author example
/* [data addObject:[NSValue valueWithCGPoint:CGPointMake(@"fd", 0)]]; [data addObject:[NSValue valueWithCGPoint:CGPointMake(-8, 10)]]; [data addObject:[NSValue valueWithCGPoint:CGPointMake(-6, 40)]]; [data addObject:[NSValue valueWithCGPoint:CGPointMake(-5, 20)]]; [data addObject:[NSValue valueWithCGPoint:CGPointMake(0, 50)]]; [data addObject:[NSValue valueWithCGPoint:CGPointMake(3, 3)]]; [data addObject:[NSValue valueWithCGPoint:CGPointMake(4, 18)]]; [data addObject:[NSValue valueWithCGPoint:CGPointMake(6, 36)]]; [data addObject:[NSValue valueWithCGPoint:CGPointMake(9, 66)]];*/
self.scatterPlot = [[ScatterPlot alloc] initWithHostingView:_graphHostingView andData:data];
[self.scatterPlot initialisePlot];
Upvotes: 1
Views: 1121
Reputation: 27381
Core Plot includes two different ways to format date values. CPTTimeFormatter
formats dates based on a time interval given in seconds relative to a reference date. CPTCalendarFormatter
lets you specify the interval (days, months, hours, etc.).
The DatePlot and Plot Gallery example apps demonstrate how to use CPTTimeFormatter
. See this discussion thread for an example of how to use CPTCalendarFormatter
.
CPTCalendarFormatter
is really great but it is not available in version 1.0. You can add it to your project from the link referenced above.
Upvotes: 2