Core Plot 1.0:为Legends提供自定义标签 [英] Core Plot 1.0: Provide Custom Labels for Legends

查看:161
本文介绍了Core Plot 1.0:为Legends提供自定义标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



我花了不到几个小时不同的委托和图例设置,但找不到我的错误。我可以给出我可能出现错误的任何提示?



我有子类XYGraph生成条形图如下: / p>

.h



< p $ p> @interface BarLineChart:CPTXYGraph
@property(strong,nonatomic)id @end

在我的实现 .m 中,我设置传说如下:

  //添加图例
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中,为此我设置了委托。代表)。
这是我的viewController的界面:

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

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

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

从未被调用。

解决方案

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


I am using CorePlot 1.0 and would like to add a legend to my bar chart (which is a subclassed XYGraph). I have the datasource and legend title methods in the viewController, which instantiates the bar chart and sets itself as its delegate.

I have spend quite a few hours with different delegate and legend setups but can't find my error. Can you give my any hints on where I may have made an error?

I have subclassed XYGraph to generate bar charts as follows:

.h

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

In my implementation .m, I set up the legend as follows:

 // 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;

I keep the datasource methods in a separate viewController, for which I have set the delegate (stored in self.delegate). This is my viewController's interface:

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

My data source methods to get the plot data works fine, but the legend title method

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

is never called.

解决方案

The legend title method is part of the datasource, not the delegate. If your datasource and delegate are in different classes, make sure the title method is implemented in the correct one.

这篇关于Core Plot 1.0:为Legends提供自定义标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆