2
votes

I have implemented graphs using this tutorial http://www.raywenderlich.com/13271/how-to-draw-graphs-with-core-plot-part-2

now i want to add a title which will be the calculated percentage of each graph bar at the top of each graph bar, i am trying it like this

int i =0;
    for (CPTBarPlot *plot in plots) {
        plot.dataSource = self;
        plot.delegate = self;
        plot.barWidth = CPTDecimalFromDouble(CPDBarWidth * 2);
        plot.barOffset = CPTDecimalFromDouble(barX);
        plot.lineStyle = barLineStyle;
        NSString *plotname = [plottiltes objectAtIndex:i];
        plot.title = plotname;
        NSLog(@"%@",plotname);
        i++;
        [graph addPlot:plot toPlotSpace:graph.defaultPlotSpace];
        barX += CPDBarWidth * 4;
    } 

but not succeding till yet, plz. guide me. Regards Saad

1

1 Answers

2
votes

The title property is the description of the plot that shows up in the legend. Use data labels to label the bars. If the values that you're displaying aren't the plotted values, you'll need to use custom data labels. Implement the following datasource method and make custom labels. You can use a CPTTextLayer to display a text string or any other CPTLayer if you need to get fancy.

-(CPTLayer *)dataLabelForPlot:(CPTPlot *)plot recordIndex:(NSUInteger)index;