Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8014835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:04:07+00:00 2026-06-04T20:04:07+00:00

I am trying to create a bar graph similar to the one below –

  • 0

I am trying to create a bar graph similar to the one below – where the x axis has 2 different labels – one the labels on the bars themselves, indicating performance, and the other at the bottom of the axis, indicating the year. Only the numbers need to be shown rotated, on the graph rather than at the top.

bar graph

I am showing the years by creating custom labels. I am also able to show the performance figures for the bars by implementing the -dataLabelForPlot:recordIndex: method. The performance figures shows up but horizontally, but I want to be able to rotate the performance figures by 90 degrees.
Setting the labelRotation on the plot does not help because I have set the labelingPolicy to CPTAxisLabelingPolicyNone so I can add custom labels.

Below is my code:

-(CPTLayer *)dataLabelForPlot:(CPTPlot *)plot recordIndex:(NSUInteger)index 
{
    CPTMutableTextStyle *axisTitleTextStyle = [CPTMutableTextStyle textStyle];
    axisTitleTextStyle.fontSize = 10.0;
    axisTitleTextStyle.color = [CPTColor blackColor];

    CPTTextLayer *label = [[CPTTextLayer alloc] init];
    label.textStyle = axisTitleTextStyle;
    if ( [plot isKindOfClass:[CPTBarPlot class]] ) {
        if ( [plot.identifier isEqual:@"Fund"] ) {
            label.text =  [[[self dataGroup1] objectAtIndex:index] stringValue];
        }
        else if ( [plot.identifier isEqual:@"Benchmark"] ) {
            label.text =  [[[self dataGroup2] objectAtIndex:index] stringValue];
        }

    }
    return [label autorelease];
}


- (void) drawGraph 
{
    graphHostingView_ = [[CPTGraphHostingView alloc] initWithFrame:self.bounds];

    calPerfGraph_ = [[CPTXYGraph alloc] initWithFrame:self.bounds];
    graphHostingView_.hostedGraph = calPerfGraph_;

    [self addSubview:graphHostingView_];

    calPerfGraph_.plotAreaFrame.masksToBorder = NO;

    calPerfGraph_.paddingLeft = 5.0;
    calPerfGraph_.paddingTop = 20.0;
    calPerfGraph_.paddingRight = 10.0;
    calPerfGraph_.paddingBottom =20.0;

    calPerfGraph_.plotAreaFrame.paddingTop = 10.0;
    calPerfGraph_.plotAreaFrame.paddingBottom = 50.0;
    calPerfGraph_.plotAreaFrame.paddingLeft = 10.0;
    calPerfGraph_.plotAreaFrame.paddingRight = 35.0;

    // Y axis scale - round to nearest ten
    int maxYScale = (([[self getPositiveMax] intValue] / 10 ) + 1) * 10;
    int minYScale = (([[self getNegativeMax] intValue] / 10 ) + 1) * 10;

    // Styles
    CPTMutableLineStyle *lineStyle = [CPTMutableLineStyle lineStyle];
    lineStyle.lineColor = [CPTColor grayColor];
    lineStyle.lineWidth = 2.0f;

    CPTMutableLineStyle *gridLineStyle = [CPTMutableLineStyle lineStyle];
    gridLineStyle.lineColor = [CPTColor grayColor];
    gridLineStyle.lineWidth = 1.0f;

    // X axis
    CPTXYAxisSet *axisSet = (CPTXYAxisSet *)calPerfGraph_.axisSet;
    axisSet.xAxis.minorTicksPerInterval = 0;
    axisSet.xAxis.majorTickLineStyle = lineStyle;
    axisSet.xAxis.axisLineStyle = lineStyle;
    axisSet.xAxis.majorTickLength = 0;
    axisSet.xAxis.labelingPolicy = CPTAxisLabelingPolicyNone;
    axisSet.xAxis.axisConstraints = [CPTConstraints constraintWithLowerOffset:0]; // Bring labels to the bottom on the plot
    axisSet.xAxis.labelRotation = M_PI/2;

    int currentYear = [self getCurrentYear];
    NSMutableArray *customLabels = [NSMutableArray arrayWithCapacity:6];
    for (int i=currentYear-5,count=1; currentYear>=i; i++,count++) {
        CPTAxisLabel *newLabel = [[CPTAxisLabel alloc] initWithText:[NSString stringWithFormat:@"%d",i] textStyle:axisSet.xAxis.labelTextStyle];
        newLabel.tickLocation = CPTDecimalFromInt(count);
        newLabel.offset = axisSet.xAxis.labelOffset + axisSet.xAxis.majorTickLength;
        [customLabels addObject:newLabel];
        [newLabel release];
    }
    axisSet.xAxis.axisLabels =  [NSSet setWithArray:customLabels];

    // Y axis
    if ( maxYScale >= 40 || minYScale >= 40) {
        axisSet.yAxis.majorIntervalLength = [[NSDecimalNumber decimalNumberWithString:@"20"] decimalValue];
    }
    else {
        axisSet.yAxis.majorIntervalLength = [[NSDecimalNumber decimalNumberWithString:@"10"] decimalValue];
    }

    axisSet.yAxis.minorTicksPerInterval = 0;
    axisSet.yAxis.majorTickLength = 0;
    axisSet.yAxis.majorGridLineStyle = gridLineStyle;
    axisSet.yAxis.axisLineStyle = nil;
    axisSet.yAxis.axisConstraints = [CPTConstraints constraintWithUpperOffset:0]; // Bring labels to the right end of the plot
    axisSet.yAxis.tickDirection = CPTSignPositive;

    CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)calPerfGraph_.defaultPlotSpace;
    plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(0.0) length:CPTDecimalFromDouble([[self calPerfFundData] count]+1)];
    plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(-minYScale) length:CPTDecimalFromDouble(minYScale + maxYScale)];

    CPTBarPlot *barPlot = [CPTBarPlot tubularBarPlotWithColor:[CPTColor greenColor] horizontalBars:NO];    
    barPlot.baseValue = CPTDecimalFromString(@"0");
    barPlot.dataSource = self;
    barPlot.barOffset = CPTDecimalFromFloat(.7);
    barPlot.identifier = @"Fund";
    barPlot.barWidth = CPTDecimalFromFloat(.25);
    [barPlot addAnimation:[self animateVerticalBars] forKey:@"FundAnimation"];
    [calPerfGraph_ addPlot:barPlot toPlotSpace:plotSpace];

    CPTBarPlot *bbarPlot = [CPTBarPlot tubularBarPlotWithColor:[CPTColor colorWithComponentRed:0.9 green:0.9 blue:0.9 alpha:0.8] horizontalBars:NO];    
    bbarPlot.baseValue = CPTDecimalFromString(@"0");
    bbarPlot.dataSource = self;
    bbarPlot.barOffset = CPTDecimalFromFloat(1);
    bbarPlot.barWidth = CPTDecimalFromFloat(.25);
    bbarPlot.identifier = @"Benchmark";
    [bbarPlot addAnimation:[self animateVerticalBars] forKey:@"BenchmarkAnimation"];
    [calPerfGraph_ addPlot:bbarPlot toPlotSpace:plotSpace];
}

How can I rotate the performance figures on the bars? Any help is appreciated.
Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T20:04:09+00:00Added an answer on June 4, 2026 at 8:04 pm

    Both plots and axes have their own independent labelRotation properties. You will be responsible for setting the rotation of your custom axis labels, but the labelRotation property of the bar plot should set the rotation for the data labels above the bars.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a search bar similar to the one in safari browser
I'm trying to create a stacked bar graph with errorbars* using ggplot2, similar to
I am trying to create a menu bar that has 2 levels of menus.
I'm trying to create a css menu bar that has all grey text with
I am trying to create a bar graph using the matplot library but I
I'm trying to create a horizontal 100% stacked bar graph using HTML and CSS.
So I am trying to create an animated bar graph using apple core animation.
I am trying to create a bar chart with an extra Y-axis that maps
Greetings, I am trying to create a bar chart of the data posted below
Been trying to create a layout similar to the Android Facebook app (top bar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.