0

2つのプロットを持つグラフがあります。1つのプロットは、10個のデータポイントを示しており、静的です。2番目のプロットは、スライダー選択の関数である1つのデータポイントのみを表示する必要があります。

ただし、スライダーを動かして単一のデータポイントの座標を計算するたびに、スライドを停止するまで、プロットは一連のポイント全体を生成します。このドットの軌跡を削除し、スライダーの停止位置で表されるものだけを表示したいと思います。これが理にかなっていることを願っています。

グラフは次のようになります(誤って):

おっと、私は画像を投稿するには新しすぎますが、あなたは写真を手に入れると確信しています。

スライダーIBActionのコードの一部を次に示します。

CPTScatterPlot *dotPlot = [[[CPTScatterPlot alloc] init] autorelease];
dotPlot.identifier = @"Blue Plot";
dotPlot.dataSource = self;
dotPlot.dataLineStyle = nil;
[graph addPlot:dotPlot];

NSMutableArray *dotArray = [NSMutableArray arrayWithCapacity:1];
NSNumber *xx = [NSNumber numberWithFloat:[estMonthNumber.text floatValue]];
NSNumber *yy = [NSNumber numberWithFloat:[estMonthYield.text floatValue]];
[dotArray addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:xx,@"x",yy,@"y", nil]];

CPTMutableLineStyle *dotLineStyle = [CPTMutableLineStyle lineStyle];
dotLineStyle.lineColor = [CPTColor blueColor];
CPTPlotSymbol *yieldSymbol = [CPTPlotSymbol ellipsePlotSymbol];
yieldSymbol.fill = [CPTFill fillWithColor:[CPTColor blueColor]];
yieldSymbol.size = CGSizeMake(10.0, 10.0);
dotPlot.plotSymbol = yieldSymbol;

self.dataForPlot = dotArray;

[dotPlot reloadData]を使用してプロットをリロードしようとしましたが、dotPlotを削除して追加し直そうとしましたが、どちらも機能しないようです。または、命令を間違った場所または間違った順序で配置している可能性があります。

アドバイスをいただければ幸いです。

4

2 に答える 2

1

スライダー アクションで散布図を再作成するのはなぜですか? そのメソッドで行う必要があるのは、2 番目のプロットのデータを提供する配列を更新し、reloadData を呼び出すことだけです。

いずれにせよ、トレイルを取得している理由は、新しいプロットを作成してグラフに追加し続けるためです。スライダー メソッドに含める必要がある唯一のコードは次のとおりです。

NSMutableArray *dotArray = [NSMutableArray arrayWithCapacity:1];
NSNumber *xx = [NSNumber numberWithFloat:[estMonthNumber.text floatValue]];
NSNumber *yy = [NSNumber numberWithFloat:[estMonthYield.text floatValue]];
[dotArray addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:xx,@"x",yy,@"y", nil]];
self.dataForPlot = dotArray;

[graph reloadData];
于 2011-09-26T20:42:44.370 に答える
1

私は、解決策から離れたコード行について考えました。よくあることですが、私は解決策を夢見ていました。最初に、NSMutableArray *dotArray などのコードをすべてスライダー メソッドから削除しました。次に、Flyingdiver がアドバイスしたように、スライダー メソッドで [graph reloadData] を保持しました。3 番目に、データソース メソッドを次のように変更しました。

#pragma mark - Plot datasource methods
-(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot {
    return [dataForPlot count];
}
-(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:     (NSUInteger)index { 
    NSNumber *num = [[dataForPlot objectAtIndex:index] valueForKey:(fieldEnum == CPTScatterPlotFieldX ? @"x" : @"y")];
    // Blue dot gets placed above the red actual yields
    if ([(NSString *)plot.identifier isEqualToString:@"Blue Plot"]) {
        if (fieldEnum == CPTScatterPlotFieldX) {
            num = [NSNumber numberWithFloat:[estMonthNumber.text floatValue]]; }
        if (fieldEnum == CPTScatterPlotFieldY) {
        num = [NSNumber numberWithFloat:[estMonthYield.text floatValue]]; }
    }
    return num;
}

もう一度、私の謎を解決する手がかりをくれた Flyingdiver に感謝します。私は多くのことを学びました。

于 2011-09-27T15:15:29.310 に答える