Re: Load data from csv file and plot line graph
Re: Load data from csv file and plot line graph
- Subject: Re: Load data from csv file and plot line graph
- From: Ni Lei <email@hidden>
- Date: Thu, 11 Mar 2010 07:44:01 -0800
For the code example,
> CPTestAppScatterPlotController.m
> that I downloaded from core-plot Google website, a line graph can be
> plotted based on randomly
> generated initial data x, y.
>
> // Add some initial data
> NSMutableArray *contentArray = [NSMutableArray
> arrayWithCapacity:100];
> NSUInteger i;
> for ( i = 0; i < 60; i++ ) {
> id x = [NSNumber numberWithFloat:1+i*0.05];
> id y = [NSNumber numberWithFloat:1.2*rand()/
> (float)RAND_MAX + 1.2];
> [contentArray addObject:[NSMutableDictionary
> dictionaryWithObjectsAndKeys:x, @"x", y, @"y", nil]];
> }
> self.dataForPlot = contentArray;
>
> Then i modified the code,
> NSString *filePath = [[NSBundle mainBundle] pathForResource:@"ECG_Data"
> ofType:@"csv"];
> NSString *myText = [NSString stringWithContentsOfFile:filePath
> encoding:NSUTF8StringEncoding error:nil ];
> NSScanner *scanner = [NSScanner scannerWithString:myText];
> [scanner setCharactersToBeSkipped:[NSCharacterSet
> characterSetWithCharactersInString:@"\n, "]];
> NSMutableArray *newPoints = [NSMutableArray array];
> float time, data;
> while ( [scanner scanFloat:&time] && [scanner scanFloat:&data]
> ) {
> [newPoints addObject:
> [NSMutableDictionary dictionaryWithObjectsAndKeys:
> [NSNumber numberWithFloat:time], @"time",
> [NSNumber numberWithFloat:data], @"data",
> nil]];
> }
> self.dataForPlot = newPoints;
> It seems that my code could not read the data from csv file.
> (there are two cols of the data in ECG_Data.csv, one for time and one for
> data)
> Can anyone give me some suggestion???
> Thanks!!!!
>
> regards,
> Ni Lei
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden