0
NSArrayControllerからデータを取得する棒グラフを設計しようとしています。それ自体が別のデータソースにバインドされています。NSArrayControllerにバインドされたコアプロット棒グラフ
ここで正しいアプローチは何ですか?
- マイグラフコントローラは、コントローラのawakeFromNib、私はグラフとセットアップバインディングを描くにはNSArrayControllerは
- のサブクラスである:
- (無効)awakeFromNib {
[スーパーawakeFromNib] ;
// Add plot space for horizontal bar charts
CPTXYPlotSpace *barPlotSpace = [[CPTXYPlotSpace alloc] init];
barPlotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(-20.0f) length:CPTDecimalFromFloat(200.0f)];
barPlotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(-7.0f) length:CPTDecimalFromFloat(15.0f)];
[graph addPlotSpace:barPlotSpace];
//[barPlotSpace release];
// First bar plot
CPTMutableTextStyle *whiteTextStyle = [CPTMutableTextStyle textStyle];
whiteTextStyle.color = [CPTColor whiteColor];
CPTBarPlot *barPlot = [[CPTBarPlot tubularBarPlotWithColor:[CPTColor darkGrayColor] horizontalBars:YES] retain];
barPlot.baseValue = CPTDecimalFromFloat(20.0f);
barPlot.dataSource = self;
barPlot.barOffset = CPTDecimalFromFloat(-0.25f);
barPlot.identifier = barPlot1;
barPlot.plotRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(0.0) length:CPTDecimalFromDouble(7.0)];
barPlot.labelTextStyle = whiteTextStyle;
[graph addPlot:barPlot toPlotSpace:barPlotSpace];
/*
// Second bar plot
barPlot = [CPTBarPlot tubularBarPlotWithColor:[CPTColor blueColor] horizontalBars:YES];
barPlot.dataSource = self;
barPlot.baseValue = CPTDecimalFromFloat(20.0f);
barPlot.barOffset = CPTDecimalFromFloat(0.25f);
barPlot.cornerRadius = 2.0;
barPlot.identifier = barPlot2;
barPlot.plotRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(0.0) length:CPTDecimalFromDouble(7.0)];
barPlot.delegate = self;
[graph addPlot:barPlot toPlotSpace:barPlotSpace];
*/
[barPlot bind:CPTBarPlotBindingBarLocations
toObject:self withKeyPath:@"arrangedObjects" options:nil]; }
これは正しい方法ですか?
私の配置オブジェクトは、グラフ化する必要がある名前と時間フィールドを持つ管理対象オブジェクトのセットです。
ありがとうございます!
散布図のサンプルアプリケーションを見ましたが、どのように(NSArrayControllerから)配置されたオブジェクトをグラフにバインドする必要があるのかよく分かりません。私の配置されたオブジェクトはどのフィールドですか? (x、y?)とグラフ側のバインディング定数は何ですか? – Maverick
バインディング定数は、 'CPTBarPlotBindingBarLocations'と' CPTBarPlotBindingBarTips'です。 'arrangedObjects'の中で名前を制御します。 Interface Builderで "XY Values Controller"を選択し、右側のAttributes Inspectorペインを開くことでCPTTestAppでこれを見ることができます。 –
わかりましたが、_CPTBarPlotBindingBarLocations_と* CPTBarPlotBindingBarTips *はどういう意味ですか?私のX軸にはたくさんの企業があり、Y軸は各社の従業員数です。私のarrangedObjectsは、従業員の.name = company name .employees = numの辞書の配列です。バインディングを設定するにはどうすればよいですか? – Maverick