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 7536107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:29:09+00:00 2026-05-30T06:29:09+00:00

I am using the Core Plot library for drawing graphs on the iOS. I

  • 0

I am using the Core Plot library for drawing graphs on the iOS. I want to add colors between the grid lines of the yAxis. I have managed to do it with setting the alternatingBandFills property of the axis. However, I have to use custom labels on the yAxis as well, and when I am providing the custom labels, the alternatingBandFills property does not work for some reason.

Any help how to add colors to the spaces between the grid lines on the yAxis as well as using custom labels will be much appreciated.

The code that I am using now looks like:

    CPTXYAxisSet *axisSet = (CPTXYAxisSet *)self.hostedGraph.axisSet;
    CPTXYAxis *yAxis = axisSet.yAxis; 

    yAxis.orthogonalCoordinateDecimal = CPTDecimalFromDouble(minValueX);        
    yAxis.labelingPolicy = CPTAxisLabelingPolicyNone;

    NSArray *yAxisTickLocations = [NSArray arrayWithObjects:
                                   [NSDecimalNumber numberWithDouble:lowerRedRangeFrom],
                                   [NSDecimalNumber numberWithDouble:lowerOrangeRangeFrom],
                                   [NSDecimalNumber numberWithDouble:greenRangeFrom],
                                   [NSDecimalNumber numberWithDouble:upperOrangeRangeFrom],
                                   [NSDecimalNumber numberWithDouble:upperRedRangeFrom],
                                   [NSDecimalNumber numberWithDouble:upperRedRangeTo],
                                   nil];
    NSArray *yAxisLabels = [NSArray arrayWithObjects:@"Label1",@"Label2", @"Label3",@"Label4",@"Label5",@"Label6", nil];

    NSUInteger labelLocationY = 0;
    NSMutableArray *customLabelsY = [NSMutableArray arrayWithCapacity:[yAxisLabels count]];
    for (NSNumber *tickLocation in yAxisTickLocations) {

        CPTAxisLabel *newLabel = [[CPTAxisLabel alloc] initWithText: [yAxisLabels objectAtIndex:labelLocationY++] textStyle:axisSet.xAxis.labelTextStyle];
        newLabel.tickLocation = [tickLocation decimalValue];
        newLabel.offset = axisSet.xAxis.labelOffset + axisSet.xAxis.majorTickLength;
        newLabel.rotation = M_PI/4;
        [customLabelsY addObject:newLabel];
    }

    axisSet.yAxis.axisLabels =  [NSSet setWithArray:customLabelsY];
    yAxis.alternatingBandFills = [NSArray arrayWithObjects:
                                  [CPTColor redColor],
                                  [CPTColor orangeColor],
                                  [CPTColor greenColor],
                                  [CPTColor orangeColor],
                                  [CPTColor redColor], nil];
  • 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-05-30T06:29:10+00:00Added an answer on May 30, 2026 at 6:29 am

    I have figured it out:

    The labeling policy of the axis should be: CPTAxisLabelingPolicyLocationsProvided, for which the documentation states: ” User sets tick locations; axis makes labels.”.

    Now we only need to specify the locations of the ticks. This is done by creating a NSSetobject with the locations. Then we have to set the majorTickLocations property of the axis.

    So my code now looks like:

        CPTXYAxisSet *axisSet = (CPTXYAxisSet *)self.hostedGraph.axisSet;
        CPTXYAxis *yAxis = axisSet.yAxis;
    
        yAxis.orthogonalCoordinateDecimal = CPTDecimalFromDouble(minValueX);        
        yAxis.labelingPolicy = CPTAxisLabelingPolicyLocationsProvided;
    
        NSSet *majorTickLocations = [NSSet setWithObjects:
                                     [NSDecimalNumber numberWithDouble:lowerRedRangeFrom],
                                     [NSDecimalNumber numberWithDouble:lowerOrangeRangeFrom],
                                     [NSDecimalNumber numberWithDouble:greenRangeFrom],
                                     [NSDecimalNumber numberWithDouble:upperOrangeRangeFrom],
                                     [NSDecimalNumber numberWithDouble:upperRedRangeFrom],
                                     [NSDecimalNumber numberWithDouble:upperRedRangeTo],
                                     nil];
        yAxis.majorTickLocations = majorTickLocations;
    
        yAxis.alternatingBandFills = [NSArray arrayWithObjects:
                                      [CPTColor redColor],
                                      [CPTColor orangeColor],
                                      [CPTColor greenColor],
                                      [CPTColor orangeColor],
                                      [CPTColor redColor], nil];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a graph for my iOS app, using the Core Plot library However
I'm using Core Plot in an iOS-Application and want to format the steps of
I have trouble with using the Core-Plot library in MonoTouch. I use this as
Anyone know how to create line graphs on iOS without using Core-Plot but using
I have an application using Core Data and bindings. I want to have an
Im using core-plot for my graphing component of my iPhone app, and I have
I am drawing a ScatterPlot using core-plot framework. My x coordinates are hours starting
I am using core-plot library to draw a bar-chart on my iPhone application and
I'm using Core Plot to develop some iOS applications, but zooming and panning seems
I have just started using core data. I want to setup a pre-populated db.

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.