У меня есть диаграмма с двумя штриховыми графиками (пример: 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) прямоугольник InContext : (CGContextRef) контекст {
if (index == 0) {
return YES;
}else{
return NO;
}
}
Спасибо Эрик, я прокомментировал -legendTitleForBarPlot: recordIndex: метод и -legend: shouldDrawSwatchAtIndex: forPlot: inRect: InContext: методы. Я установил свойство title для обоих моих сюжетов. Но это все еще происходит так же, как и раньше. Я попытался изменить 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 –
Вы внедрили метод '-barFillForBarPlot: recordIndex:' в свой источник данных? Это также вызовет поведение легенды. С вашего скриншота это выглядит не так, как вам нужно. –
Да, я сделал. Я отправил свой полный код на другой ответ. Заранее спасибо –