objective-c - 核心图1.0 : Provide Custom Labels for Legends

标签 objective-c ios delegates core-plot

我正在使用CorePlot 1.0,并且想向我的条形图(它是 XYGraph 的子类)添加图例。我在 viewController 中有数据源和图例标题方法,它实例化条形图并将其自身设置为其委托(delegate)。

我花了相当多的时间来设置不同的委托(delegate)和图例,但找不到我的错误。您能给我一些关于我可能在哪里犯了错误的提示吗?

我对 XYGraph 进行了子类化以生成条形图,如下所示:

.h

@interface BarLineChart : CPTXYGraph
@property (strong, nonatomic) id <CPTPlotDataSource, CPTBarPlotDataSource, CPTBarPlotDelegate, CPTPlotSpaceDelegate> delegate;
@end

在我的实现.m中,我按如下方式设置图例:

 // Add legend
CPTLegend *legend           = [CPTLegend legendWithGraph:self];
legend.fill                 = [CPTFill fillWithColor:[CPTColor colorWithGenericGray:0.15]];
legend.borderLineStyle      = axisLineStyle;
legend.cornerRadius         = 10.0;
legend.swatchSize           = CGSizeMake(16.0, 16.0);
CPTMutableTextStyle *legendTextStyle = [CPTMutableTextStyle textStyle];
legendTextStyle.color       = [CPTColor whiteColor];
legendTextStyle.fontSize    = 10.0;
legend.textStyle            = legendTextStyle;
legend.rowMargin            = 1.0;
legend.numberOfRows         = 3;
legend.paddingLeft          = 10.0;
legend.paddingTop           = 10.0;
legend.paddingRight         = 10.0;
legend.paddingBottom        = 10.0;
legend.delegate = self.delegate;

self.legend                 = legend;
self.legendAnchor           = CPTRectAnchorTop;
self.defaultPlotSpace.delegate = self.delegate;

我将数据源方法保存在单独的 viewController 中,并为其设置了委托(delegate)(存储在 self.delegate 中)。 这是我的 viewController 的界面:

`@interface FinstatViewController : CompanyViewController <UITableViewDelegate, UITableViewDataSource, UISplitViewControllerDelegate, UIPopoverControllerDelegate, CompanyPresenter, ChartSelectionDelegate, CPTPlotDataSource, CPTBarPlotDataSource, CPTBarPlotDelegate, CPTPlotSpaceDelegate, CPTLegendDelegate, CPTScatterPlotDataSource, CPTScatterPlotDelegate>`

我获取绘图数据的数据源方法工作正常,但图例标题方法

-(NSString *)legendTitleForBarPlot:(CPTBarPlot *)barPlot recordIndex:(NSUInteger)index

永远不会被调用。

最佳答案

图例标题方法是数据源的一部分,而不是委托(delegate)的一部分。如果您的数据源和委托(delegate)位于不同的类中,请确保在正确的类中实现标题方法。

关于objective-c - 核心图1.0 : Provide Custom Labels for Legends,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9720863/

相关文章:

ios - 使用 Storyboard将多个 UITableView 添加到 iPad 应用程序

c++ - ObjC++ 调用用 C 编写的静态库

c# - 在最小起订量中提高委托(delegate)事件

ios - 类方法单例对象可以响应委托(delegate)调用吗?

ios - 将 MainViewController 设置为 MKMapView 的委托(delegate)时不会出现注释

ios - 这段代码是否从 objective-c 正确地转换为 swift?

ios - NSKeyedArchiver 不推荐使用的方法问题

ios - 滑动按钮不会用于远程通知

ios - 目标 - C : UITableView Content Changing on Scroll

ios - 表格中的第一个单元格始终为空。仅从第二个单元格显示 - objective-c