I am trying to add legend in my bar chart based on the examples like this
CPTBarPlot* barPlot = [[CPTBarPlot alloc] init];
barPlot.dataSource = self;
barPlot.baseValue = CPTDecimalFromString(@"0");
barPlot.barOffset = CPTDecimalFromFloat(1.0f);
barPlot.barCornerRadius = 2.0f;
barPlot.identifier = @"Bar Plot 2";
[barChart addPlot:barPlot toPlotSpace:plotSpace];
// Add legend
CPTLegend *theLegend = [CPTLegend legendWithGraph:barChart];
theLegend.numberOfColumns = 1;
theLegend.fill = [CPTFill fillWithColor:[CPTColor whiteColor]];
theLegend.borderLineStyle = [CPTLineStyle lineStyle];
theLegend.cornerRadius = 5.0;
CPTMutableTextStyle* legendStyle = [[CPTMutableTextStyle alloc] init];
legendStyle.fontSize = 18.0f;
theLegend.textStyle = legendStyle;
barChart.legend = theLegend;
barChart.legendAnchor = CPTRectAnchorRight;
barChart.legendDisplacement = CGPointMake(-50.0, 80.0);
and this is the method to set titles in the legend
//legend title
-(NSString *)legendTitleForBarPlot:(CPTBarPlot *)barPlot recordIndex:(NSUInteger)index
{
if (index == 0) {
return @"Major";
}
if (index == 1) {
return @"Minor" ;
}
if (index == 2) {
return @"Normal"; }
return [NSString stringWithFormat:@"Bar %u", index];
}
But i can only see the one line in the rectangular box with title 'Bar Plot 2' and one black rectangular box before title. the one set in barPlot.identifier.But the desired output is to display three lines with Major,minor,normal as titles.. I feel like the method legendTitleForBarPlot is not being called, as the result is same after commenting this method as well.

-legendTitleForBarPlot:recordIndex:method was added between 0.9 and 1.0. Also, make sure that method is implemented in your datasource class. - Eric SkrochnumberOfRecordsForPlot:numberForPlot:dataLabelForPlot:etc are implemented. Also i am adding legend title for pie chart and it works correctly but not in bar plot. Thanks - TechnocraT