我有一个带2条线图的图表(例如:A和B)。多条线图图例
对于每个小时我有2个条形图。
当我设置图例时,我得到了每个小时的样本和文字以及酒吧 的情节。
实例:在我的图表有4个小时,然后我的传说会是这样
AAAA
BBBB
,我只希望
AB
因为每隔一小时,酒吧意味着相同。 我该怎么做?
我想尽一切办法做到这一点,但没有成功到现在....
贝娄是我
// CPTLegend *theLegend = [CPTLegend legendWithGraph:barChart];
CPTLegend *theLegend = [CPTLegend legendWithPlots:[NSArray arrayWithObjects:[barChart plotAtIndex:0],[barChart plotAtIndex:1], nil]];
theLegend.numberOfRows = 1;
theLegend.numberOfColumns = 2;//[horas count] +1/2;
//theLegend.fill = [CPTFill fillWithColor:[CPTColor colorWithGenericGray:0.15]];
//theLegend.borderLineStyle = barLineStyle;
theLegend.cornerRadius = 10.0;
theLegend.swatchSize = CGSizeMake(15, 15);
//whiteTextStyle.fontSize = 16.0;
//theLegend.textStyle = whiteTextStyle;
theLegend.rowMargin = 10.0;
theLegend.paddingLeft = 12.0;
theLegend.paddingTop = 12.0;
theLegend.paddingRight = 12.0;
theLegend.paddingBottom = 12.0;
//theLegend.equalColumns = YES;
//theLegend.equalRows = YES;
theLegend.delegate = self;
barChart.legend = theLegend;
- (的NSString *)legendTitleForBarPlot:(CPTBarPlot *)barPlot recordIndex :(NSUInteger)指数{
if ([barPlot.identifier isEqual:@"Embarque"]) {
if (index == 0)
{
return @"Embarque";
}else {
return @"";
}
}else {
if (index == 0)
{
return @"Desembarque";
}else {
return @"";
}
}
} - (BOOL)传说:(CPTLegend *)传奇shouldDrawSwatchAtIndex:(NSUInteger)指数forPlot:(CPTPlot *)情节inRect:(的CGRect)RECT inContext的(CGContextRef)上下文{
if (index == 0) {
return YES;
}else{
return NO;
}
}
感谢埃里克, 我评论-legendTitleForBarPlot:recordIndex:方法和-legend:shouldDrawSwatchAtIndex:forPlot:inRect:inContext的:方法。 我设置了我的两个阴谋的标题属性。 但它仍然像以前一样发生。 我试图将de numberOfRows更改为1,将numberOfCollouns更改为2,但图例重叠。 请把打印屏幕上一看波纹管 http://3.bp.blogspot.com/-QQa9LKUaJHY/T32WTHFcfOI/AAAAAAAAAGI/xpruAySamrQ/s1600/Captura+de+Tela+2012-04-05+às+ 09.50.31+(2).png – 2012-04-05 12:58:14
你在数据源中实现了'-barFillForBarPlot:recordIndex:'方法吗?这也会触发传奇行为。从你的截图看,你看起来并不需要它。 – 2012-04-06 23:26:32
是的,我做过。 我在另一个答案上发布了我的完整代码。 在此先感谢 – 2012-04-09 14:16:40