Google から CorePlot_0.9 をダウンロードし、iPhone プロジェクトにインポートしました。iPhoneアプリで線(ScatterPlot)を描きたいです。クラスからコードを確認してコピーし、'CPTTestApp-iPhone'
CPTTestAppScatterPlotController
非常にうまく機能するプロジェクトを実行しました。しかし、チャートの値を変更したい。私は自分のレベルで最善を尽くしましたが、値を与える必要がある場所と散布図の値がグラフにどのように表示されるかがわかりません。ここにコードがあります、
This is in ViewDidLoad
{
// Create a green plot area
CPTScatterPlot *dataSourceLinePlot = [[[CPTScatterPlot alloc] init] autorelease];
CPTMutableLineStyle *lineStyle = [CPTMutableLineStyle lineStyle];
lineStyle.lineWidth = 5.f;
lineStyle.miterLimit = 1.0f;
lineStyle.lineWidth = 3.0f;
lineStyle.lineColor = [CPTColor blackColor];
lineStyle.dashPattern = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0f], [NSNumber numberWithFloat:0.0f], nil];
dataSourceLinePlot.dataLineStyle = lineStyle;
dataSourceLinePlot.identifier = @"Green Plot";
dataSourceLinePlot.dataSource = self;
// Add some initial data
NSMutableArray *contentArray = [NSMutableArray arrayWithCapacity:100];
NSUInteger i;
for ( i = 0; i < 20; i++ )
{
id x = [NSNumber numberWithFloat:0+i*0.5];//1+i*0.05
//NSLog(@"Rand_Max : %d", RAND_MAX);//Rand_Max : 2147483647
id y = [NSNumber numberWithFloat:3.2*rand()/(float)RAND_MAX+0.2];//1.2*rand()/(float)RAND_MAX + 1.2
[contentArray addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:x, @"x", y, @"y", nil]];
}
dataForPlot = contentArray;
}
#pragma mark -
#pragma mark Plot Data Source Methods
-(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot
{
return [dataForPlot count];
}
-(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index
{
NSLog(@"NumberForPlot calling");
NSNumber *num = [[dataForPlot objectAtIndex:index] valueForKey:(fieldEnum == CPTScatterPlotFieldX ? @"x" : @"y")];
// Green plot gets shifted above the blue
if ([(NSString *)plot.identifier isEqualToString:@"Green Plot"])
{
if ( fieldEnum == CPTScatterPlotFieldY )
num = [NSNumber numberWithDouble:[num doubleValue] + 0.0];
}
return num;
}
グラフに表示される値を変更するために値を指定する必要がある場所を教えてください。また、グラフの値を動的に変更する方法を教えてください。前もって感謝します。私を助けてください。