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

  • Home
  • SEARCH
  • 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 8064809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:28:55+00:00 2026-06-05T11:28:55+00:00

I am programming a app where I have graph with two y axis and

  • 0

I am programming a app where I have graph with two y axis and one x axis.left y axis has range from 0 to 20 so there are 20 majorTick axis.Right y axis has range from 0 to 10,so I want left y axis to be labelled for every alternate majorTickAxis.

here is my code snippet

//code
   CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)self.graph.defaultPlotSpace;
float xmax=10.0;
float xmin=0.0;
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(xmin)      length:CPTDecimalFromFloat(xmax-xmin)];
float ymax=20.0;
float ymin=0.0;
float ymax2=10.0;
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(ymin) length:CPTDecimalFromFloat(ymax-ymin)];



// Grid line styles
CPTMutableLineStyle *majorGridLineStyle = [CPTMutableLineStyle lineStyle];
majorGridLineStyle.lineWidth = 0.75;
majorGridLineStyle.lineColor = [[CPTColor whiteColor] colorWithAlphaComponent:0.75];

CPTMutableLineStyle *minorGridLineStyle = [CPTMutableLineStyle lineStyle];
minorGridLineStyle.lineWidth = 0.25;
minorGridLineStyle.lineColor = [[CPTColor whiteColor] colorWithAlphaComponent:0.1];

CPTMutableLineStyle *redLineStyle = [CPTMutableLineStyle lineStyle];
redLineStyle.lineWidth = 2.0;
redLineStyle.lineColor = [[CPTColor redColor] colorWithAlphaComponent:0.5];                         

CPTMutableLineStyle *greenLineStyle = [CPTMutableLineStyle lineStyle];
greenLineStyle.lineWidth = 2.0;
greenLineStyle.lineColor = [[CPTColor greenColor] colorWithAlphaComponent:0.5];     

// Axes
CPTXYAxisSet *axisSet = (CPTXYAxisSet *)self.graph.axisSet;
CPTXYAxis *x          = axisSet.xAxis;
x.orthogonalCoordinateDecimal = CPTDecimalFromString(@"0");
x.majorIntervalLength = [[NSDecimalNumber decimalNumberWithString:@"1"] decimalValue];
x.minorTicksPerInterval       = 4;
x.labelOffset = 3.0f;
x.title         = @"Time";
x.titleOffset   = 20.0;
x.titleLocation = CPTDecimalFromFloat((xmax+xmin)/2);
x.majorGridLineStyle= majorGridLineStyle;
x.minorGridLineStyle=minorGridLineStyle;


CPTXYAxis *y = axisSet.yAxis;
y.majorIntervalLength         = CPTDecimalFromString(@"1.0");
y.majorTickLength=2.0f;
y.minorTicksPerInterval       = 4;
y.orthogonalCoordinateDecimal = CPTDecimalFromFloat(0.0);
y.labelExclusionRanges = [NSArray arrayWithObjects:
                          [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInteger(0.0) 
                                                       length:CPTDecimalFromInteger(0.0)],Nil];
y.majorGridLineStyle= majorGridLineStyle;
y.minorGridLineStyle=minorGridLineStyle;


CPTXYAxis *y2 = [[(CPTXYAxis *)[CPTXYAxis alloc] initWithFrame:CGRectZero] autorelease];
y2.plotSpace    =plotSpace;     
y2.orthogonalCoordinateDecimal = CPTDecimalFromFloat(xmax);
y2.majorGridLineStyle=majorGridLineStyle;
y2.minorGridLineStyle=minorGridLineStyle;
y2.minorTicksPerInterval       = 4;
y2.majorIntervalLength        = CPTDecimalFromString(@"1.0");
y2.labelOffset        = 10.0;
y2.coordinate          =CPTCoordinateY;

y2.axisLineStyle       = x.axisLineStyle;
y2.labelTextStyle              = x.labelTextStyle;
y2.labelOffset                 = -30.0f;
y2.visibleRange                = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInteger(0) length:CPTDecimalFromInteger(ymax2)];


y2.title                       = @"Temperature";
y2.titleLocation               = CPTDecimalFromInteger(5.0);
y2.titleTextStyle              =x.titleTextStyle;
y2.titleOffset                 =-45.0f;
y2.labelExclusionRanges = [NSArray arrayWithObjects:
                          [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInteger(0.0) 
                                                       length:CPTDecimalFromInteger(0.0)],Nil];


self.graph.axisSet.axes = [NSArray arrayWithObjects:x, y, y2, nil];

// Create a plot that uses the data source method for red graph
CPTScatterPlot *redPlot = [[[CPTScatterPlot alloc] init] autorelease];
redPlot.identifier = @"red Plot";;

CPTMutableLineStyle *lineStyle = [[redPlot.dataLineStyle mutableCopy] autorelease];
lineStyle.miterLimit        = 1.0f;
redPlot.dataLineStyle = redLineStyle;
redPlot.dataSource = self;
redPlot.interpolation = CPTScatterPlotInterpolationStepped;

[self.graph addPlot:redPlot];

// Create a plot that uses the data source method for green graph
CPTScatterPlot *greenPlot = [[[CPTScatterPlot alloc] init] autorelease];
greenPlot.identifier = @"green Plot";;

CPTMutableLineStyle *greenlineStyle = [[greenPlot.dataLineStyle mutableCopy] autorelease];
greenlineStyle.miterLimit       = 1.0f;
greenPlot.dataLineStyle = greenLineStyle;
greenPlot.dataSource = self;
[self.graph addPlot:greenPlot];

 // Add some data
NSMutableArray *newData = [NSMutableArray arrayWithCapacity:100];
NSUInteger i;
for ( i = 0; i < 45; i++ ) {
    id x = [NSNumber numberWithDouble:i * 0.2];
    id y = [NSNumber numberWithDouble:i * rand() / ((double)RAND_MAX*5.0) ];        
    [newData addObject:[NSDictionary dictionaryWithObjectsAndKeys:
      x, @"x",y, @"y",nil]];
}
NSMutableArray *newData1 = [NSMutableArray arrayWithCapacity:100];
for ( i = 0; i < 45; i++ ) {
    id x =[NSNumber numberWithDouble:i * rand() / ((double)RAND_MAX*5.0) ]; 
    id y2 = [NSNumber numberWithDouble:i * 0.2];
    [newData1 addObject:[NSDictionary dictionaryWithObjectsAndKeys:
                        x, @"x",y2, @"y2",nil]];
}
self.plotData = newData;
self.plotData2=newData1;
  • 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-05T11:28:56+00:00Added an answer on June 5, 2026 at 11:28 am

    If you want the two y-axes to have different scales, you need to add another plot space. Use the same xRange for the second plot space, but use a different yRange, e.g.,

    CPTXYPlotSpace *plotSpace2 = [[[CPTXYPlotSpace alloc] init] autorelease];
    plotSpace2.xRange = plotSpace.xRange;
    plotSpace2.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(ymin)
                                                     length:CPTDecimalFromFloat(ymax2 - ymin)];
    [graph addPlotSpace:plotSpace2];
    y2.plotSpace = plotSpace2;
    

    Use the majorIntervalLength to control the location of the ticks and grid lines:

    y.majorIntervalLength = CPTDecimalFromFloat((ymax - ymin) / 10.0f);
    y2.majorIntervalLength = CPTDecimalFromFloat((ymax2 - ymin) / 10.0f);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to learn rails from zero programming experience and have an app
I have been programming an Android App for a while and we want to
I am programming an app that eventually will have several Activities. Right now, however,
I am programming multi-threaded app. I have two threads. On is for transferring some
I'm programming an Android app, where I have to store pictures to some online
After years in embedded programming, I have to develop a Windows app. I dug
I'm writing a GUI app with wxwidgets in C++ for one of my programming
I'm abit new to programming Android App's, however I have come across a problem,
I wish to have an app written in the D programming language update its
I'm programming an iPhone app and have my constants arranged in Constants.h and Constants.m

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.