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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:22:37+00:00 2026-06-16T02:22:37+00:00

after calling scaleToFitPlots, My X axis is scaled correctly but my Y Axis is

  • 0

after calling scaleToFitPlots, My X axis is scaled correctly but my Y Axis is far too high. Two screenshots attached, 1st pic: Original, 2nd pic: After I scrolled down.

enter image description here
enter image description here

I want the graph to be entirely viewable (from Y=0 to Y=MAX) within the green box.
On iPhone, iPad I get this erroneous Y-axis scaling.

For some reason, it thinks there plotArea is taller than it actually is?

Snippet of my graph configuration code:

-(void)configureGraph {
    CPTGraph *graph = [[CPTXYGraph alloc] initWithFrame:self.hostView.bounds];
    graph.plotAreaFrame.borderLineStyle = nil;
    self.hostView.hostedGraph = graph;

    //Controls padding between frame & draw
    [graph.plotAreaFrame setPaddingTop:20.0f];
    [graph.plotAreaFrame setPaddingRight:20.0f];
    [graph.plotAreaFrame setPaddingBottom:20.0f];
    [graph.plotAreaFrame setPaddingLeft:30.0f];
    //Controls padding between frame and graph (graph is wrapper)
    graph.paddingLeft = 0.0;
    graph.paddingTop = 0.0;
    graph.paddingRight = 0.0;
    graph.paddingBottom = 0.0;

    // 5 - Enable user interactions for plot space
    CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *) graph.defaultPlotSpace;
    plotSpace.allowsUserInteraction = YES;

}

-(void)scaleToFitPlot
{
    CPTGraph *graph = [self getGraph];
    CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *) graph.defaultPlotSpace;
    [plotSpace scaleToFitPlots:[NSArray arrayWithObjects:self.meterPlot, nil]];
}

-(void)configurePlots {
    // 1 - Get graph and plot space
    CPTGraph *graph = self.hostView.hostedGraph;
    CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *) graph.defaultPlotSpace;

    // 2 - Create the three plots
    meterPlot = [[CPTScatterPlot alloc] init];

    meterPlot.dataSource = self;
    meterPlot.identifier = MYMSymbolHourly;
    // Set plot delegate, to know when symbols have been touched
    // We will display an annotation when a symbol is touched, but this can be another graph!
    meterPlot.delegate                         = self;
    meterPlot.plotSymbolMarginForHitDetection  = 5.0f;

    //CPTColor *meterColor = [CPTColor greenColor];
    CPTColor *meterColor = [self orangeClr];

    [graph addPlot:meterPlot toPlotSpace:plotSpace];
    // 3 - Set up plot space
    printf("\nset initialscale");
    //[plotSpace scaleToFitPlots:[NSArray arrayWithObjects:meterPlot, nil]];
    [self scaleToFitPlot];
    CPTMutablePlotRange *xRange = [plotSpace.xRange mutableCopy];
    //[xRange expandRangeByFactor:CPTDecimalFromCGFloat(1.1f)];
    plotSpace.xRange = xRange;
    CPTMutablePlotRange *yRange = [plotSpace.yRange mutableCopy];
    //[yRange expandRangeByFactor:CPTDecimalFromCGFloat(1.2f)];
    plotSpace.yRange = yRange;
    // 4 - Create styles and symbols
    CPTMutableLineStyle *meterLineStyle = [meterPlot.dataLineStyle mutableCopy];
    meterLineStyle.lineWidth = 2.5;
    meterLineStyle.lineColor = meterColor;
    meterPlot.dataLineStyle = meterLineStyle;
    CPTMutableLineStyle *meterSymbolLineStyle = [CPTMutableLineStyle lineStyle];
    meterSymbolLineStyle.lineColor = meterColor;
    CPTPlotSymbol *meterSymbol = [CPTPlotSymbol ellipsePlotSymbol];
    meterSymbol.fill = [CPTFill fillWithColor:meterColor];
    meterSymbol.lineStyle = meterSymbolLineStyle;
    meterSymbol.size = CGSizeMake(6.0f, 6.0f);
    meterPlot.plotSymbol = meterSymbol;
}

-(void)configureAxes {
    // 1 - Create styles
    CPTMutableTextStyle *axisTitleStyle = [CPTMutableTextStyle textStyle];
    axisTitleStyle.color = [self grey222Clr];
    axisTitleStyle.fontName = @"Helvetica-Bold";
    axisTitleStyle.fontSize = 12.0f;
    CPTMutableLineStyle *axisLineStyle = [CPTMutableLineStyle lineStyle];
    axisLineStyle.lineWidth = 2.0f;
    axisLineStyle.lineColor = [self axisGreyClr];
    CPTMutableTextStyle *xAxisTextStyle = [[CPTMutableTextStyle alloc] init];
    xAxisTextStyle.color = [self grey222Clr]; // This is causing that line bug on y axis
    xAxisTextStyle.fontName = @"Helvetica-Bold";
    xAxisTextStyle.fontSize = 10.0f;


    CPTMutableLineStyle *tickLineStyle = [CPTMutableLineStyle lineStyle];
    tickLineStyle.lineColor = [self axisGreyClr];
    tickLineStyle.lineWidth = 2.0f;
    CPTMutableLineStyle *gridLineStyle = [CPTMutableLineStyle lineStyle];

    gridLineStyle.lineColor = [self axisGreyClr];
    gridLineStyle.lineWidth = 2.0f;

    gridLineStyle.dashPattern = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.8f], nil];
    gridLineStyle.patternPhase=0.0f;

    // 2 - Get axis set
    CPTXYAxisSet *axisSet = (CPTXYAxisSet *) self.hostView.hostedGraph.axisSet;
    // 3 - Configure x-axis
    CPTAxis *x = axisSet.xAxis;
    x.title = [self getXAxisTitleForChart];
    x.titleTextStyle = axisTitleStyle;
    x.titleOffset = 15.0f;
    x.axisLineStyle = axisLineStyle;
    x.labelingPolicy = CPTAxisLabelingPolicyNone;
    x.labelTextStyle = xAxisTextStyle;
    x.majorTickLineStyle = axisLineStyle;
    x.majorTickLength = 4.0f;
    x.tickDirection = CPTSignNegative;
    x.majorGridLineStyle = gridLineStyle;

    [self setXAxisLabels];

    CPTMutableTextStyle *yAxisTextStyle = [[CPTMutableTextStyle alloc] init];
    yAxisTextStyle.color = [self orangeClr]; 
    yAxisTextStyle.fontName = @"Helvetica-Bold";
    yAxisTextStyle.fontSize = 11.0f;

    // 4 - Configure y-axis
    CPTAxis *y = axisSet.yAxis;
    y.title = @"Usage kWh";
    y.titleTextStyle = axisTitleStyle;
    y.titleOffset = -46.0f;
    y.axisLineStyle = axisLineStyle;
    y.majorGridLineStyle = gridLineStyle;
    y.labelingPolicy = CPTAxisLabelingPolicyNone;
    y.labelTextStyle = yAxisTextStyle;

    y.labelOffset = 30.0f;
    y.majorTickLineStyle = axisLineStyle;
    y.majorTickLength = 4.0f;
    y.minorTickLength = 2.0f;
    y.tickDirection = CPTSignPositive;

    [self setYAxisLabels];
}
  • 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-16T02:22:39+00:00Added an answer on June 16, 2026 at 2:22 am

    The first image shows the correct result of -scaleToFitPlots:. It computes plot ranges that exactly enclose the plot data for x and y. If you already know the y-range you want (e.g., Y=0 to Y=MAX), then just set that directly. If you want to scale only the x-axis, call -scaleToFitPlots: and then set the yRange afterwards.

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

Sidebar

Related Questions

After calling fork , the current process will call exit(0) . But the child
i fetch one html fragment like <li>市&nbsp;场&nbsp;价 which contains &nbsp; , but after calling
Two part question: After calling the Mixpanel api I am returned something like this
After calling notifydatasetchanged(); I want to scroll to the bottom of list so that
After calling to a com component procedure , an error raised OLE error C0000094.
After calling msgrcv(), I got a E2BIG: on SunOS, CPP compiler. Output is as
I would like to know if after calling functions the data I have in
What does the pointer of a dynamically allocated memory points to after calling the
I'm interacting with the Magento API and after calling: $result = $soap->call( $session_id, 'catalog_product.list'
I have a JTable inside a JScrollPane. After calling my function which should populate

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.