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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:41:07+00:00 2026-06-04T19:41:07+00:00

I need help in plotting date vs number graph using CorePlot. I have already

  • 0

I need help in plotting date vs number graph using CorePlot. I have already checked out DatePlot. But my requirement is bit different which is as follows.

I have an array of objects where each object has got a NSDate and a Double number.
For ex:
Array of 5 objects: (NSDate in format yyyy-mm-dd)

  • Object1 – 2012-05-01 – 10.34
  • Object2 – 2012-05-02 – 10.56
  • Object3 – 2012-05-03 – 10.12
  • Object4 – 2012-05-04 – 10.78
  • Object5 – 2012-05-05 – 10.65

This data comes from a service and would differ every time.

Please advise.

  • 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-04T19:41:09+00:00Added an answer on June 4, 2026 at 7:41 pm

    I used a CPTScatterPlot to display a graph of time series data like yours.

    You need to create a data source class which will be queried by core plot when it is drawing the graph. My data source object contains an NSArray of objects with two attributes: observationDate and observationValue. The class has to implement the CPTPlotDataSource protocol. These are the protocol methods that I implemented:

    #pragma mark- CPPlotDataSource protocol methods
    - (NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot
    {
       // return the number of objects in the time series
       return [self.timeSeries count];
    }
    
    -(NSNumber *)numberForPlot:(CPTPlot *)plot 
                         field:(NSUInteger)fieldEnum 
                   recordIndex:(NSUInteger)index 
    {
      NSNumber * result = [[NSNumber alloc] init];
      // This method returns x and y values.  Check which is being requested here.
      if (fieldEnum == CPTScatterPlotFieldX)
      { 
        // x axis - return observation date converted to UNIX TS as NSNumber
        NSDate * observationDate = [[self.timeSeries objectAtIndex:index] observationDate];
        NSTimeInterval secondsSince1970 = [observationDate timeIntervalSince1970];
        result = [NSNumber numberWithDouble:secondsSince1970]; 
      }
      else
      { 
        // y axis - return the observation value
        result = [[self.timeSeries objectAtIndex:index] observationValue];
      }
      return result;
    }
    

    Note that I am converting the date to a double – dates cannot be plotted directly. I implement other methods on the class to return values such as the start and end dates of the time series and the min/max values – these are useful when configuring the PlotSpace of your graph.

    Once you have initialised your data source you then assign it to the dataSource property of your CPTScatterPlot:

    ...
    CPTXYGraph * myGraph = [[CPTXYGraph alloc] initWithFrame:self.bounds];
    
    // define your plot space here (xRange, yRange etc.)
    ...
    
    CPTScatterPlot * myPlot = [[CPTScatterPlot alloc] initWithFrame:graph.defaultPlotSpace.accessibilityFrame];
    
    // graphDataSource is your data source class
    myPlot.dataSource = graphDataSource;
    [myGraph addPlot:myPlot];
    ...
    

    Have a look at the CPTTestApp in the core plot download for details of configuring your graph and plotspace. If you need any more details please ask. Good luck!

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

Sidebar

Related Questions

Hi probably quite a simple question but.. When plotting a graph using matplotlib.pyplot my
Need help. I have Graph API code that uses an auth token with offline
Need help using regex and powershell to accomplish the following. I have the following
Need help figuring this out. I have two tables user ---- name skills (comma
Need help parsing... In my code, I have a method that returns url.getHost();. But
Need help with deleting call log from multi numbers, using the following code i
Need help writing a script downloads data from google insight using c# this is
need help/guide for sql select query, I have 2 table stock and stock_history, in
need help regarding USSD Gateway. I have to develop an app, which will directly
need help in error in database pivot. i have table tamed table_score like below:

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.