核心图1.0:为图例提供自定义标签

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

我已经花了不同的代表和传奇设置几个小时,但无法find我的错误。 你能否提供一些我可能犯错的提示?

我已经将子图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中,为此我设置了委托(存储在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 

从来没有被称为。

图例标题方法是数据源的一部分,而不是委托。 如果您的数据源和委托使用不同的类,请确保标题方法是正确的。