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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:57:15+00:00 2026-05-22T14:57:15+00:00

I’m experimenting the Core Plot library for iOS. I’ve managed to show a graph

  • 0

I’m experimenting the Core Plot library for iOS. I’ve managed to show a graph with my information, however i’m unable to personalize the visualization as I want.
I’m trying to use a simple scatter plot to show the distance a user has traveled by day, between two dates. I’ve managed to create the data for plotting, but i’m having a hard time personalizing the plot, maybe somebody that has used this lib can help me 😉
My question is:
– If I only show the positive side of both x and y axis, I’m not able to see the labels.
– For example, if there are 31 days between the two dates, the x axis goes from 0 to 30. How do i change the labels to show the date, for instance startDate + x.
This is what I’ve done so far:

@interface DistanceChart : CPGraphHostingView <CPPlotDataSource> {
    CPXYGraph *graph;
    NSMutableArray *dataForPlot;
    RouteManager *routeManager;
    NSDate *startDate;
    NSDate *endDate;
}

@property (nonatomic, retain) NSMutableArray *dataForPlot;
@property (nonatomic, retain) RouteManager *routeManager;
@property (nonatomic, retain) NSDate *startDate;
@property (nonatomic, retain) NSDate *endDate;

- (void)initPlot;

@end



@implementation DistanceChart
@synthesize dataForPlot;
@synthesize routeManager;
@synthesize startDate;
@synthesize endDate;

- (void)initPlot {
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"dd-MM-yyyy"];
    self.startDate = [dateFormatter dateFromString:@"01-05-2011"];
    self.endDate = [dateFormatter dateFromString:@"31-05-2011"];

    //get the data
    self.dataForPlot = [routeManager getTotalDistanceByDay:routeManager.routes from:startDate to:endDate];
    NSLog(@"Data: %@", dataForPlot);


    graph = [[CPXYGraph alloc] initWithFrame:CGRectZero];
    self.hostedGraph = graph;

    graph.paddingLeft = 5;
    graph.paddingTop = 5;
    graph.paddingRight = 5;
    graph.paddingBottom = 5;

    // Setup plot space
    int days = [endDate timeIntervalSinceDate:startDate] / 60 / 60 / 24 + 1;

    CPXYPlotSpace *plotSpace = (CPXYPlotSpace *)graph.defaultPlotSpace;
    plotSpace.allowsUserInteraction = YES;
    plotSpace.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(0) length:CPDecimalFromFloat(days)];
    plotSpace.yRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(0) length:CPDecimalFromFloat(15)]; //TODO: set maximum Y according to max distance

    // Axes
    CPXYAxisSet *axisSet = (CPXYAxisSet *)graph.axisSet;
    CPXYAxis *x = axisSet.xAxis;
    x.majorIntervalLength = CPDecimalFromString(@"1");
    x.orthogonalCoordinateDecimal = CPDecimalFromString(@"0");
    x.minorTicksPerInterval = 1;

    CPXYAxis *y = axisSet.yAxis;
    y.majorIntervalLength = CPDecimalFromString(@"1");
    y.minorTicksPerInterval = 1;
    y.orthogonalCoordinateDecimal = CPDecimalFromString(@"0");
    x.labelRotation = M_PI/8;

    // Create a green plot area
    CPScatterPlot *dataSourceLinePlot = [[[CPScatterPlot alloc] init] autorelease];
    dataSourceLinePlot.identifier = @"Green Plot";

    CPMutableLineStyle *lineStyle = [[dataSourceLinePlot.dataLineStyle mutableCopy] autorelease];
    lineStyle.lineWidth = 2.f;
    lineStyle.lineColor = [CPColor greenColor];

    dataSourceLinePlot.dataLineStyle = lineStyle;
    dataSourceLinePlot.dataSource = self;

    // Put an area gradient under the plot above
    CPColor *areaColor = [CPColor colorWithComponentRed:0.3 green:1.0 blue:0.3 alpha:0.8];
    CPGradient *areaGradient = [CPGradient gradientWithBeginningColor:areaColor endingColor:[CPColor clearColor]];
    areaGradient.angle = -90.0f;
    CPFill *areaGradientFill = [CPFill fillWithGradient:areaGradient];
    dataSourceLinePlot.areaFill = areaGradientFill;
    dataSourceLinePlot.areaBaseValue = CPDecimalFromString(@"1.75");

    // Animate in the new plot, as an example
    dataSourceLinePlot.opacity = 0.0f;
    dataSourceLinePlot.cachePrecision = CPPlotCachePrecisionDecimal;
    [graph addPlot:dataSourceLinePlot];

    CABasicAnimation *fadeInAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
    fadeInAnimation.duration = 1.0f;
    fadeInAnimation.removedOnCompletion = NO;
    fadeInAnimation.fillMode = kCAFillModeForwards;
    fadeInAnimation.toValue = [NSNumber numberWithFloat:1.0];
    [dataSourceLinePlot addAnimation:fadeInAnimation forKey:@"animateOpacity"];
}

#pragma mark -
#pragma mark Plot Data Source Methods

- (NSUInteger)numberOfRecordsForPlot:(CPPlot *)plot 
{
    return [dataForPlot count];
}

- (NSNumber *)numberForPlot:(CPPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index 
{
    NSDecimalNumber *num = [[dataForPlot objectAtIndex:index] valueForKey:(fieldEnum == CPScatterPlotFieldX ? @"x" : @"y")];

    return num;
}

- (CPLayer *)dataLabelForPlot:(CPPlot *)plot recordIndex:(NSUInteger)index
{
    return nil;
}

- (void)dealloc {
    [dataForPlot release];
    [routeManager release];
    [startDate release];
    [endDate release];

    [super dealloc];
}

@end
  • 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-22T14:57:16+00:00Added an answer on May 22, 2026 at 2:57 pm

    You probably need to increase the padding to show the labels. You may also need to add padding on the plotAreaFrame.

    There are a couple of example programs (“DatePlot” and “MinorTickLabels”) included with Core Plot that show how to format dates and times on the axes.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
i want to parse a xhtml file and display in UITableView. what is the
I want to construct a data frame in an Rcpp function, but when I
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text

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.