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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:26:55+00:00 2026-05-31T16:26:55+00:00

I have implemented a CorePlot graph in my iOS application, however I am unable

  • 0

I have implemented a CorePlot graph in my iOS application, however I am unable to dynamically size the y-Axis based on the data points in the set. Some datasets range from 10-50, while others would range from 400-500. In both cases, I would like to have y-origin (0) visible.

I have tried using the scaletofitplots method:

[graph.defaultPlotSpace scaleToFitPlots:[graph allPlots]];

but this has no effect on the graphs, they still show the default Y-Axis range of 0 to 1.

The only way that I can change the y-Axis is to do it manually via this:

graph.defaultPlotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0f)) length:CPTDecimalFromFloat(500.0f)];

however this doesn’t work well for graphs with smaller ranges (10-50), as you can imagine.

Is there any method to retrieve the highest y-value from my dataset so that I can manually set the maximum y-Axis to that value? Or is there a better alternative?

EDIT : Here’s the file I am using:

#import "TUTSimpleScatterPlot.h"

@implementation TUTSimpleScatterPlot

@synthesize hostingView = _hostingView;
@synthesize graph = _graph;
@synthesize graphData = _graphData;

-(id)initWithHostingView:(CPTGraphHostingView *)hostingView andData:(NSMutableArray *)data {
    self = [super init];

    if (self != nil) {
        self.hostingView = hostingView;
        self.graphData = data;
        self.graph = nil;
    }
    return self;
}

-(void)initialisePlot {

    if ((self.hostingView == nil) || (self.graphData == nil)) {
        NSLog(@"TUTSimpleScatterPlot: Cannot Initialise plot with hosting view and data");
        return;
    }

    if (self.graph != nil) {
        NSLog(@"TUTSimpleScatterPlot: Graph Object already exists.");
    }
    NSDate *refDate = [NSDate date];
    NSTimeInterval oneDay = 24 * 60 * 60;

    CGRect frame = [self.hostingView bounds];
    self.graph = [[CPTXYGraph alloc] initWithFrame:frame];

    CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)self.graph.defaultPlotSpace;
    plotSpace.allowsUserInteraction = YES;
    plotSpace.delegate = self;
    self.graph.plotAreaFrame.paddingBottom = 20.0f;
    self.graph.plotAreaFrame.paddingLeft = 35.0f;


    self.hostingView.hostedGraph = self.graph;

    CPTMutableLineStyle *lineStyle = [CPTMutableLineStyle lineStyle];
    lineStyle.lineColor = [CPTColor whiteColor];
    lineStyle.lineWidth = 2.0f;

    CPTMutableLineStyle *lineStyleThin = [CPTMutableLineStyle lineStyle];
    lineStyleThin.lineColor = [CPTColor whiteColor];
    lineStyleThin.lineWidth = 1.0f;

    CPTMutableTextStyle *textStyle = [CPTMutableTextStyle textStyle];
    textStyle.fontName = @"HelveticaNeue-Medium";
    textStyle.fontSize = 10;
    textStyle.color = [CPTColor whiteColor];

    CPTMutableLineStyle *plotSymbolLineStyle = [CPTMutableLineStyle lineStyle];
    plotSymbolLineStyle.lineColor = [CPTColor whiteColor];
    plotSymbolLineStyle.lineWidth = 1.0f;

    CPTPlotSymbol *plotSymbol = [CPTPlotSymbol ellipsePlotSymbol];
    plotSymbol.lineStyle = plotSymbolLineStyle;
    plotSymbol.fill = [CPTFill fillWithColor:[CPTColor colorWithComponentRed:0.4 green:0.6 blue:0.8 alpha:1.0]];
    plotSymbol.size = CGSizeMake(8.0, 8.0);

    CPTScatterPlot *plot = [[CPTScatterPlot alloc] init];
    plot.dataSource = self;
    plot.identifier = @"mainPlot";

    [plotSpace scaleToFitPlots:[graph allPlots]];

    CPTMutablePlotRange *yRange = [plotSpace.yRange mutableCopy];
    [yRange expandRangeByFactor:CPTDecimalFromDouble(615)];
    plotSpace.yRange = yRange;

    plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(oneDay - (oneDay * 6.3f)) length:CPTDecimalFromFloat(oneDay * 6.6f)];
    plotSpace.allowsUserInteraction = YES;

    CPTPlotRange *globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(0.0f) length:CPTDecimalFromDouble(615.0f)];
    plotSpace.globalYRange = globalYRange;

    // Modify the graph's axis with a label, line style, etc
    CPTXYAxisSet *axisSet = (CPTXYAxisSet *)self.graph.axisSet;

    axisSet.xAxis.axisConstraints = [CPTConstraints constraintWithLowerOffset:0.0]; 
    axisSet.xAxis.axisLineStyle = lineStyle;
    axisSet.xAxis.majorTickLineStyle = lineStyle;
    axisSet.xAxis.labelTextStyle = textStyle;
    axisSet.xAxis.labelOffset = 1.0f;
    axisSet.xAxis.majorIntervalLength = CPTDecimalFromFloat(oneDay*1);
    axisSet.xAxis.orthogonalCoordinateDecimal = CPTDecimalFromString(@"0.0");
    axisSet.xAxis.minorTicksPerInterval = 0;
    axisSet.xAxis.majorTickLength = 0.0f;
    axisSet.xAxis.majorGridLineStyle = majorGridLineStyle;

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"dd MMM"];
    CPTTimeFormatter *timeFormatter = [[CPTTimeFormatter alloc] initWithDateFormatter:dateFormatter];
    timeFormatter.referenceDate = refDate;
    axisSet.xAxis.labelFormatter = timeFormatter;

    axisSet.yAxis.axisLineStyle = lineStyle;
    axisSet.yAxis.majorTickLineStyle = lineStyle;
    axisSet.yAxis.minorTickLineStyle = lineStyleThin;
    axisSet.yAxis.labelTextStyle = textStyle;
    axisSet.yAxis.labelOffset = 3.0f;
    axisSet.yAxis.majorIntervalLength = CPTDecimalFromString(@"50.0");
    axisSet.yAxis.minorTicksPerInterval = 1;
    axisSet.yAxis.minorTickLength = 3.0;
    axisSet.yAxis.majorTickLength = 5.0;
    axisSet.yAxis.orthogonalCoordinateDecimal = CPTDecimalFromFloat(0);
    axisSet.yAxis.majorGridLineStyle = majorGridLineStyle;

    axisSet.yAxis.axisConstraints = [CPTConstraints constraintWithLowerOffset:0.0];

    CPTMutableLineStyle *theLineStyle = [CPTMutableLineStyle lineStyle];
    theLineStyle.lineColor = [CPTColor  colorWithComponentRed:0.3 green:0.6 blue:0.9 alpha:1.0];
    theLineStyle.lineWidth = 2.0f;

    plot.dataLineStyle = theLineStyle;
    plot.plotSymbol = plotSymbol;

    [self.graph addPlot:plot];

}
  • 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-31T16:26:57+00:00Added an answer on May 31, 2026 at 4:26 pm

    It looks like you’re using -scaleToFitPlots: correctly. This method will update the plot data if needed. Make sure the proper data is available to the datasource before you call it.

    Edit based on the new code:

    -scaleToFitPlots: is being called before you add the plot to the graph. Therefore the -allPlots array is empty and there is nothing to scale. Move the scaling operation after the plot is built and added to the graph.

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

Sidebar

Related Questions

I have implemented tracing based on System.Diagnostics. I am also using a System.Diagnostics.TextWriterTraceListener, and
I have implemented ADFS authentication for an asp.net 4.0 application. I have hosted the
I have implemented SQL Server session mode for an asp.net application. <sessionState mode=SQLServer compressionEnabled=true
I have implemented language localization to an Android application. My questions are: I can't
I have implemented a ViewFlipper with 8 child view in my application as follows.
I have a iPhone app with a CorePlot graph. I would like the user
I have implemented quartz scheduler in my application. And its working upto a certain
I have implemented delegate for scrollview in webview. Since , iOS 5 the default
I have implemented a view-based NSOutlineView in my project. I am using floating group
I have implemented a graph editor with Eclipse EMF and GMF frameworks. After completing

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.