我正在尝试设计一个条形图,它将从NSArrayController获取数据,而它本身是绑定到另一个数据源的。
这里的正确方法是什么?
我的图形控制器是NSArrayController
-(void)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]; }这样做对吗?
我的arrangedObjects是一组托管对象,它们有我需要绘制的名称和时间域。
谢谢!
发布于 2012-01-29 17:24:02
使用绑定时,不要设置数据源。也不要忘记将字段绑定到CPTBarPlotBindingBarTips。
CPTTestApp示例应用程序演示了将散点图绑定到数组控制器。条形图的处理过程是相同的,除非绑定常量有不同的名称。
https://stackoverflow.com/questions/9050680
复制相似问题