Using Core Plot in an iPhone Application

Skill

Using Core Plot in an iPhone Application

Posted in:

The need to display a graph of some kind comes up surprisingly often when developing applications. Because of this, for almost every language and framework under the sun, there is some sort of graphing/plotting library (and sometimes a lot more than just one). While there is no built in library for graphing for iPhone applications, there is an open source library called Core Plot. This library is under active development and can be used to create a number of different types of graphs - if you want, you can check our their example page here.

Today we are going to be taking a look at how to get this library into your iPhone application, as well as how to use it to create a simple plot. But before we can do anything, first you have to go get the source for Core Plot. Because the library is still relatively new and under quick active development, there are no packages available - you have to get the source code straight from Core Plot's repository. So as a first step, you probably need to install Mercurial. Once you have that, getting the source is a simple matter of the following command:

hg clone http://core-plot.googlecode.com/hg/ core-plot

That last argument (in our case here core-plot) is the directory you want to check the code out to. Ok, now that we have the code, what do we do? Well, let's get an iPhone Xcode project going! For this tutorial, our project is going to be named "SOTC-CorePlotTest". The first thing to do after you get an Xcode project off the ground is drag the CorePlot-CocoaTouch.xcodeproj file from the core-plot/framework directory into your new project. When you do that, you will get the following dialog:

The defaults are fine - most of the time we don't want to copy the entire library into your project - we just want a reference to wherever you checked our core-plot. So leave "Copy items into destination group's folder" unchecked. One you click "Add" on this dialog, an entry for CorePlot-CocoaTouch.xcodeproj will show up the "Groups & Files" tree for your project:

Because the iPhone core-plot is a static library, it needs to be linked with your application. To do this, you need to grab the entry libCorePlot-CocoaTouch.a from the "Groups & Files" (it is a child of the CorePlot-CocoaTouch.xcodeproj entry) and drag it to "Link Binaries with Libraries" node in your application's target:

Now we have to tell Xcode that our application is dependent on the core plot library - that way the library gets built when we build our app. This is done in the settings window for the application target. Under the "General" tab, you can add CorePlot-CocoaTouch as a direct dependency:

But don't think we are done yet! Now we have to modify some build settings. You do this by going to the "Build" tab of the project settings (not the build tab of the settings widow you were just in - those were build settings for the target). In here there are two properties that we have to modify: "Header Search Paths" and "Other Linker Flags". There are a lot of properties, but fortunately Apple gives us a little filter box to find the properties that we want. So first, "Header Search Paths". Here we need to add the full path to the core-plot/framework directory:

Then we need to add the -ObjC linker flag, which causes the linker to "Loads all members of static archive libraries that define an Objective C class or a category". We need this flag because Core Plot uses Objective C categories on existing classes, and when compiling against it as a static library, the code for the categories is not linked into the final executable. This flag forces that code to be included.

Ok, we are almost done with all this configuration - just one more step. We have to add the built in Core Animation library to our project, because Core Plot is built on top of Core Animation. To do this, you add the QuartzCore framework to the project. Right click on the Frameworks folder in the "Groups & Files" tree and choose Add->Existing Framework and browse for QuartzCore:

Whew! We are finally set to actually start using Core Plot. If you created a simple window project when you started, you probably have an AppDelegate and a ViewController class in your classes folder (mine here are "CorePlotTestAppDelegate" and "CorePlotTestViewController"). We aren't going to worry about the AppDelegate class today - all the code we are going to write will be in the ViewController. So start off by pulling up the .h file for your controller (in my case "CorePlotTestViewController.h"). It probably looks something like this at the moment:

#import <UIKit/UIKit.h>

@interface CorePlotTestViewController : UIViewController
{
}

@end

Not much will change in this file, but there are a few things we are going to need to add:

#import <UIKit/UIKit.h>
#import "CorePlot-CocoaTouch.h"

@interface CorePlotTestViewController : UIViewController <CPPlotDataSource>
{
  CPXYGraph *graph;
}

@end

First off, we need to reference the Core Plot libraries with an import statement. Since this is an iPhone application, we pull in the "CocoaTouch" version of the header file. Now that we have that, we can make the other two changes - an instance variable (to hold our graph) and a protocol. The variable is self explanatory, but the protocol probably needs some explanation. In this case, this view controller is going to be the data source for our graph, and so it has to implement the protocol CPPlotDataSource. This protocol is defined in Core Plot and consists of two functions:

@protocol CPPlotDataSource <NSObject>

-(NSUInteger)numberOfRecords;

@optional

// Implement one of the following
-(NSArray *)numbersForPlot:(CPPlot *)plot
    field:(NSUInteger)fieldEnum
    recordIndexRange:(NSRange)indexRange;

-(NSNumber *)numberForPlot:(CPPlot *)plot
    field:(NSUInteger)fieldEnum
    recordIndex:(NSUInteger)index;

-(NSRange)recordIndexRangeForPlot:(CPPlot *)plot
    plotRange:(CPPlotRange *)plotRect;

@end

Well, four functions actually, but you only have to implement two of them. The first one is a getter for the number of data points on the plot (numberOfRecords), and the last three (of which you need to implement one) are functions for getting the specific value for a particular data point.

Ok, that is it for talking about our ViewController header file - but before we move on to the actual implementation, we have to do one other thing. A core plot graph cannot be hosted in just any UIView - it has to be hosted in a CPLayerHostingView. To get this to happen we have to change the base type of our view. So pull open the xib file for the view for this view controller, and change the base type of the view to CPLayerHostingView in the Identity Inspector:

Identity Inspector

Finally, some implementation code! We will start off with the implementation of the protocol you saw above. In our case we will actually be drawing two plots on one graph - one being the function x^2, and the other being 1/x:

-(NSUInteger)numberOfRecords {
  return 51;
}

-(NSNumber *)numberForPlot:(CPPlot *)plot
    field:(NSUInteger)fieldEnum
    recordIndex:(NSUInteger)index
{
  double val = (index/5.0)-5;

  if(fieldEnum == CPScatterPlotFieldX)
  { return [NSNumber numberWithDouble:val]; }
  else
  {
    if(plot.identifier == @"X Squared Plot")
    { return [NSNumber numberWithDouble:val*val]; }
    else
    { return [NSNumber numberWithDouble:1/val]; }
  }
}

For these plots, I am explicitly returning 51 data points spread over the x range -5 to 5. In a real application the data would probably be coming from somewhere, like a file or user input, but here we are just graphing functions. When numberForPlot is called, I take the data point index passed in and transform it to an x value between -5 and 5. If the function was called asking for the X value (when fieldEnum is CPScatterPlotFieldX), I just return it. Otherwise, depending on the the identifier of the plot, I return the value either squared or inverted.

So that takes care of generating data for the graph. Now we need to take care of the creation of the graph itself:

- (void)viewDidLoad {
  [super viewDidLoad];
 
  graph = [[CPXYGraph alloc] initWithFrame: self.view.bounds];
       
  CPLayerHostingView *hostingView = (CPLayerHostingView *)self.view;
  hostingView.hostedLayer = graph;
  graph.paddingLeft = 20.0;
  graph.paddingTop = 20.0;
  graph.paddingRight = 20.0;
  graph.paddingBottom = 20.0;

If you remember from the header file, graph is a instance variable, and here we are finally populating it. Here we are creating a CPXYGraph (currently the only type of graph Core Plot offers), and then setting it as the hosted layer in our view (which is actually a CPLayerHostingView thanks to the change in the xib file earlier). We also set some padding here to give the graph some space on the screen.

  CPXYPlotSpace *plotSpace = (CPXYPlotSpace *)graph.defaultPlotSpace;
  plotSpace.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(-6)
      length:CPDecimalFromFloat(12)];
  plotSpace.yRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(-5)
      length:CPDecimalFromFloat(30)];

A Core Plot graph can have many PlotSpaces. A PlotSpace is where individual plots live - but all plots in a plot space share the same range. In this case, we only need one PlotSpace, so we grab the default one. Here we are setting the x and y range of the plot space - one thing to note is that range is set in terms of position and length, not minimum and maximum values.

  CPLineStyle *lineStyle = [CPLineStyle lineStyle];
  lineStyle.lineColor = [CPColor blackColor];
  lineStyle.lineWidth = 2.0f;
       
  axisSet.xAxis.majorIntervalLength = [NSDecimalNumber decimalNumberWithString:@"5"];
  axisSet.xAxis.minorTicksPerInterval = 4;
  axisSet.xAxis.majorTickLineStyle = lineStyle;
  axisSet.xAxis.minorTickLineStyle = lineStyle;
  axisSet.xAxis.axisLineStyle = lineStyle;
  axisSet.xAxis.minorTickLength = 5.0f;
  axisSet.xAxis.majorTickLength = 7.0f;
  axisSet.xAxis.axisLabelOffset = 3.0f;
 
  axisSet.yAxis.majorIntervalLength = [NSDecimalNumber decimalNumberWithString:@"5"];
  axisSet.yAxis.minorTicksPerInterval = 4;
  axisSet.yAxis.majorTickLineStyle = lineStyle;
  axisSet.yAxis.minorTickLineStyle = lineStyle;
  axisSet.yAxis.axisLineStyle = lineStyle;
  axisSet.yAxis.minorTickLength = 5.0f;
  axisSet.yAxis.majorTickLength = 7.0f;
  axisSet.yAxis.axisLabelOffset = 3.0f;

In this large chunk of code, we are setting up various axes properties (all of which are pretty much self explanatory). There are already a huge number of properties that you can set on axes, and that number is only going to grow as Core Plot continues to improve.

Finally, let's add some plots:

  CPScatterPlot *xSquaredPlot = [[[CPScatterPlot alloc]
      initWithFrame:graph.defaultPlotSpace.bounds] autorelease];
  xSquaredPlot.identifier = @"X Squared Plot";
  xSquaredPlot.dataLineStyle.lineWidth = 1.0f;
  xSquaredPlot.dataLineStyle.lineColor = [CPColor redColor];
  xSquaredPlot.dataSource = self;
  [graph addPlot:xSquaredPlot];
 
  CPPlotSymbol *greenCirclePlotSymbol = [CPPlotSymbol ellipsePlotSymbol];
  greenCirclePlotSymbol.fill = [CPFill fillWithColor:[CPColor greenColor]];
  greenCirclePlotSymbol.size = CGSizeMake(2.0, 2.0);
  xSquaredPlot.defaultPlotSymbol = greenCirclePlotSymbol;  
 
  CPScatterPlot *xInversePlot = [[[CPScatterPlot alloc]
      initWithFrame:graph.defaultPlotSpace.bounds] autorelease];
  xInversePlot.identifier = @"X Inverse Plot";
  xInversePlot.dataLineStyle.lineWidth = 1.0f;
  xInversePlot.dataLineStyle.lineColor = [CPColor blueColor];
  xInversePlot.dataSource = self;
  [graph addPlot:xInversePlot];
}

In both cases we are creating scatter plots (CPScatterPlot), although there are other XY plot types (such as CPBarPlot). The key thing here is the setting of the dataSource property - you have to set that property to whatever object is going to provide data for that plot (i.e., the one that implemented the CPPlotDataSource protocol). In this case, it is the controller itself, so we just put self. For the inverse plot, all we do is color the line blue, but for the squared plot we do a little bit extra. The scatter plot allows for markers to be put at data points, and so in this case we have a small green circle at every point.

Well, that is it! You want to see what all this work looks like? If you were coding along, you could just hit "Go", but for those that weren't, here is a screenshot:

Graph Screenshot

Because that viewDidLoad function is spread across a couple code blocks and probably hard to just read (or copy), here is the CorePlotTestViewController.m file in one block:

//
//  CorePlotTestViewController.m
//  CorePlotTest
//

#import "CorePlotTestViewController.h"

@implementation CorePlotTestViewController

- (void)viewDidLoad {
  [super viewDidLoad];
 
  graph = [[CPXYGraph alloc] initWithFrame: self.view.bounds];
       
  CPLayerHostingView *hostingView = (CPLayerHostingView *)self.view;
  hostingView.hostedLayer = graph;
  graph.paddingLeft = 20.0;
  graph.paddingTop = 20.0;
  graph.paddingRight = 20.0;
  graph.paddingBottom = 20.0;

  CPXYPlotSpace *plotSpace = (CPXYPlotSpace *)graph.defaultPlotSpace;
  plotSpace.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(-6)
      length:CPDecimalFromFloat(12)];
  plotSpace.yRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(-5)
      length:CPDecimalFromFloat(30)];
 
  CPXYAxisSet *axisSet = (CPXYAxisSet *)graph.axisSet;
 
  CPLineStyle *lineStyle = [CPLineStyle lineStyle];
  lineStyle.lineColor = [CPColor blackColor];
  lineStyle.lineWidth = 2.0f;
       
  axisSet.xAxis.majorIntervalLength = [NSDecimalNumber decimalNumberWithString:@"5"];
  axisSet.xAxis.minorTicksPerInterval = 4;
  axisSet.xAxis.majorTickLineStyle = lineStyle;
  axisSet.xAxis.minorTickLineStyle = lineStyle;
  axisSet.xAxis.axisLineStyle = lineStyle;
  axisSet.xAxis.minorTickLength = 5.0f;
  axisSet.xAxis.majorTickLength = 7.0f;
  axisSet.xAxis.axisLabelOffset = 3.0f;
 
  axisSet.yAxis.majorIntervalLength = [NSDecimalNumber decimalNumberWithString:@"5"];
  axisSet.yAxis.minorTicksPerInterval = 4;
  axisSet.yAxis.majorTickLineStyle = lineStyle;
  axisSet.yAxis.minorTickLineStyle = lineStyle;
  axisSet.yAxis.axisLineStyle = lineStyle;
  axisSet.yAxis.minorTickLength = 5.0f;
  axisSet.yAxis.majorTickLength = 7.0f;
  axisSet.yAxis.axisLabelOffset = 3.0f;
       
  CPScatterPlot *xSquaredPlot = [[[CPScatterPlot alloc]
      initWithFrame:graph.defaultPlotSpace.bounds] autorelease];
  xSquaredPlot.identifier = @"X Squared Plot";
  xSquaredPlot.dataLineStyle.lineWidth = 1.0f;
  xSquaredPlot.dataLineStyle.lineColor = [CPColor redColor];
  xSquaredPlot.dataSource = self;
  [graph addPlot:xSquaredPlot];
 
  CPPlotSymbol *greenCirclePlotSymbol = [CPPlotSymbol ellipsePlotSymbol];
  greenCirclePlotSymbol.fill = [CPFill fillWithColor:[CPColor greenColor]];
  greenCirclePlotSymbol.size = CGSizeMake(2.0, 2.0);
  xSquaredPlot.defaultPlotSymbol = greenCirclePlotSymbol;  
 
  CPScatterPlot *xInversePlot = [[[CPScatterPlot alloc]
      initWithFrame:graph.defaultPlotSpace.bounds] autorelease];
  xInversePlot.identifier = @"X Inverse Plot";
  xInversePlot.dataLineStyle.lineWidth = 1.0f;
  xInversePlot.dataLineStyle.lineColor = [CPColor blueColor];
  xInversePlot.dataSource = self;
  [graph addPlot:xInversePlot];
}

-(NSUInteger)numberOfRecords {
  return 51;
}

-(NSNumber *)numberForPlot:(CPPlot *)plot field:(NSUInteger)fieldEnum  
      recordIndex:(NSUInteger)index
{
  double val = (index/5.0)-5;
  if(fieldEnum == CPScatterPlotFieldX)
  { return [NSNumber numberWithDouble:val]; }
  else
  {
    if(plot.identifier == @"X Squared Plot")
    { return [NSNumber numberWithDouble:val*val]; }
    else
    { return [NSNumber numberWithDouble:1/val]; }
  }
}

@end

Hope you found this intro to Core Plot useful! While it is still quite young as a plotting framework, it has a lot of potential (especially since it is the first one for the iPhone). You can grab a zip file below that holds the Xcode project we built today, if you want to try it out for yourself (although you will have to grab the core plot source separately - I did not include them). If you have any questions or comments, please leave them below.

Anonymous
07/05/2009 - 20:09

Theres a problem with the build. coreplot.h uses wrong folder directory for its includes (the folder is source and it writes CorePlot) Also, when I build and go the app stops in debug mode and I get EXC_BAD_ACCESS. It may be due to the app I put it in. I had a project already started it is a cocoa app I made with the apple tutorial and it had a main already would that generate the error?. It would be nice to show what kind of project to start it in if its better to start with a new project and maybe to specify what to do with the main.

reply

ybellavance@gmail.com
07/05/2009 - 22:50

I actually had to put coreplot.hg like it was for the examples I ran.

reply

ybellavance@gmail.com
07/05/2009 - 20:23

I also had to transfer some files from the iphoneOnly folder to the Source folder.

reply

ybellavance@gmail.com
07/05/2009 - 21:01

BTW, i was doing all the same steps but for a mac application and I changed all the iphone names for mac names

reply

xuberance
09/26/2009 - 18:16

Sorry for the newbie question:
What kind of mac osx application xcode project did you start out with to start integrating these changes to get it working on the mac rather than the iphone?

reply

ybellavance@gmail.com
07/05/2009 - 21:24

The following line does not work...it seems defaultPlotSymbol has been removed from the latest Core-plot release:

xSquaredPlot.defaultPlotSymbol = greenCirclePlotSymbol;

reply

ybellavance@gmail.com
07/05/2009 - 21:45

concerning that same last comment.

There are 2 problems with this. its a pointer not a var so -> should be used and secondly defaultPlotSymbol doesnt exist....only plotSymbols.

reply

ybellavance@gmail.com
07/05/2009 - 21:51

Me again sorry.....plotSymbol being protected with getter setter methods i put this line instead :

[xSquaredPlot setPlotSymbol:greenCirclePlotSymbol];

reply

ybellavance@gmail.com
07/05/2009 - 21:59

and finally im getting these warnings:

warning: incomplete implementation of class 'CorePlotTestViewController'
warning: method definition for '-numberOfRecordsForPlot:' not found
warning: class 'CorePlotTestViewController' does not fully implement the 'CPPlotDataSource' protocolThis is all with you example on the iphone simulator. The application still launches but I get a crash asking to send to apple

reply

ybellavance@gmail.com
07/05/2009 - 22:05

Me again, after commenting all the code in the controlller method no more crashes but of course my screen is white so something in the code is doing it.....By the way I liked your tutorial though I learned to link static libs with it :)...dont want to be too negative for nothing

reply

Brad Larson
07/08/2009 - 11:45

Sorry about the compile-time problems you're having. That's the problem with a framework at this stage, the APIs tend to change rapidly. In the case of the warning you're getting, you'll need to change

-(NSUInteger)numberOfRecords {

in the above code to the new

-(NSUInteger)numberOfRecordsForPlot:(CPPlot *)plot {

definition.

The white screen you're seeing may be due to the fact that the delegate method is missing and therefore won't report back how many data points need to be plotted.

If you have additional questions, I recommend posting them to the Google Group for this project at http://groups.google.com/group/coreplot-discuss?hl=en

reply

The Fattest
07/08/2009 - 13:29

Thanks for the response Brad, we will quickly get the tutorial above updated. You guys are doing an awesome job at really kicking some programming tail on core plot, keep it up.

reply

Joe Pritchard
07/08/2009 - 06:01

I am having exactly the same issues as the last post, any ideas???

reply

robotarmy
07/24/2009 - 05:09

I'm getting the following; any ideas? I think i set the paths right.

Building target “CorePlotTest” of project “CorePlotTest” with configuration “Debug” — (1 error, 3 warnings)
/Developer/upstat/core-plot/CorePlotTest/Classes/CorePlotTestViewController.m: In function '-[CorePlotTestViewController viewDidLoad]':
/Developer/upstat/core-plot/CorePlotTest/Classes/CorePlotTestViewController.m:60: error: request for member 'defaultPlotSymbol' in something not a structure or union
/Developer/upstat/core-plot/CorePlotTest/Classes/CorePlotTestViewController.m: At top level:
/Developer/upstat/core-plot/CorePlotTest/Classes/CorePlotTestViewController.m:87: warning: incomplete implementation of class 'CorePlotTestViewController'
/Developer/upstat/core-plot/CorePlotTest/Classes/CorePlotTestViewController.m:87: warning: method definition for '-numberOfRecordsForPlot:' not found
/Developer/upstat/core-plot/CorePlotTest/Classes/CorePlotTestViewController.m:87: warning: class 'CorePlotTestViewController' does not fully implement the 'CPPlotDataSource' protocol
/Developer/upstat/core-plot/CorePlotTest/Classes/CorePlotTestViewController.m:60: error: request for member 'defaultPlotSymbol' in something not a structure or union
/Developer/upstat/core-plot/CorePlotTest/Classes/CorePlotTestViewController.m: At top level:
/Developer/upstat/core-plot/CorePlotTest/Classes/CorePlotTestViewController.m:87: warning: incomplete implementation of class 'CorePlotTestViewController'
/Developer/upstat/core-plot/CorePlotTest/Classes/CorePlotTestViewController.m:87: warning: method definition for '-numberOfRecordsForPlot:' not found
/Developer/upstat/core-plot/CorePlotTest/Classes/CorePlotTestViewController.m:87: warning: class 'CorePlotTestViewController' does not fully implement the 'CPPlotDataSource' protocol
Build failed (1 error, 3 warnings)

reply

The Tallest
07/24/2009 - 07:07

See Brad's comment above - the CPPlotDataSource protocol has changed since I wrote this tutorial. I haven't tried to build against the latest code yet, so I don't know exactly what you have to do to fix it. But if you look at the protocol definition, it should be pretty obvious.

reply

Farhad
08/01/2009 - 15:30

I tried adding core-plot to my project using the steps above and these are the errors I"m getting

The compiling erros:

CorePlotProbes.h:No such file or directory
warnings: implicit declaration of function 'COREPLOT_LAYER_POSITION_CHANGE_ENABLED'
warnings:'CPLayer may not respond to '-className'

And for Linking errors:
i686-apple-darwin9-gcc-4.2.1: /Users/fn/Documents/iPhone/core-plot/framework/build/Debug-iphonesimulator/libCorePlot-CocoaTouch.a: No such file or directory

Any ideas?

reply

lws
08/02/2009 - 07:04

Farhad: You need to update from the repository, there was some dtrace stuff missing in the .xcodeproj file.

I get the same warning about "may not respond to '-className' and since warnings are treated like errors per configuration default, you should go and change that setting in the core-plot cocoa touch project file.

Another issue I'm having:

axisSet.xAxis.majorIntervalLength = [NSDecimalNumber decimalNumberWithString:@"5"];

is throwing an error, complaining axisSet would be undeclared (which is true, but why is it missing in the tutorial?)

reply

lws
08/02/2009 - 07:05

nvm, solution is to add:

CPXYAxisSet *axisSet = (CPXYAxisSet *)graph.axisSet;
right before the problem...

reply

Anonymous
08/03/2009 - 17:25

in the simulator works but on the real one not: any idea?
the error is: GDB: Program received signal: "SIGABRT"

reply

Lazio
08/05/2009 - 12:37

The problem is in this line:

layerHost.hostedLayer= graph;

Console throws:

*** -[NSDecimalNumber isGreaterThanOrEqualTo:]: unrecognized selector sent to instance 0x101680
2009-08-05 12:33:05.416 ChecarPlazas[1908:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSDecimalNumber isGreaterThanOrEqualTo:]: unrecognized selector sent to instance 0x101680'
2009-08-05 12:33:05.506 ChecarPlazas[1908:207] Stack: (

But in the simulator everything is OK...

reply

Lazio
08/05/2009 - 17:53

Problem solved:

add the next flag to the Linker:

-all_load

suerte carnales!!

reply

Mit in Austin, TX
08/09/2009 - 10:25

Lazio,

Thanks for that fix. Core Plot is not working on my iPhone. As I try to become more skilled in Objective C coding, I'd like to understand how you figured out that fix? Can you guide us through the steps to determine the all_load flag was missing? It seems random but I am sure it's not.

Thanks,
Amit

reply

tcash21
08/04/2009 - 10:43

These are the errors I keep receiving when trying to compile:

Line Location MainWindow.xib:3: The 'window' outlet of 'Layer Hosting View' is connected to 'Window' but 'window' is no longer defined on CPLayerHostingView.

Line Location CPLayer.h:3: error: CPPlatformSpecificDefines.h: No such file or directory
Line Location CPPlatformSpecificCategories.h:3: error: CPLayer.h: No such file or directory

reply

Anonymous
08/04/2009 - 22:51

I'm getting similar issues.. is there a resolution for this?

reply

Anonymous
08/05/2009 - 09:52

I found my problem. I didn't make the include path recursive

reply

Anonymous
08/04/2009 - 13:19

I'm having major issues just compiling the example code supplied in the zip file. I've downloaded core plot source and made sure all header search paths are correct. Anyone help!? Are you using The Simulator as the SDK?

Building target “CorePlot-CocoaTouch” of project “CorePlot-CocoaTouch” with configuration “Debug” — (1 error)
Checking Dependencies
error: There is no SDK with specified name or path 'Unknown Path'
error: There is no SDK with specified name or path 'Unknown Path'
Build failed (1 error)

reply

Chris
08/04/2009 - 19:44

I'm getting the same errors as the person above...

Building target “CorePlot-CocoaTouch” of project “CorePlot-CocoaTouch” with configuration “Debug” — (1 error)
Checking Dependencies
error: There is no SDK with specified name or path 'Unknown Path'
error: There is no SDK with specified name or path 'Unknown Path'
Build failed (1 error)

I'm sure I'm being dumb but could someone please set us straight?

Thank you!

Chris.

reply

Chris
08/04/2009 - 21:06

Forget it. I figured it out. I skipped a step in the tutorial set-up.

Thanks!

reply

The Reddest
08/05/2009 - 08:32

Which step did you skip? The other guys might have skipped the same step.

reply

Chris
08/05/2009 - 21:18

Good point...

You know, I'm not sure. I only assumed I did 'cause I went back and followed the tutorial's setup carefully from scratch and it worked. I'm known (worldwide) for skimming through the manual and getting all messed up :)

I have another question though:

Has anyone seen the view invert when closing the example app running in the iPhone simulator? I'm actually seeing it in all the example iPhone projects. Anyone know what the deal is there? I love the API, but, I'm not sure I want to use it in my apps unless I can get that (very minor) issue resolved. For all I know, it's something I'm doing, but, I don't think so as I didn't edit any of the code...BTW - I'm using the 2.2.1 SDK.

Great Job, Guys!

Chris.

reply

Anonymous
08/06/2009 - 09:39

Chris if you can please figure out what you changed that would help a ton! I've followed the tutorial about 5 times now. I get different errors whether I use the Simulator, Project Settings, or Debug vs. Release modes to build and Go.

If I use Simulator and Debug, my first error is:
error: CPPlatformSpecificDefines.h: No such file or directory
error: CPLayer.h No such file or directory.

Help Please!!!

reply

Chris
08/06/2009 - 14:26

OK...

Here's what I did, exactly...

1) installed Mercurial (http://www.selenic.com/mercurial/wiki/)
2) Cloned the code base (hg clone http://core-plot.googlecode.com/hg/ core-plot)
3) Grabbed the Sample Project from this Tutorial (http://www.switchonthecode.com/sites/default/files/713/source/SOTC-CorePlotTest.zip)
4) Went through the tutorial step by step. Obviously (or maybe not), the tutorial project is setup to use paths to the core-plot installation location on the tutorial developer's machine. I installed the core-plot framework at /Users/mycompname/ so when I added/edited the compiler flags I referenced my install location. (e.g. the HEADER_SEARCH_PATHS = /Users/mycompname/core-plot/framework/**) w/ recursive setting ON).

My dev envorinment looks like this:
computer - intel MacBook pro (5 months old)
iPhone SDK - 2.2.1
Project Target - iPhone Simulator 2.2.1 DEBUG

I don't know what else to say.

It sounds like your paths are setup all the way. Especially since you get different errors for different targets...as unless you have identical global project/target settings for all you builds.

I hope this helps you. I know how frustrating this can be.

My suggestion is to start from scratch. Do what I outlined (with very special attention paid to following the tuorials step for edit the settings for the TARGET and the PROJECT...they're very different). Do that and get back to us/me...we'll get you sorted out...then you can help the next guy/gal :)

Peace and cars that run on chicken grease!

Chris.

reply

Tulius Lima
11/12/2009 - 12:41

Hi!

I was getting this same error. But doing the recursive thing (and paying attention to the TARGET and PROJECT settings) got me going....to the next error (which is better than nothing).

I imported "CorePlot-CocoaTouch.h" in my ViewController, and now I am getting the following error:
"CorePlot-CocoaTouch.h: No such file or directory"

I am at a lost...
Can you help?
Thanks in Advance!

reply

George
12/28/2009 - 17:46

You forgot to tick the "Recursive" checkbox when you added the path to core-plot in the "Header Search Paths" in the build properties.

reply

Clems
04/06/2011 - 04:13

Where's that box?? wich setting takes with value in the Project Info window??? THANKS!

reply

Chris
08/06/2009 - 14:27

I meant = "It sounds like your paths AREN'T setup all the way."

reply

Mit in Austin, TX
08/08/2009 - 01:07

I'm getting this error.

*** -[UIView setHostedLayer:]: unrecognized selector sent to instance 0xf1e350
2009-08-08 01:03:00.588 FTPPro[14161:207] *** Terminating app due to uncaught exception '
NSInvalidArgumentException', reason: '*** -[UIView setHostedLayer:]: unrecognized selector sent to instance 0xf1e350'


Any ideas?

reply

Mit in Austin, TX
08/08/2009 - 01:51

Interface Builder error.

I did not set the class name of the view correctly. Fat fingered CPlayer instead of CPLayer...

If you see that error, you know where to go.

reply

mars
02/08/2010 - 21:45

im still getting this error...im unable to set up the view outlet in the Layer Hosting View (view) to the FIle's Owner outlet and vv...it just wont let me...why?

reply

Anonymous
03/05/2010 - 10:42

if you add .h files from core-plot to your project you will not have this crash

reply

Tatyana
08/14/2009 - 04:00

Great job!!! Thank you.
It works with a few modifications.
Complete code looks like this:

-(NSUInteger)numberOfRecordsForPlot:(CPPlot *)plot{
        return 51;
}

-(NSNumber *)numberForPlot:(CPPlot *)plot
                                         field:(NSUInteger)fieldEnum
                           recordIndex:(NSUInteger)index
{
        double val = (index/5.0)-5;
       
        if(fieldEnum == CPScatterPlotFieldX)
        { return [NSNumber numberWithDouble:val]; }
        else
        {
                if(plot.identifier == @"X Squared Plot")
                { return [NSNumber numberWithDouble:val*val]; }
                else
                { return [NSNumber numberWithDouble:1/val]; }
        }
}

- (void)viewDidLoad {
    [super viewDidLoad];
       
        graph = [[CPXYGraph alloc] initWithFrame: self.view.bounds];
        self.view = [[CPLayerHostingView alloc]initWithFrame:[UIScreen mainScreen].bounds];
        CPLayerHostingView *hostingView = (CPLayerHostingView *)self.view;
        hostingView.hostedLayer = graph;
        graph.paddingLeft = 20.0;
        graph.paddingTop = 20.0;
        graph.paddingRight = 20.0;
        graph.paddingBottom = 20.0;
       
       
        CPXYPlotSpace *plotSpace = (CPXYPlotSpace *)graph.defaultPlotSpace;
        plotSpace.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(-6)
                                                                                                   length:CPDecimalFromFloat(12)];
        plotSpace.yRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(-5)
                                                                                                   length:CPDecimalFromFloat(30)];
       
       
       
        CPLineStyle *lineStyle = [CPLineStyle lineStyle];
        lineStyle.lineColor = [CPColor blackColor];
        lineStyle.lineWidth = 2.0f;
       
        CPXYAxisSet *axisSet = (CPXYAxisSet *)graph.axisSet;
        axisSet.xAxis.majorIntervalLength = [NSDecimalNumber decimalNumberWithString:@"5"];
        axisSet.xAxis.minorTicksPerInterval = 4;
        axisSet.xAxis.majorTickLineStyle = lineStyle;
        axisSet.xAxis.minorTickLineStyle = lineStyle;
        axisSet.xAxis.axisLineStyle = lineStyle;
        axisSet.xAxis.minorTickLength = 5.0f;
        axisSet.xAxis.majorTickLength = 7.0f;
        axisSet.xAxis.axisLabelOffset = 3.0f;
       
        axisSet.yAxis.majorIntervalLength = [NSDecimalNumber decimalNumberWithString:@"5"];
        axisSet.yAxis.minorTicksPerInterval = 4;
        axisSet.yAxis.majorTickLineStyle = lineStyle;
        axisSet.yAxis.minorTickLineStyle = lineStyle;
        axisSet.yAxis.axisLineStyle = lineStyle;
        axisSet.yAxis.minorTickLength = 5.0f;
        axisSet.yAxis.majorTickLength = 7.0f;
        axisSet.yAxis.axisLabelOffset = 3.0f;
       
        CPScatterPlot *xSquaredPlot = [[[CPScatterPlot alloc]
                                                                        initWithFrame:graph.defaultPlotSpace.bounds] autorelease];
        xSquaredPlot.identifier = @"X Squared Plot";
        xSquaredPlot.dataLineStyle.lineWidth = 1.0f;
        xSquaredPlot.dataLineStyle.lineColor = [CPColor redColor];
        xSquaredPlot.dataSource = self;
        [graph addPlot:xSquaredPlot];
       
        CPPlotSymbol *greenCirclePlotSymbol = [CPPlotSymbol ellipsePlotSymbol];
        greenCirclePlotSymbol.fill = [CPFill fillWithColor:[CPColor greenColor]];
        greenCirclePlotSymbol.size = CGSizeMake(2.0, 2.0);

        [xSquaredPlot setPlotSymbol:greenCirclePlotSymbol];
       
        CPScatterPlot *xInversePlot = [[[CPScatterPlot alloc]
                                                                        initWithFrame:graph.defaultPlotSpace.bounds] autorelease];
        xInversePlot.identifier = @"X Inverse Plot";
        xInversePlot.dataLineStyle.lineWidth = 1.0f;
        xInversePlot.dataLineStyle.lineColor = [CPColor blueColor];
        xInversePlot.dataSource = self;
        [graph addPlot:xInversePlot];
}

reply

Ryan Brubaker
08/19/2009 - 14:30

Nice tutorial...thanks!

reply

Anonymous
08/28/2009 - 09:26

Hello,

I have got 2 errors when i try to compile :

* for x and y axis
axisSet.xAxis.majorIntervalLength = [NSDecimalNumber decimalNumberWithString:@"5"];
--> error : incompatible type for argument 1 of 'setMajorIntervalLenght'

axisSet.yAxis.majorIntervalLength = [NSDecimalNumber decimalNumberWithString:@"5"];
--> error : incompatible type for argument 1 of 'setMajorIntervalLenght'

Anyway I commented out these two lines to test. The build succed but unfortunatly when i run the app it gives me the following error :

dyld: Library not loaded: /System/Library/Frameworks/UIKit.framework/UIKit
Referenced from: /Users/yyy/iphone/testCorePlot/build/Debug-iphonesimulator/testCorePlot.app/testCorePlot
Reason: image not found

I'm new at objective-c and xcode it's certainly a simple step i forgot (i hope), so if someone has an idea i will be very happy ^^

regards

reply

gfwalters
08/30/2009 - 22:06

Just call the decimalValue method:

axisSet.xAxis.majorIntervalLength = [[NSDecimalNumber decimalNumberWithString:@"5"] decimalValue];

axisSet.yAxis.majorIntervalLength = [[NSDecimalNumber decimalNumberWithString:@"5"] decimalValue];

reply

Anonymous
08/31/2009 - 11:15

thank you gfwalters for reply but i found another way on core-plot google group discuss (http://groups.google.com/group/coreplot-discuss/browse_thread/thread/b4ccaedad834eb9e) there are a lot of information here.

axisSet.xAxis.majorIntervalLength = CPDecimalFromFlot(5.0);

it works for me :)

reply

Dave
06/30/2010 - 12:53

This info helped me get Core Plot working in my OS X test app which had this same error. Just leaving it here for others to find.

http://lists.apple.com/archives/Applescriptobjc-dev/2010/May/msg00032.html

reply

alan duncan
09/01/2009 - 21:57

Summary of what I did to get this to work on both the simulator and the device:
http://alanduncan.net/index.php?q=node/22

reply

Anonymous
09/05/2009 - 07:03

Hi Alan,

How can i customize the axis label.

I want to have the month name (Jan, Feb, Mar...) & so on in the X-Axis.
When i set the axisLabelingPolicy is equal to CPAxisLabelingPolicyNone & try to create my own axis labels, I get the following error
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFArray allObjects]: unrecognized selector sent to instance 0xe9b6c0'.

reply

Techjunkie
09/06/2009 - 07:39

>axisSet.xAxis.majorIntervalLength = CPDecimalFromFlot(5.0);

Should be,

axisSet.xAxis.majorIntervalLength = CPDecimalFromFloat(5.0);

Got it working in the simulator now and will try it on the device shortly.

reply

Techjunkie
09/06/2009 - 07:53

Yeah - the "-all_load" flag made it run on the device too. :)

reply

xuberance
09/26/2009 - 18:19

Hi Brad et al. Thanks for your tutorial. It was very helpful and descriptive.
I got the basic plot feature working on the iphone simulator. Could anyone point out how I could possibly integrate thse changes to create an interactive plotting application on the mac using the core plot framework?
TIA, cheers!

reply

Anonymous
11/23/2009 - 06:39

Hi,
I have study this example and work fine, only my problem is that label not appear in te axis, why?
thanks for all

reply

ss5346
12/16/2009 - 22:33

can i write a word like @"ABC" on the core-plot graph?

if use core-plot example ex.CPTestApp-iPhone

can i write words on the graph?

or can i create a label on th graph?

please teach me!!

thanks!!

reply

iPhonenoob
01/11/2010 - 21:17

Hi,

Has anyone encountered this error when compiling?

error:redefinition of typedef 'CPNativeImage'

Thanks everyone!

reply

coreplotuser
01/26/2010 - 05:43

You might want to check that you have not included both MacOS and iPhone specific headers in the header search path.

reply

coreplotuser
01/26/2010 - 05:44

You've mentioned that you can include multiple PlotSpaces in a single plot. How do I assign a second PlotSpace to a single graph? Right now I only have access to the default PlotSpace.

reply

hiro
02/06/2010 - 07:12

Hi,

I'm getting this error.

/Users/xxxx/XcodeProject/SOTC-CorePlotExample/SOTC_CorePlotExampleViewController.xib:-1:0 The 'view' outlet of 'File's Owner' is connected to 'Layer Hosting View' but 'CPLayerHostingView' is not a kind of 'UIView' as specified by the outlet type.

Help please!

Thank you!

reply

mars
02/08/2010 - 21:53

In the CPTestApp, ive started coding it from scratch for my own use. All is fine, but it crashes saying Unknown Class CPLayerHostingView in IB, [UIView setHostedLayer:] unrecognized selector.

In IB, i can see that the MainWIndow.xib is fine, everything identical, set up properly. But in the individual xib files, for each individual UIView, the view outlet is connected to files owner but in yellow and the alert reads:

The view outlet of Files Owner is connected to Layer Hosting View but CPLayerHostingView is not a kind of UIView as specified by the outlet type...

any ideas? Ive tried starting the file from scratch again but i get the same error.

reply

mars
02/09/2010 - 12:03

i got it to work....ok, i added the -all_load -ObjC flag in the Target>Settings....I think this is where everyone gets confused...

There are 2 places where to put the other link and header search paths, in Project Settings and in Target Settings...I found these following things confusing:

1) where to add the Header Search Paths &IF Recursive or not &IF framework/ &OR framework/iPhoneonly &OR framework/Source &IF to check Always Search User Paths or not.
2) where to add the Other Links &IF to check Link with Std Libraries or Not

thx
mars
www.santiapps.com

reply

ghegazi
02/26/2010 - 21:57

Has anyone figured out this issue:

/Users/ghegazi/Documents/SOTC_CorePlotTest/SOTC_CorePlotTestViewController.xib:-1:0 The 'view' outlet of 'File's Owner' is connected to 'Layer Hosting View' but 'CPLayerHostingView' is not a kind of 'UIView' as specified by the outlet type.

I got everything else right.

reply

Ni
03/05/2010 - 17:21

I download the code, and run it on my mac.

I got the following errors:
error: incompatible type for argument 1 of 'setMajorIntervalLength:'
error: request for member 'axisLabelOffset' in something not a structure or union
error: incompatible type for argument 1 of 'setMajorIntervalLength:'
error: incompatible type for argument 1 of 'setMajorIntervalLength:'
and etc 7 errors. Anyone have any ideas what's going wrong here??

reply

TCorlett
03/20/2010 - 21:30

Try:
// axisSet.xAxis.majorIntervalLength = [[NSDecimalNumber decimalNumberWithString:@"5"] decimalValue];
axisSet.xAxis.majorIntervalLength = CPDecimalFromFloat(5.0);
And
// axisSet.xAxis.axisLabelOffset = 3.0f;
axisSet.xAxis.labelOffset = 3.0f;

reply

TCorlett
03/20/2010 - 22:13

Ali in all; to get the copy I downloaded working:

// axisSet.xAxis.majorIntervalLength = [[NSDecimalNumber decimalNumberWithString:@"5"] decimalValue];
axisSet.xAxis.majorIntervalLength = CPDecimalFromFloat(5.0);
axisSet.xAxis.minorTicksPerInterval = 4;
axisSet.xAxis.majorTickLineStyle = lineStyle;
axisSet.xAxis.minorTickLineStyle = lineStyle;
axisSet.xAxis.axisLineStyle = lineStyle;
axisSet.xAxis.minorTickLength = 5.0f;
axisSet.xAxis.majorTickLength = 7.0f;
// axisSet.xAxis.axisLabelOffset = 3.0f;
axisSet.xAxis.labelOffset = 3.0f;

axisSet.yAxis.majorIntervalLength = [[NSDecimalNumber decimalNumberWithString:@"5"] decimalValue];
axisSet.yAxis.minorTicksPerInterval = 4;
axisSet.yAxis.majorTickLineStyle = lineStyle;
axisSet.yAxis.minorTickLineStyle = lineStyle;
axisSet.yAxis.axisLineStyle = lineStyle;
axisSet.yAxis.minorTickLength = 5.0f;
axisSet.yAxis.majorTickLength = 7.0f;
// axisSet.yAxis.axisLabelOffset = 3.0f;
axisSet.yAxis.labelOffset = 3.0f;
// CPScatterPlot *xSquaredPlot = [[[CPScatterPlot alloc]
// initWithFrame:graph.defaultPlotSpace.bounds] autorelease];
CPScatterPlot *xSquaredPlot = [[[CPScatterPlot alloc]initWithFrame:
CGRectMake(90, 12, 200, 25)] autorelease];
xSquaredPlot.identifier = @"X Squared Plot";
xSquaredPlot.dataLineStyle.lineWidth = 1.0f;
xSquaredPlot.dataLineStyle.lineColor = [CPColor redColor];
xSquaredPlot.dataSource = self;
[graph addPlot:xSquaredPlot];

CPPlotSymbol *greenCirclePlotSymbol = [CPPlotSymbol ellipsePlotSymbol];
greenCirclePlotSymbol.fill = [CPFill fillWithColor:[CPColor greenColor]];
greenCirclePlotSymbol.size = CGSizeMake(2.0, 2.0);
// xSquaredPlot.defaultPlotSymbol = greenCirclePlotSymbol;
xSquaredPlot.plotSymbol = greenCirclePlotSymbol;
// CPScatterPlot *xInversePlot = [[[CPScatterPlot alloc]
// initWithFrame:graph.defaultPlotSpace.bounds] autorelease];
CPScatterPlot *xInversePlot = [[[CPScatterPlot alloc]initWithFrame:
CGRectMake(90, 12, 200, 25)] autorelease];
xInversePlot.identifier = @"X Inverse Plot";
xInversePlot.dataLineStyle.lineWidth = 1.0f;
xInversePlot.dataLineStyle.lineColor = [CPColor blueColor];
xInversePlot.dataSource = self;
[graph addPlot:xInversePlot];
}

reply

sassi0910
03/17/2010 - 15:30

How can i zoom in the graph or relocate the graph ?

I will do it like in the sample code of "CPTestApp-iPhone"

Any ideas ?

Please help.

reply

Wayne Lo
04/21/2010 - 20:26

Great tutorial!

Regarding the header search paths setup, wouldn't it be better to enter a relative path for the framework folder instead of an absolute path? If the folder contains the project- and framework is moved, the search path is still valid.

reply

Oscar Peli
04/26/2010 - 05:43

My app works well inside the simulator but fails if run inside the device.
This is the error it raises:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFString sizeWithTextStyle:]: unrecognized selector sent to instance 0x407be60'

any idea?

reply

Sean
05/07/2010 - 22:19

Had same exact issue where the app ran in simulator but not in iPad.

A post above mentions the fix (and thanks as this post save me a bunch of time )...

Add these flags here in XCode 3.2.2 ...

Target>yourApp>GetInfo>Build>Settings>Linking>OtherLinkerFlags

-all_load -ObjC

reply

Anonymous
06/03/2010 - 06:14

VERY IMPORTANT: Make the search path recursive as mentioned by ErikCJordan

/Users/me/Documents/workspace/core-plot/framework//

Yes...thats two forward slashes followed by two stars

reply


07/29/2010 - 08:45

hey
im getting 2 errors saying this

error: CorePlot-CocoaTouch.h: No such file or directory
error: CorePlot-CocoaTouch.h: No such file or directory

any idea's

reply

atee
08/26/2010 - 16:13

I did several times, everything what creator and others wrote in this tutorial, but i'm stil getting error: CorePlot-CocoaTouch.h: No such file or directory
Can anyone help me, what can be the problem?

reply

atee
08/27/2010 - 14:57

I can import the .h file like this:

#import "/Users/atee/Documents/core-
plot/framework/CorePlot-CocoaTouch.h"

But then the compiler still have problem with CorePlot-CocoaTouch.h, its importing 61 headers, but the compiler cant find them.Please, help me!

reply

atee
08/27/2010 - 15:48

I have the solution!
you should verify that you set the "Header Search Paths" and "Other Linker Flags" for "All Configurations". There's a dropdown menu under the "Build" tab in the "Project Info".
It takes 8 hours from my life! :)

reply

Giri
02/09/2011 - 05:15

Hi,

I am getting the error " CorePlot-CocoaTouch.h: No such file or directory". I have kept the coreplot0.2.2 folder in the desktop. I used the following path for set header path.
"/Users/Giri/Desktop/iPhoneGraph/CorePlot 0.2.2/Source/framework".

is it correct ? please Help Me. Thanks in advance.

reply

umer
08/27/2010 - 20:13

Thanks Sean you helped me

reply

Dov
09/06/2010 - 14:22

I recently updated my app to use the latest version of core-plot and started getting these errors:

Syntax error before '^' token
and
'type name' declared as function returning a function.

I also see this warning '__IPHONE_OS_VERSION_MIN_REQUIRED' redefined - any thoughts or ideas are appreciated

reply

Dov
09/06/2010 - 14:24

I updated to alpharelease-0.1

reply

arjang
09/08/2010 - 14:51

I have the same problem/

reply

arjang
09/08/2010 - 14:52

with alpharelease-0.1

reply

rf
09/10/2010 - 12:04

If you're getting __IPHONE_OS_VERSION_MIN_REQUIRED redefine errors during build, try going into the CorePlot-CocoaTouch project's target and under the Build tab changing the 'iOS Deployment Target' to 'Compiler Default' (or match it with what's in your main app).

The problem seems to come up when the deployment targets for the main app and the core-plot library project are both defined but are mismatched.

HTH

reply

seb
11/24/2010 - 10:57

thanks a lot , you're right

reply

Lubakis
10/08/2010 - 06:22

So I have created a UITabBar application with 2 view controllers the one is a TableViewController and the second one has to hold a graph drawn with core plot. Everything is ok but my CorePlotView isn't calling it's methods. Any ideas why? I have linked everything in IB but the methods aren't called

reply

dconlisk
10/17/2010 - 06:17

I just upgraded my (working) project to iOS4 (upgraded to the latest version of XCode and downloaded the latest version of CorePlot) and I was having a lot of problems similar to the above.

The solution for me: I had to replace all references to CPLayerHostingView to CPGraphHostingView both in my code and in Interface Builder.

Hope that helps someone!

David

reply

Ajit
11/09/2010 - 04:09

Hello i still have some error running this code.If u could send me the Classes files with the Correction u made.Thanks..

reply

Ajit
11/11/2010 - 10:47

Finally it worked for me...Thanks.

reply

agrawalyogesh
11/11/2010 - 12:37

Ajit, what did you do to get this working

reply

jimmy
11/13/2010 - 23:12

Hello, the only change you have to make is to pass the correct address of the Framework and make changes regarding the Framework.That much will do.

Example.

../../core-plot/framework

OR

/Users/macbookpro/core-plot/framework

reply

Ka-rocks
11/10/2010 - 10:03

Thanks for the tutorial.
I have a problem. I couldn't change the base type to CPLayerHostingView or CPGraphHostingView. These options were not found in the drop-down list. How to change?
Using UIView , i got error.

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView setHostedGraph:]: unrecognized selector sent to instance 0x622d360'

Someone please help me.

reply

jimmy
11/13/2010 - 23:14

Just Replace the CPLayerHostingView with CPGraphHostingView both in code and the Nib file.That much will do.

reply

Ka-rocks
11/15/2010 - 01:06

Thanks for the reply. I figured it out. The option CPGraphHostingView, was not there in the drop down list of Base Class type in Xib inspector. But I manually typed it and set it. It works fine now.

reply

agrawalyogesh
11/11/2010 - 12:44

Hi,

I tried everything that has been said here but I am getting following error

Library not found for -lCorePlot

Command /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2 failed with exit code 1

I am using 4.2 compiler and 4.1 iOS

Please help

Thanks,

reply

bcraft73
11/11/2010 - 14:28

I am a seriously stumped newbie. I've followed the instructions to the letter, but when I compile (without actually coding ANYTHING yet), I get 69 compiler errors.

The header search paths seem to check out fine, and I made sure it was for "All configurations".

Same with the -all_load -ObjC in Other Linker Flags.

I am using Xcode 3.1-compatible project format, with iOS Device 3.2, and using the iPad Simulator 3.2.

Can someone seriously dumb it down for me? I can muddle my way through creating a graph, if I can just get the thing to compile at the outset. And is there anything special I need to do for the iPad?

reply

jimmy
11/12/2010 - 01:39

http://www.mediafire.com/?4gz9zopm0kbdh30

Its the working copy.Try it and dont forget to change the Framework Location on the Target Setting.

reply

agrawalyogesh
11/12/2010 - 10:25

Hi Jimmy, How do we use this code, into our project?

reply

garyshaf
11/12/2010 - 17:31

Has anyone encountered this error? I tried running the iPad demo:

CPTestApp-iPad[84:307] *** Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [nan nan]'

reply

agrawalyogesh
11/13/2010 - 12:30

Hi,

Finally I have got the code working: The only one change that you have to do apart from look into the below code is, in the interface builder use CPGraphHostingView instead of CPLayerHostingView for your view class.

If you want to install the core-plot using sdk and not the way it is described above, then please go over the the following link

http://stackoverflow.com/questions/4146341/core-plot-configuration-error/4173170#4173170

- (void)viewDidLoad {
    [super viewDidLoad];

       
        graph = [[CPXYGraph alloc] initWithFrame: self.view.bounds];
       
        self.view = [[CPGraphHostingView alloc]initWithFrame:[UIScreen mainScreen].bounds];
       
        CPGraphHostingView *hostingView = (CPGraphHostingView *)self.view;
        hostingView.hostedGraph = graph;
        graph.paddingLeft = 20.0;
        graph.paddingTop = 20.0;
        graph.paddingRight = 20.0;
        graph.paddingBottom = 20.0;
       
        CPXYPlotSpace *plotSpace = (CPXYPlotSpace *)graph.defaultPlotSpace;
        plotSpace.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(-6)
                                                                                                   length:CPDecimalFromFloat(12)];
        plotSpace.yRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(-5)
                                                                                                   length:CPDecimalFromFloat(30)];
       
       
        CPLineStyle *lineStyle = [CPLineStyle lineStyle];
        lineStyle.lineColor = [CPColor blackColor];
        lineStyle.lineWidth = 2.0f;
       
        CPXYAxisSet *axisSet = (CPXYAxisSet *)graph.axisSet;
        axisSet.xAxis.majorIntervalLength = [[NSDecimalNumber decimalNumberWithString:@"5"] decimalValue];
        axisSet.xAxis.minorTicksPerInterval = 4;
        axisSet.xAxis.majorTickLineStyle = lineStyle;
        axisSet.xAxis.minorTickLineStyle = lineStyle;
        axisSet.xAxis.axisLineStyle = lineStyle;
        axisSet.xAxis.minorTickLength = 5.0f;
        axisSet.xAxis.majorTickLength = 7.0f;
//      axisSet.xAxis.axisLabelOffset = 3.0f;
       
        axisSet.yAxis.majorIntervalLength = [[NSDecimalNumber decimalNumberWithString:@"5"] decimalValue];
        axisSet.yAxis.minorTicksPerInterval = 4;
        axisSet.yAxis.majorTickLineStyle = lineStyle;
        axisSet.yAxis.minorTickLineStyle = lineStyle;
        axisSet.yAxis.axisLineStyle = lineStyle;
        axisSet.yAxis.minorTickLength = 5.0f;
        axisSet.yAxis.majorTickLength = 7.0f;
//      axisSet.yAxis.axisLabelOffset = 3.0f;
       
        CPScatterPlot *xSquaredPlot = [[CPScatterPlot alloc] init];
                                                                        //initWithFrame:graph.defaultPlotSpace.bounds] autorelease];
        xSquaredPlot.identifier = @"X Squared Plot";
        xSquaredPlot.dataLineStyle.lineWidth = 1.0f;
        xSquaredPlot.dataLineStyle.lineColor = [CPColor redColor];
        xSquaredPlot.dataSource = self;
        [graph addPlot:xSquaredPlot];
       
        CPPlotSymbol *greenCirclePlotSymbol = [CPPlotSymbol ellipsePlotSymbol];
        greenCirclePlotSymbol.fill = [CPFill fillWithColor:[CPColor greenColor]];
        greenCirclePlotSymbol.size = CGSizeMake(2.0, 2.0);
        xSquaredPlot.plotSymbol = greenCirclePlotSymbol;  
       
        CPScatterPlot *xInversePlot = [[CPScatterPlot alloc] init];
                                                                        //initWithFrame:graph.defaultPlotSpace.bounds] autorelease];
        xInversePlot.identifier = @"X Inverse Plot";
        xInversePlot.dataLineStyle.lineWidth = 1.0f;
        xInversePlot.dataLineStyle.lineColor = [CPColor blueColor];
        xInversePlot.dataSource = self;
        [graph addPlot:xInversePlot];
}

reply

kwinkler
11/18/2010 - 21:09

Everything about the installation seem straightforward, except for the part about-

"add the full path to the core-plot/framework directory".

Using Spotlight, I can't find any directory named "core-plot/framework". I've tried various guesses for what this might refer to, but nothing works. I keep getting a build failure of-

No architectures to compile for (ONLY_ACTIVE_ARCH=YES, active arch=x86_64, VALID_ARCHS=armv6 armv7).

Any ideas of what I am missing?

reply

kwinkler
11/18/2010 - 23:28

After lots of trial and error, I finally got a link to the framework working. The error mentioned above was caused by creating a project for MacOS rather than iOS.

I'm still getting about twenty build errors, even after applying all of the fixes that are mentioned in the above thread. I will keep trying, but perhaps it is time to post a new version of the demo and installation procedures.

reply

Sysc
11/20/2010 - 19:44

Hello, I've been trying to add the core plot library for a while and it is still not working out. I am getting 138 errors. The main error is :

pbxcp: CorePlot-CocoaTouch.h: No such file or directory

I've added the header search path and other linkage stuff but still same errors.
My header search path is /Users/moeassi/Downloads/CorePlot_0.2.1/Source/framework
and Ive added the -ObjC and -all_load.
Please help

reply

Anonymous
01/03/2011 - 13:38

I also had this problem. To solve it just make sure the header search path is set as recursive (double click on it and select the "Recursive" option)

reply

Rajashekar
12/16/2010 - 13:34

Hi,

I was able to compile the code but I am getting an runtime exception, I have given the exception below.

I am using IOS 4.2, Xcode 3.2.5

Exception:

2010-12-16 10:30:07.156 MyCorePlotTest[9237:207] -[CPMutableNumericData setDataType:]: unrecognized selector sent to instance 0x4c10be0
(gdb) continue
2010-12-16 10:30:08.346 MyCorePlotTest[9237:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CPMutableNumericData setDataType:]: unrecognized selector sent to instance 0x4c10be0'
*** Call stack at first throw:
(
0 CoreFoundation 0x00f99be9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x010ee5c2 objc_exception_throw + 47
2 CoreFoundation 0x00f9b6fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x00f0b366 ___forwarding___ + 966
4 CoreFoundation 0x00f0af22 _CF_forwarding_prep_0 + 50
5 MyCorePlotTest 0x00005d3c -[CPPlot setCachedDataType:] + 288
6 MyCorePlotTest 0x00004ef3 -[CPPlot cacheNumbers:forField:atRecordIndex:] + 226
7 MyCorePlotTest 0x00008309 -[CPScatterPlot reloadDataInIndexRange:] + 312
8 MyCorePlotTest 0x00003d06 -[CPPlot reloadData] + 129
9 MyCorePlotTest 0x00003d4c -[CPPlot reloadDataIfNeeded] + 63
10 CoreFoundation 0x00f102cf -[NSArray makeObjectsPerformSelector:] + 239
11 MyCorePlotTest 0x00012343 -[CPGraph reloadDataIfNeeded] + 70
12 MyCorePlotTest 0x0001f7d3 -[CPLayer layoutAndRenderInContext:] + 147
13 MyCorePlotTest 0x0002c304 -[CPGraphHostingView drawRect:] + 294
14 UIKit 0x0037d6eb -[UIView(CALayerDelegate) drawLayer:inContext:] + 426
15 QuartzCore 0x00d409e9 -[CALayer drawInContext:] + 143
16 QuartzCore 0x00d405ef _ZL16backing_callbackP9CGContextPv + 85
17 QuartzCore 0x00d3fdea CABackingStoreUpdate + 2246
18 QuartzCore 0x00d3f134 -[CALayer _display] + 1085
19 QuartzCore 0x00d3ebe4 CALayerDisplayIfNeeded + 231
20 QuartzCore 0x00d3138b _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 325
21 QuartzCore 0x00d310d0 _ZN2CA11Transaction6commitEv + 292
22 UIKit 0x0034819f -[UIApplication _reportAppLaunchFinished] + 39
23 UIKit 0x00348659 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 690
24 UIKit 0x00352db2 -[UIApplication handleEvent:withNewEvent:] + 1533
25 UIKit 0x0034b202 -[UIApplication sendEvent:] + 71
26 UIKit 0x00350732 _UIApplicationHandleEvent + 7576
27 GraphicsServices 0x018cfa36 PurpleEventCallback + 1550
28 CoreFoundation 0x00f7b064 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
29 CoreFoundation 0x00edb6f7 __CFRunLoopDoSource1 + 215
30 CoreFoundation 0x00ed8983 __CFRunLoopRun + 979
31 CoreFoundation 0x00ed8240 CFRunLoopRunSpecific + 208
32 CoreFoundation 0x00ed8161 CFRunLoopRunInMode + 97
33 UIKit 0x00347fa8 -[UIApplication _run] + 636
34 UIKit 0x0035442e UIApplicationMain + 1160
35 MyCorePlotTest 0x000020f8 main + 102
36 MyCorePlotTest 0x00002089 start + 53
)
terminate called after throwing an instance of 'NSException'
Program received signal: “SIGABRT”.

reply

Oliver
01/16/2011 - 23:34

Hey,
After editing the code for the current coreplot SDK, I now have 0 errors and 0 warnings.
Unfortuantly the simulator dies on startup. The nib name in the .xib is set to CPGraphHostingView and seems to be working.

.h file:

#import <UIKit/UIKit.h>
#import "CorePlot-CocoaTouch.h"


@interface plot3ViewController : UIViewController <CPPlotDataSource>
{
       
        CPXYGraph *graph;
}
@end

.m file

- (void)viewDidLoad {
        [super viewDidLoad];
       
        graph = [[CPXYGraph alloc] initWithFrame: self.view.bounds];
       
        CPGraphHostingView *hostingView = (CPGraphHostingView *)self.view;
        hostingView.hostedGraph = graph;
        graph.paddingLeft = 20.0;
        graph.paddingTop = 20.0;
        graph.paddingRight = 20.0;
        graph.paddingBottom = 20.0;
       
        CPXYPlotSpace *plotSpace = (CPXYPlotSpace *)graph.defaultPlotSpace;
        plotSpace.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(-6) length:CPDecimalFromFloat(12)];
        plotSpace.yRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(-5) length:CPDecimalFromFloat(30)];
       
        CPXYAxisSet *axisSet = (CPXYAxisSet *)graph.axisSet;
       
        CPLineStyle *lineStyle = [CPLineStyle lineStyle];
        lineStyle.lineColor = [CPColor blackColor];
        lineStyle.lineWidth = 2.0f;
       
        axisSet.xAxis.majorIntervalLength = [[NSDecimalNumber decimalNumberWithString:@"5"] decimalValue];
        axisSet.xAxis.minorTicksPerInterval = 4;
        axisSet.xAxis.majorTickLineStyle = lineStyle;
        axisSet.xAxis.minorTickLineStyle = lineStyle;
        axisSet.xAxis.axisLineStyle = lineStyle;
        axisSet.xAxis.minorTickLength = 5.0f;
        axisSet.xAxis.majorTickLength = 7.0f;
//      axisSet.xAxis.axisLabelOffset = 3.0f;
       
//      axisSet.yAxis.majorIntervalLength = [NSDecimalNumber decimalNumberWithString:@"5"];
        axisSet.yAxis.minorTicksPerInterval = 4;
        axisSet.yAxis.majorTickLineStyle = lineStyle;
        axisSet.yAxis.minorTickLineStyle = lineStyle;
        axisSet.yAxis.axisLineStyle = lineStyle;
        axisSet.yAxis.minorTickLength = 5.0f;
        axisSet.yAxis.majorTickLength = 7.0f;
//      axisSet.yAxis.axisLabelOffset = 3.0f;
       
        CPScatterPlot *xSquaredPlot = [[CPScatterPlot alloc] init];
        xSquaredPlot.identifier = @"X Squared Plot";
        xSquaredPlot.dataLineStyle.lineWidth = 1.0f;
        xSquaredPlot.dataLineStyle.lineColor = [CPColor redColor];
//      xSquaredPlot.dataSource = self;
        [graph addPlot:xSquaredPlot];
       
        CPPlotSymbol *greenCirclePlotSymbol = [CPPlotSymbol ellipsePlotSymbol];
        greenCirclePlotSymbol.fill = [CPFill fillWithColor:[CPColor greenColor]];
        greenCirclePlotSymbol.size = CGSizeMake(2.0, 2.0);
        xSquaredPlot.plotSymbol = greenCirclePlotSymbol;  
       
        CPScatterPlot *xInversePlot = [[CPScatterPlot alloc] init];
        xInversePlot.identifier = @"X Inverse Plot";
        xInversePlot.dataLineStyle.lineWidth = 1.0f;
        xInversePlot.dataLineStyle.lineColor = [CPColor blueColor];
        xInversePlot.dataSource = self;
        [graph addPlot:xInversePlot];
}


-(NSUInteger)numberOfRecordsForPlot:(CPPlot *)plot {
        return 51;
}

-(NSNumber *)numberForPlot:(CPPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index {
        double val = (index/5.0)-5;
        if(fieldEnum == CPScatterPlotFieldX)
        { return [NSNumber numberWithDouble:val]; }
        else
        {
                if(plot.identifier == @"X Squared Plot")
                { return [NSNumber numberWithDouble:val*val]; }
                else
                { return [NSNumber numberWithDouble:1/val]; }
        }
}

@end

Any help would be appreciated. Thanks!

reply

Oliver
01/16/2011 - 23:44

Edit/Update:

.m file:

-(NSUInteger)numberOfRecordsForPlot:(CPPlot *)plot {
        return 51;
}

-(NSNumber *)numberForPlot:(CPPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index {
        double val = (index/5.0)-5;
        if(fieldEnum == CPScatterPlotFieldX)
        { return [NSNumber numberWithDouble:val]; }
        else
        {
                if(plot.identifier == @"X Squared Plot")
                { return [NSNumber numberWithDouble:val*val]; }
                else
                { return [NSNumber numberWithDouble:1/val]; }
        }
}

reply

Oliver
01/16/2011 - 23:45

sigh,

-(NSUInteger)numberOfRecordsForPlot:(CPPlot *)plot {
        return 51;
}

-(NSNumber *)numberForPlot:(CPPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index {
        double val = (index/5.0)-5;
        if(fieldEnum == CPScatterPlotFieldX)
        { return [NSNumber numberWithDouble:val]; }
        else
        {
                if(plot.identifier == @"X Squared Plot")
                { return [NSNumber numberWithDouble:val*val]; }
                else
                { return [NSNumber numberWithDouble:1/val]; }
        }
}


- (void)viewDidLoad {
    //[super viewDidLoad];
       
       
        graph = [[CPXYGraph alloc] initWithFrame: self.view.bounds];
       
        self.view = [[CPGraphHostingView alloc]initWithFrame:[UIScreen mainScreen].bounds];
       
        CPGraphHostingView *hostingView = (CPGraphHostingView *)self.view;
        hostingView.hostedGraph = graph;
        graph.paddingLeft = 20.0;
        graph.paddingTop = 20.0;
        graph.paddingRight = 20.0;
        graph.paddingBottom = 20.0;
       
        CPXYPlotSpace *plotSpace = (CPXYPlotSpace *)graph.defaultPlotSpace;
        plotSpace.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(-6)
                                                                                                   length:CPDecimalFromFloat(12)];
        plotSpace.yRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(-5)
                                                                                                   length:CPDecimalFromFloat(30)];
       
       
        CPLineStyle *lineStyle = [CPLineStyle lineStyle];
        lineStyle.lineColor = [CPColor blackColor];
        lineStyle.lineWidth = 2.0f;
       
        CPXYAxisSet *axisSet = (CPXYAxisSet *)graph.axisSet;
        axisSet.xAxis.majorIntervalLength = [[NSDecimalNumber decimalNumberWithString:@"5"] decimalValue];
        axisSet.xAxis.minorTicksPerInterval = 4;
        axisSet.xAxis.majorTickLineStyle = lineStyle;
        axisSet.xAxis.minorTickLineStyle = lineStyle;
        axisSet.xAxis.axisLineStyle = lineStyle;
        axisSet.xAxis.minorTickLength = 5.0f;
        axisSet.xAxis.majorTickLength = 7.0f;
        //      axisSet.xAxis.axisLabelOffset = 3.0f;
       
        axisSet.yAxis.majorIntervalLength = [[NSDecimalNumber decimalNumberWithString:@"5"] decimalValue];
        axisSet.yAxis.minorTicksPerInterval = 4;
        axisSet.yAxis.majorTickLineStyle = lineStyle;
        axisSet.yAxis.minorTickLineStyle = lineStyle;
        axisSet.yAxis.axisLineStyle = lineStyle;
        axisSet.yAxis.minorTickLength = 5.0f;
        axisSet.yAxis.majorTickLength = 7.0f;
        //      axisSet.yAxis.axisLabelOffset = 3.0f;
       
        CPScatterPlot *xSquaredPlot = [[CPScatterPlot alloc] init];
        //initWithFrame:graph.defaultPlotSpace.bounds] autorelease];
        xSquaredPlot.identifier = @"X Squared Plot";
        xSquaredPlot.dataLineStyle.lineWidth = 1.0f;
        xSquaredPlot.dataLineStyle.lineColor = [CPColor redColor];
        xSquaredPlot.dataSource = self;
        [graph addPlot:xSquaredPlot];
       
        CPPlotSymbol *greenCirclePlotSymbol = [CPPlotSymbol ellipsePlotSymbol];
        greenCirclePlotSymbol.fill = [CPFill fillWithColor:[CPColor greenColor]];
        greenCirclePlotSymbol.size = CGSizeMake(2.0, 2.0);
        xSquaredPlot.plotSymbol = greenCirclePlotSymbol;  
       
        CPScatterPlot *xInversePlot = [[CPScatterPlot alloc] init];
        //initWithFrame:graph.defaultPlotSpace.bounds] autorelease];
        xInversePlot.identifier = @"X Inverse Plot";
        xInversePlot.dataLineStyle.lineWidth = 1.0f;
        xInversePlot.dataLineStyle.lineColor = [CPColor blueColor];
        xInversePlot.dataSource = self;
        [graph addPlot:xInversePlot];
}


@end

reply

Anonymous
01/17/2011 - 20:31

I have the following error, even though, I followed all the settings suggested above. Any idea?

Command /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2 failed with exit code 1

reply

Anonymous
01/18/2011 - 08:05

I followed the instructions on googlecode, and made some changes according to the information I found here. This works for me:

-(NSUInteger)numberOfRecordsForPlot:(CPPlot *)plot{
        return 51;
}

-(NSNumber *)numberForPlot:(CPPlot *)plot
                                         field:(NSUInteger)fieldEnum
                           recordIndex:(NSUInteger)index
{
        double val = (index/5.0)-5;
       
        if(fieldEnum == CPScatterPlotFieldX)
        { return [NSNumber numberWithDouble:val]; }
        else
        {
                if(plot.identifier == @"X Squared Plot")
                { return [NSNumber numberWithDouble:val*val]; }
                else
                { return [NSNumber numberWithDouble:1/val]; }
        }
}

- (void)viewDidLoad {
    [super viewDidLoad];
       
        graph = [[CPXYGraph alloc] initWithFrame: self.view.bounds];
        self.view = [[CPGraphHostingView alloc]initWithFrame:[UIScreen mainScreen].bounds];
        CPGraphHostingView *hostingView = (CPGraphHostingView *)self.view;
        hostingView.hostedGraph = graph;
        graph.paddingLeft = 20.0;
        graph.paddingTop = 20.0;
        graph.paddingRight = 20.0;
        graph.paddingBottom = 20.0;
       
       
        CPXYPlotSpace *plotSpace = (CPXYPlotSpace *)graph.defaultPlotSpace;
        plotSpace.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(-6)
                                                                                                   length:CPDecimalFromFloat(12)];
        plotSpace.yRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(-5)
                                                                                                   length:CPDecimalFromFloat(30)];
       
       
       
        CPLineStyle *lineStyle = [CPLineStyle lineStyle];
        lineStyle.lineColor = [CPColor blackColor];
        lineStyle.lineWidth = 2.0f;
       
        CPXYAxisSet *axisSet = (CPXYAxisSet *)graph.axisSet;
        axisSet.xAxis.majorIntervalLength = [[NSDecimalNumber decimalNumberWithString:@"5"] decimalValue];
        axisSet.xAxis.minorTicksPerInterval = 4;
        axisSet.xAxis.majorTickLineStyle = lineStyle;
        axisSet.xAxis.minorTickLineStyle = lineStyle;
        axisSet.xAxis.axisLineStyle = lineStyle;
        axisSet.xAxis.minorTickLength = 5.0f;
        axisSet.xAxis.majorTickLength = 7.0f;
        //axisSet.xAxis.axisLabelOffset = 3.0f;
       
        axisSet.yAxis.majorIntervalLength = [[NSDecimalNumber decimalNumberWithString:@"5"] decimalValue];
        axisSet.yAxis.minorTicksPerInterval = 4;
        axisSet.yAxis.majorTickLineStyle = lineStyle;
        axisSet.yAxis.minorTickLineStyle = lineStyle;
        axisSet.yAxis.axisLineStyle = lineStyle;
        axisSet.yAxis.minorTickLength = 5.0f;
        axisSet.yAxis.majorTickLength = 7.0f;
        //axisSet.yAxis.axisLabelOffset = 3.0f;
       
        CPScatterPlot *xSquaredPlot = [[CPScatterPlot alloc] init];
        xSquaredPlot.identifier = @"X Squared Plot";
        xSquaredPlot.dataLineStyle.lineWidth = 1.0f;
        xSquaredPlot.dataLineStyle.lineColor = [CPColor redColor];
        xSquaredPlot.dataSource = self;
        [graph addPlot:xSquaredPlot];
       
        CPPlotSymbol *greenCirclePlotSymbol = [CPPlotSymbol ellipsePlotSymbol];
        greenCirclePlotSymbol.fill = [CPFill fillWithColor:[CPColor greenColor]];
        greenCirclePlotSymbol.size = CGSizeMake(2.0, 2.0);
       
        [xSquaredPlot setPlotSymbol:greenCirclePlotSymbol];
       
CPScatterPlot *xInversePlot = [[CPScatterPlot alloc] init];
        xInversePlot.identifier = @"X Inverse Plot";
        xInversePlot.dataLineStyle.lineWidth = 1.0f;
        xInversePlot.dataLineStyle.lineColor = [CPColor blueColor];
        xInversePlot.dataSource = self;
        [graph addPlot:xInversePlot];
}

Hope that helps someone.

reply

Bob Vaughan
01/21/2011 - 13:21

I am getting a compiler error with the sample code on the following two lines:

xSquaredPlot.dataLineStyle.lineWidth = 1.0f;
xSquaredPlot.dataLineStyle.lineColor = [CPColor redColor];

These two lines are repeated 3 times so I get six errors. All six lines get this error:

Object cannot be set - either readonly property or no setter found

What could be causing this?

reply

Anonymous
01/26/2011 - 09:54

I'm getting the following error:

 -[CPMutableNumericData setDataType:]: unrecognized selector sent to instance 0x4c4fb80
 Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CPMutableNumericData setDataType:]: unrecognized selector sent to instance 0x4c4fb80'
*** Call stack at first throw:
.....

Any Idea?

reply

Anonymous
01/26/2011 - 10:19

solved it:

Do you have the -all_load flag in your build settings.

reply

raihan
01/27/2011 - 07:35

following code shows error:

lineStyle.lineColor = [CPColor blackColor];
lineStyle.lineWidth = 2.0f;

xSquaredPlot.dataLineStyle.lineWidth = 1.0f;
xSquaredPlot.dataLineStyle.lineColor = [CPColor redColor];

xInversePlot.dataLineStyle.lineWidth = 1.0f;
xInversePlot.dataLineStyle.lineColor = [CPColor blueColor];

Object can not be set ..... either read only or no setter found

this error shown because in library their property is set read only
which can't be edit....

what is the soln...??

reply

Gonzalo
02/08/2011 - 22:31

I was seeing the same compile error. THis is because the category that redeclares the property as readwrite is located in the CPLineStyle implementation file (CPLineStyle.m). If you followed the tutorial from the Core Plot site as I did, you added only the Core Plot project to our own app's Xcode project and not all the sources. So, when we build our projects, the compiler knows nothing about what's in the implementation files of the dependent project. I "fixed" this by moving the CPLineStyle category into CPLineStyle.h.

reply

Sheik
06/08/2011 - 09:04

Aslkm
Am trying this from last 2 days have u got it .I have the errors #import "coreplot_......h" nosiuch file opr direcory.If u have integrated send me.

Thank u

reply

Anonymous
02/01/2011 - 09:27

I am getting CPLayerHostingView undeclared error. Please help me.

reply

Anonymous
02/08/2011 - 19:54

Use CPGraphHostingView in place of CPLayerHostingView

reply

Anonymous
02/01/2011 - 11:46

Hi.
Can I use core-plot with monoDevelop ?

reply

Anonymous
02/04/2011 - 09:10

This works for me;

-(NSUInteger)numberOfRecordsForPlot:(CPPlot *)plot{
        return 51;
}

-(NSNumber *)numberForPlot:(CPPlot *)plot
                                         field:(NSUInteger)fieldEnum
                           recordIndex:(NSUInteger)index
{
        double val = (index/5.0)-5;
       
        if(fieldEnum == CPScatterPlotFieldX)
        {
                return [NSNumber numberWithDouble:val];
        }
        else
        {
                if(plot.identifier == @"X Squared Plot")
                {
                        return [NSNumber numberWithDouble:val*val];
                }
                else
                {
                        return [NSNumber numberWithDouble:1/val];
                }
        }
}

- (void)viewDidLoad {
    [super viewDidLoad];
       
        graph = [[CPXYGraph alloc] initWithFrame: self.view.bounds];
        self.view = [[CPGraphHostingView alloc]initWithFrame:[UIScreen mainScreen].bounds];
        CPGraphHostingView *hostingView = (CPGraphHostingView *)self.view;
        hostingView.hostedGraph = graph;
        graph.paddingLeft = 20.0;
        graph.paddingTop = 20.0;
        graph.paddingRight = 20.0;
        graph.paddingBottom = 20.0;
       
       
        CPXYPlotSpace *plotSpace = (CPXYPlotSpace *)graph.defaultPlotSpace;
        plotSpace.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(-6)
                                                                                                   length:CPDecimalFromFloat(12)];
        plotSpace.yRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(-6)
                                                                                                   length:CPDecimalFromFloat(32)];
       
       
        CPMutableLineStyle *lineStyle = [CPMutableLineStyle lineStyle];
        lineStyle.lineWidth = 1.0f;
        lineStyle.lineColor = [CPColor grayColor];
       
        CPXYAxisSet *axisSet = (CPXYAxisSet *)graph.axisSet;
        axisSet.xAxis.majorIntervalLength = [[NSDecimalNumber decimalNumberWithString:@"1"] decimalValue];
        axisSet.xAxis.minorTicksPerInterval = 4;
        axisSet.xAxis.majorTickLineStyle = lineStyle;
        axisSet.xAxis.minorTickLineStyle = lineStyle;
        axisSet.xAxis.axisLineStyle = lineStyle;
        axisSet.xAxis.minorTickLength = 5.0f;
        axisSet.xAxis.majorTickLength = 7.0f;
        //axisSet.xAxis.axisLabelOffset = 3.0f;
       
        axisSet.yAxis.majorIntervalLength = [[NSDecimalNumber decimalNumberWithString:@"5"] decimalValue];
        axisSet.yAxis.minorTicksPerInterval = 4;
        axisSet.yAxis.majorTickLineStyle = lineStyle;
        axisSet.yAxis.minorTickLineStyle = lineStyle;
        axisSet.yAxis.axisLineStyle = lineStyle;
        axisSet.yAxis.minorTickLength = 5.0f;
        axisSet.yAxis.majorTickLength = 7.0f;
        //axisSet.yAxis.axisLabelOffset = 3.0f;
       
        CPScatterPlot *xSquaredPlot = [[CPScatterPlot alloc] init];
       
        xSquaredPlot.identifier = @"X Squared Plot";
       
        lineStyle = [[xSquaredPlot.dataLineStyle mutableCopy] autorelease];
        lineStyle.lineWidth = 1.0f;
    lineStyle.lineColor = [CPColor redColor];
    xSquaredPlot.dataLineStyle = lineStyle;
        xSquaredPlot.dataSource = self;
        [graph addPlot:xSquaredPlot];
       
        CPPlotSymbol *greenCirclePlotSymbol = [CPPlotSymbol ellipsePlotSymbol];
        greenCirclePlotSymbol.fill = [CPFill fillWithColor:[CPColor redColor]];
        greenCirclePlotSymbol.size = CGSizeMake(2.0, 2.0);
       
        [xSquaredPlot setPlotSymbol:greenCirclePlotSymbol];
       
        CPScatterPlot *xInversePlot = [[CPScatterPlot alloc] init];
        xInversePlot.identifier = @"X Inverse Plot";
        lineStyle = [[xInversePlot.dataLineStyle mutableCopy] autorelease];
        lineStyle.lineWidth = 2.0f;
    lineStyle.lineColor = [CPColor yellowColor];
    xInversePlot.dataLineStyle = lineStyle;
        xInversePlot.dataSource = self;
        [graph addPlot:xInversePlot];
}
 

reply

Anonymous
03/26/2011 - 17:25

OH SWEET JESUS THANK YOU DEAR GOD. This almost works!

If you're having trouble with this code use the Mutable variety of lineStyle.

reply

Wornish
03/30/2011 - 06:24

I am Using xcode4.0.1.
This builds OK without errors.
But when I run in the IOS simulator I get 2 errors

-[CPMutableNumericData setDataType:]: unrecognized selector sent to instance 0x4e1ed10

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CPMutableNumericData setDataType:]: unrecognized selector sent to instance 0x4e1ed10'

This seems to be coming from an issue in CPPLot.m any help appreciated

wornish

reply

Wornish
03/30/2011 - 06:45

Cracked it

I needed the -all_load in the other build settings

thanks to anonymous above

I'm off and running

reply

Giri
02/09/2011 - 05:00

Hi,

I am getting the error " CorePlot-CocoaTouch.h: No such file or directory". I have kept the coreplot0.2.2 folder in the desktop. I used the following path for set header path.
"/Users/Giri/Desktop/iPhoneGraph/CorePlot 0.2.2/Source/framework".

is it correct ? please Help Me. Thanks in advance.

reply

Cray
02/09/2011 - 07:41

Try to set "Headers Search Paths" in your target's settings instead of project settings.

reply

Anonymous
03/04/2011 - 05:36

Try this "/Users/Giri/Desktop/iPhoneGraph/CorePlot\ 0.2.2/Source/framework"

reply

cdor
02/12/2011 - 16:42

I can't get this to work. It gives me 168 erros!
First one saying: "CorePlot-CocoaTouch.h: no such file or directory"
Any help would be appreciated!
Thanks

reply

Anonymous
03/10/2011 - 09:39

Make the header path Recursive

reply

Wornish
03/30/2011 - 06:05

I am new to core plot and get the same problem CorePlot-CocoaTouch.h
No such file or directory and 162 issues.

You say to make the path to the header files recursive , how do you do that ?

reply

Wornish
03/30/2011 - 06:19

I found the check box in xcode4

reply

Cesare
02/14/2011 - 08:21

Got into this problem (when compiling for device)

"___switch32", referenced from:
-[CPPlotSymbol newSymbolPath] in libCorePlot-CocoaTouch.a(CPPlotSymbol.o)

Any hint?

reply

Oscars99
02/15/2011 - 19:37

I seem to be getting the same issue but don't know how to fix it. Please help

File /Users/oscar/core-plot/systemtests/tests/build/Debug-iphonesimulator/libCorePlot-CocoaTouch.a depends on itself. This target might include its own product.

reply

Martin Eigo
02/24/2011 - 10:02

In case anyone else has a problem with the line

lineStyle = [[xInversePlot.dataLineStyle mutableCopy] autorelease];

giving a selector not recognised error, try the following
lineStyle = [[xInversePlot.dataLineStyle copyWithZone:xInversePlot.dataLineStyle.zone] autorelease];

reply

Anonymous
03/05/2011 - 21:53

How do I get a Core Plot into an already existing window? In other words, say I've left a space on an already designed .xib. Now I want to add a graph in the middle of the page. Please help, and answer like I know nothing (which is very close to accurate).

reply

Anonymous
03/05/2011 - 21:59

Just to add more depth...in my .m file for the .xib, I have the following lines in my ViewDidLoad:

graph = [[CPXYGraph alloc] initWithFrame:self.view.bounds];
self.view = [[CPGraphHostingView alloc] initWithFrame:[UIScreen mainScreen].bounds];
CPGraphHostingView *hostingView = (CPGraphHostingView *)self.view;
hostingView.hostedGraph = graph;

This appears to override everything in the .xib and just present the graph. I'm looking for a fix to change this so it only appears as part of the screen without replacing my buttons, etc. Again, I don't know too much so if you could walk me through the steps that would be great!!!

reply

Anonymous
03/07/2011 - 07:06

Maybe try:
CPGraphHostingView *hostingview = [[CPGraphHostingView alloc] initWithFrame:[UIScreen mainScreen].bounds];
[self.view addSubView: hostingview];

reply

kriboogh
03/07/2011 - 07:08

When using "this works for me" code i get a "CPMutableLineStyle undefined" error on this line:
CPMutableLineStyle *lineStyle = [CPMutableLineStyle lineStyle];

Changing this to CPLineStyle it compiles but I get a SIGBRT when running the code:

[CPMutableNumericData setDataType:]: unrecognized selector sent to instance 0x6044600
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CPMutableNumericData setDataType:]: unrecognized selector sent to instance 0x6044600'

reply

kriboogh
03/07/2011 - 07:13

... and yes i have the -all_load flag set

reply

kriboogh
03/07/2011 - 07:41

i stand corrected, i had was looking in the core-plot proect settings not my project -all_load made it work :-)

reply

Abhijeet
04/01/2011 - 06:06

1.what is the difference between CPLayerHostingView and CPGraphHostingView?
2. how i call CPLayerHostingView in my application

reply

Anonymous
04/05/2011 - 20:03

I don't have any build errors, but when the app crashes upon start-up in the simulator.

If I comment-out this line, the app does not crash, but produces a blank, white view:

graph = [[CPXYGraph alloc] initWithFrame:self.view.bounds];

Any ideas?

reply

YM
04/16/2011 - 03:25

i kept getting the following errors

Undefined symbols for architecture i386:
"_OBJC_CLASS_$_CPXYGraph", referenced from:
objc-class-ref in CorePlotImplViewController.o
"_OBJC_CLASS_$_CPPlotRange", referenced from:
objc-class-ref in CorePlotImplViewController.o
"_OBJC_CLASS_$_CPLineStyle", referenced from:
objc-class-ref in CorePlotImplViewController.o
"_OBJC_CLASS_$_CPColor", referenced from:
objc-class-ref in CorePlotImplViewController.o
"_OBJC_CLASS_$_CPScatterPlot", referenced from:
objc-class-ref in CorePlotImplViewController.o
"_OBJC_CLASS_$_CPPlotSymbol", referenced from:
objc-class-ref in CorePlotImplViewController.o
"_OBJC_CLASS_$_CPFill", referenced from:
objc-class-ref in CorePlotImplViewController.o
".objc_class_name_NSNumber", referenced from:
pointer-to-literal-objc-class-name in libCorePlot.a(CPPlot.o)
pointer-to-literal-objc-class-name in libCorePlot.a(CPScatterPlot.o)
pointer-to-literal-objc-class-name in libCorePlot.a(CPBarPlot.o)
pointer-to-literal-objc-class-name in libCorePlot.a(CPUtilities.o)
pointer-to-literal-objc-class-name in libCorePlot.a(CPTradingRangePlot.o)
pointer-to-literal-objc-class-name in libCorePlot.a(CPPieChart.o)
".objc_class_name_NSMutableDictionary", referenced from:
pointer-to-literal-objc-class-name in libCorePlot.a(CPPlot.o)
pointer-to-literal-objc-class-name in libCorePlot.a(CPTheme.o)
".objc_class_name_NSDecimalNumber", referenced from:
pointer-to-literal-objc-class-name in libCorePlot.a(CPPlot.o)
pointer-to-literal-objc-class-name in libCorePlot.a(CPScatterPlot.o)
pointer-to-literal-objc-class-name in libCorePlot.a(CPBarPlot.o)
pointer-to-literal-objc-class-name in libCorePlot.a(NSNumberExtensions.o)
pointer-to-literal-objc-class-name in libCorePlot.a(CPUtilities.o)
pointer-to-literal-objc-class-name in libCorePlot.a(CPPlotRange.o)
pointer-to-literal-objc-class-name in libCorePlot.a(CPAxis.o)
...
".objc_class_name_NSMutableArray", referenced from:
pointer-to-literal-objc-class-name in libCorePlot.a(CPPlot.o)
pointer-to-literal-objc-class-name in libCorePlot.a(CPScatterPlot.o)
pointer-to-literal-objc-class-name in libCorePlot.a(CPBarPlot.o)
pointer-to-literal-objc-class-name in libCorePlot.a(CPGraph.o)
pointer-to-literal-objc-class-name in libCorePlot.a(CPTradingRangePlot.o)
pointer-to-literal-objc-class-name in libCorePlot.a(CPPieChart.o)
".objc_class_name_NSArray", referenced from:
pointer-to-literal-objc-class-name in libCorePlot.a(CPPlot.o)
pointer-to-literal-objc-class-name in libCorePlot.a(CPScatterPlot.o)
pointer-to-literal-objc-class-name in libCorePlot.a(CPBarPlot.o)
pointer-to-literal-objc-class-name in libCorePlot.a(CPGraph.o)
pointer-to-literal-objc-class-name in libCorePlot.a(CPAxisSet.o)
pointer-to-literal-objc-class-name in libCorePlot.a(CPTheme.o)
pointer-to-literal-objc-class-name in libCorePlot.a(CPTradingRangePlot.o)
...
".objc_class_name_NSException", referenced from:
pointer-to-literal-objc-class-name in libCorePlot.a(CPScatterPlot.o)
pointer-to-literal-objc-class-name in libCorePlot.a(CPBarPlot.o)
pointer-to-literal-objc-class-name in libCorePlot.a(CPGraph.o)
pointer-to-literal-objc-class-name in libCorePlot.a(CPGradient.o)
pointer-to-literal-objc-class-name in libCorePlot.a(CPLayer.o)
pointer-to-literal-objc-class-name in libCorePlot.a(CPXYPlotSpace.o)
pointer-to-literal-objc-class-name in libCorePlot.a(CPTheme.o)
...
".objc_class_name_NSNull", referenced from:
pointer-to-literal-objc-class-name in libCorePlot.a(CPScatterPlot.o)
pointer-to-literal-objc-class-name in libCorePlot.a(CPBarPlot.o)
".objc_class_name_NSValueTransformer", referenced from:
pointer-to-literal-objc-class-name in libCorePlot.a(CPScatterPlot.o)
pointer-to-literal-objc-class-name in libCorePlot.a(CPTradingRangePlot.o)
".objc_class_name_NSObject", referenced from:
.objc_class_name_CPPlotSymbol in libCorePlot.a(CPPlotSymbol.o)
.objc_class_name_CPPlotSpace in libCorePlot.a(CPPlotSpace.o)
.objc_class_name_CPPlotRange in libCorePlot.a(CPPlotRange.o)
.objc_class_name_CPFill in libCorePlot.a(CPFill.o)
.objc_class_name_CPGradient in libCorePlot.a(CPGradient.o)
.objc_class_name_CPImage in libCorePlot.a(CPImage.o)
.objc_class_name_CPLineStyle in libCorePlot.a(CPLineStyle.o)
...
".objc_class_name_NSNotificationCenter", referenced from:
pointer-to-literal-objc-class-name in libCorePlot.a(CPGraph.o)
pointer-to-literal-objc-class-name in libCorePlot.a(CPXYPlotSpace.o)
".objc_class_name_NSString", referenced from:
pointer-to-literal-objc-class-name in libCorePlot.a(CPUtilities.o)
pointer-to-literal-objc-class-name in libCorePlot.a(CPPlotRange.o)
pointer-to-literal-objc-class-name in libCorePlot.a(CPLayer.o)
pointer-to-literal-objc-class-name in libCorePlot.a(CPAxis.o)
pointer-to-literal-objc-class-name in libCorePlot.a(CPTextLayer.o)
pointer-to-literal-objc-class-name in libCorePlot.a(CPAxisLabel.o)
pointer-to-literal-objc-class-name in libCorePlot.a(CPAxisTitle.o)
...
".objc_class_name_NSScanner", referenced from:
pointer-to-literal-objc-class-name in libCorePlot.a(CPUtilities.o)
pointer-to-literal-objc-class-name in libCorePlot.a(CPAxis.o)
".objc_class_name_NSLocale", referenced from:
pointer-to-literal-objc-class-name in libCorePlot.a(CPPlotRange.o)
".objc_class_name_UIColor", referenced from:
pointer-to-literal-objc-class-name in libCorePlot.a(CPPlatformSpecificCategories.o)
pointer-to-literal-objc-class-name in libCorePlot.a(CPLayerHostingView.o)
".objc_class_name_NSMutableData", referenced from:
pointer-to-literal-objc-class-name in libCorePlot.a(CPLayer.o)
".objc_class_name_CALayer", referenced from:
.objc_class_name_CPLayer in libCorePlot.a(CPLayer.o)
".objc_class_name_NSMutableSet", referenced from:
pointer-to-literal-objc-class-name in libCorePlot.a(CPAxis.o)
".objc_class_name_NSNumberFormatter", referenced from:
pointer-to-literal-objc-class-name in libCorePlot.a(CPAxis.o)
.objc_class_name_CPTimeFormatter in libCorePlot.a(CPTimeFormatter.o)
".objc_class_name_NSSet", referenced from:
pointer-to-literal-objc-class-name in libCorePlot.a(CPAxis.o)
".objc_class_name_UIView", referenced from:
.objc_class_name_CPLayerHostingView in libCorePlot.a(CPLayerHostingView.o)
".objc_class_name_NSDateFormatter", referenced from:
pointer-to-literal-objc-class-name in libCorePlot.a(CPTimeFormatter.o)
".objc_class_name_NSDate", referenced from:
pointer-to-literal-objc-class-name in libCorePlot.a(CPTimeFormatter.o)
".objc_class_name_UIFont", referenced from:
pointer-to-literal-objc-class-name in libCorePlot.a(CPTextStylePlatformSpecific.o)
ld: symbol(s) not found for architecture i386
collect2: ld returned 1 exit status

any idea?

reply

Anonymous
05/04/2011 - 23:55

change
axisSet.xAxis.majorIntervalLength = [[NSDecimalNumber decimalNumberWithString:@"1"] decimalValue];

to

axisSet.xAxis.majorIntervalLength = CPDecimalFromString(@"5");

reply

karna
05/23/2011 - 04:25

Hi,

I am using core plat framework to plot a graph between probability(Y axis) and ratio(X axis).I have two arrays, each consisting of 700 values. When i plot the graph, the graph is drawn only for 30 too 700th value of array and not for 0 to 30th value. The value to be plotted are in float(ex. 0.986788876755). Will this create a problem. If i use plot symbol to plot the point, then the thirty points are get plotted and the line connecting the point is not visible. I am not sure where did i gone wrong. Please help me out. Thanks.

reply

dhan
05/23/2011 - 06:44

I have copied the latest source code from here , as well as latest coreplot framework from the code google and set the correct relative path too. But still i am getting the following error.

error: cannot find protocol declaration for 'CPPlotDataSource'

Urgent help is required.

reply

S.Philip
05/26/2011 - 20:14

How to add a button (or any control) to CPGraphHostingView ? When I try to add UIButton normally, It is covered by the CPGraphHostingView.

I have seen a similar post about this, but it says only to add the button to the parent view of CPGraphHostingView.

How can we add to the parent view?
can anybody help with a simple answer with example.

Thanks in advance.

-S.Philip

reply

Ivanka
06/03/2011 - 00:06

hi
I exactly followed the tutorial of adding the coreplot framework.

But still received the error CorePlot-CocoaTouch.h:No such file or directory ~~
anyone can help me ?
I'm in a hurry to get this corePlot work.

thanks a lot

reply

Ivanka
06/03/2011 - 00:57

BTW

Where should I put this??

@protocol CPPlotDataSource

-(NSUInteger)numberOfRecords;

@optional

// Implement one of the following
-(NSArray *)numbersForPlot:(CPPlot *)plot
field:(NSUInteger)fieldEnum
recordIndexRange:(NSRange)indexRange;

-(NSNumber *)numberForPlot:(CPPlot *)plot
field:(NSUInteger)fieldEnum
recordIndex:(NSUInteger)index;

-(NSRange)recordIndexRangeForPlot:(CPPlot *)plot
plotRange:(CPPlotRange *)plotRect;

@end

thanks

reply

Sheik
06/08/2011 - 08:40

I too have same problem have u solved it.If u have got guide me.

Thank u

reply

Sheik
06/08/2011 - 08:38

Hi,

i am trying to intergrate from 2 days, i have the errror /Users/nowpos/Desktop/TrackBP3511/CorePlotTestViewController.h:7:0 /Users/nowpos/Desktop/TrackBP3511/CorePlotTestViewController.h:7:32: error: CorePlot-CocoaTouch.h: No such file or directory

/Users/nowpos/Desktop/TrackBP3511/CorePlotTestViewController.h:16:0 /Users/nowpos/Desktop/TrackBP3511/CorePlotTestViewController.h:16: error: expected ')' before 'CPPlot'

/Users/nowpos/Desktop/TrackBP3511/CorePlotTestViewController.h:20:0 /Users/nowpos/Desktop/TrackBP3511/CorePlotTestViewController.h:20: error: expected ')' before 'CPPlot'

/Users/nowpos/Desktop/TrackBP3511/CorePlotTestViewController.h:24:0 /Users/nowpos/Desktop/TrackBP3511/CorePlotTestViewController.h:24: error: expected ')' before 'CPPlot'

/Users/nowpos/Desktop/TrackBP3511/CorePlotTestViewController.h:25:0 /Users/nowpos/Desktop/TrackBP3511/CorePlotTestViewController.h:25: error: expected ')' before 'CPPlotRange'

/Users/nowpos/Desktop/TrackBP3511/CorePlotTestViewController.h:31:0 /Users/nowpos/Desktop/TrackBP3511/CorePlotTestViewController.h:31: error: expected specifier-qualifier-list before 'CPXYGraph'

/Users/nowpos/Desktop/TrackBP3511/CorePlotTestViewController.m:14:0 /Users/nowpos/Desktop/TrackBP3511/CorePlotTestViewController.m:14: error: 'graph' undeclared (first use in this function)

/Users/nowpos/Desktop/TrackBP3511/CorePlotTestViewController.m:14:0 /Users/nowpos/Desktop/TrackBP3511/CorePlotTestViewController.m:14: error: 'CPXYGraph' undeclared (first use in this function)

/Users/nowpos/Desktop/TrackBP3511/CorePlotTestViewController.m:16:0 /Users/nowpos/Desktop/TrackBP3511/CorePlotTestViewController.m:16: error: 'CPLayerHostingView' undeclared (first use in this function)

/Users/nowpos/Desktop/TrackBP3511/CorePlotTestViewController.m:16:0 /Users/nowpos/Desktop/TrackBP3511/CorePlotTestViewController.m:16: error: 'hostingView' undeclared (first use in this function)

/Users/nowpos/Desktop/TrackBP3511/CorePlotTestViewController.m:16:0 /Users/nowpos/Desktop/TrackBP3511/CorePlotTestViewController.m:16: error: expected expression before ')' token

/Users/nowpos/Desktop/TrackBP3511/CorePlotTestViewController.m:23:0 /Users/nowpos/Desktop/TrackBP3511/CorePlotTestViewController.m:23: error: 'CPXYPlotSpace' undeclared (first use in this function)

/Users/nowpos/Desktop/TrackBP3511/CorePlotTestViewController.m:23:0 /Users/nowpos/Desktop/TrackBP3511/CorePlotTestViewController.m:23: error: 'plotSpace' undeclared (first use in this function)

/Users/nowpos/Desktop/TrackBP3511/CorePlotTestViewController.m:23:0 /Users/nowpos/Desktop/TrackBP3511/CorePlotTestViewController.m:23: error: expected expression before ')' token

/Users/nowpos/Desktop/TrackBP3511/CorePlotTestViewController.m:24:0 /Users/nowpos/Desktop/TrackBP3511/CorePlotTestViewController.m:24: error: 'CPPlotRange' undeclared (first use in this function)

/Users/nowpos/Desktop/TrackBP3511/CorePlotTestViewController.m:27:0 /Users/nowpos/Desktop/TrackBP3511/CorePlotTestViewController.m:27: error: 'CPXYAxisSet' undeclared (first use in this function)

/Users/nowpos/Desktop/TrackBP3511/CorePlotTestViewController.m:27:0 /Users/nowpos/Desktop/TrackBP3511/CorePlotTestViewController.m:27: error: 'axisSet' undeclared (first use in this function)

/Users/nowpos/Desktop/TrackBP3511/CorePlotTestViewController.m:27:0 /Users/nowpos/Desktop/TrackBP3511/CorePlotTestViewController.m:27: error: expected expression before ')' token

/Users/nowpos/Desktop/TrackBP3511/CorePlotTestViewController.m:29:0 /Users/nowpos/Desktop/TrackBP3511/CorePlotTestViewController.m:29: error: 'CPLineStyle' undeclared (first use in this function)

/Users/nowpos/Desktop/TrackBP3511/CorePlotTestViewController.m:29:0 /Users/nowpos/Desktop/TrackBP3511/CorePlotTestViewController.m:29: error: 'lineStyle' undeclared (first use in this function)

/Users/nowpos/Desktop/TrackBP3511/CorePlotTestViewController.m:30:0 /Users/nowpos/Desktop/TrackBP3511/CorePlotTestViewController.m:30: error: 'CPColor' undeclared (first use in this function)

/Users/nowpos/Desktop/TrackBP3511/CorePlotTestViewController.m:51:0 /Users/nowpos/Desktop/TrackBP3511/CorePlotTestViewController.m:51: error: 'CPScatterPlot' undeclared (first use in this function)

/Users/nowpos/Desktop/TrackBP3511/CorePlotTestViewController.m:51:0 /Users/nowpos/Desktop/TrackBP3511/CorePlotTestViewController.m:51: error: 'xSquaredPlot' undeclared (first use in this function)

/Users/nowpos/Desktop/TrackBP3511/CorePlotTestViewController.m:58:0 /Users/nowpos/Desktop/TrackBP3511/CorePlotTestViewController.m:58: error: 'CPPlotSymbol' undeclared (first use in this function)

/Users/nowpos/Desktop/TrackBP3511/CorePlotTestViewController.m:58:0 /Users/nowpos/Desktop/TrackBP3511/CorePlotTestViewController.m:58: error: 'greenCirclePlotSymbol' undeclared (first use in this function)

/Users/nowpos/Desktop/TrackBP3511/CorePlotTestViewController.m:59:0 /Users/nowpos/Desktop/TrackBP3511/CorePlotTestViewController.m:59: error: 'CPFill' undeclared (first use in this function)

/Users/nowpos/Desktop/TrackBP3511/CorePlotTestViewController.m:63:0 /Users/nowpos/Desktop/TrackBP3511/CorePlotTestViewController.m:63: error: 'xInversePlot' undeclared (first use in this function)

/Users/nowpos/Desktop/TrackBP3511/CorePlotTestViewController.m:75:0 /Users/nowpos/Desktop/TrackBP3511/CorePlotTestViewController.m:75: error: expected ')' before 'CPPlot'

/Users/nowpos/Desktop/TrackBP3511/CorePlotTestViewController.m:77:0 /Users/nowpos/Desktop/TrackBP3511/CorePlotTestViewController.m:77: error: 'CPScatterPlotFieldX' undeclared (first use in this function)

/Users/nowpos/Desktop/TrackBP3511/CorePlotTestViewController.m:81:0 /Users/nowpos/Desktop/TrackBP3511/CorePlotTestViewController.m:81: error: request for member 'identifier' in something not a structure or union

totally 30 errors

can any one guide me.Or send me the sample which u have integrated.

reply

ciwol
06/14/2011 - 04:17

I made it work with xcode 3, but I can't with xcode 4, could you make a tuto for xcode 4 please? or give some links

regards

reply

csprofess
06/15/2011 - 08:02

The changes that you have to make with the new package are below in addition:

* the header search paths need to be updated to include iphoneOnly or macOnly in the framework folder.

this is the viewDidLoad body

        // allocate the graph within the current view bounds
        graph = [[CPXYGraph alloc] initWithFrame: self.view.bounds];
       
        // Setting the graph as our hosting layer
        CPGraphHostingView *hostingView = (CPGraphHostingView *)self.view;
        hostingView.hostedGraph = graph;
       
        // padding for the graph on the screen
        graph.paddingLeft = 20.0;
        graph.paddingTop = 20.0;
        graph.paddingRight = 20.0;
        graph.paddingBottom = 20.0;
       
        // setup a plot space for the plot to live in
        CPXYPlotSpace *plotSpace = (CPXYPlotSpace *)graph.defaultPlotSpace;
        // sets the range of x values
        plotSpace.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(-6)
                                                                                                   length:CPDecimalFromFloat(12)];
        // sets the range of y values
        plotSpace.yRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(-5)
                                                                                                   length:CPDecimalFromFloat(30)];
       
        // plotting style is set to line plots
        CPMutableLineStyle *lineStyle = [CPMutableLineStyle lineStyle];
        lineStyle.lineColor = [CPColor blackColor];
        lineStyle.lineWidth = 2.0f;
       
        // X-axis parameters setting
        CPXYAxisSet *axisSet = (id)graph.axisSet;
        axisSet.xAxis.majorIntervalLength = CPDecimalFromString(@"5");
        axisSet.xAxis.minorTicksPerInterval = 4;
        axisSet.xAxis.majorTickLineStyle = lineStyle;
        axisSet.xAxis.minorTickLineStyle = lineStyle;
        axisSet.xAxis.axisLineStyle = lineStyle;
        axisSet.xAxis.minorTickLength = 5.0f;
        axisSet.xAxis.majorTickLength = 7.0f;
        axisSet.xAxis.labelOffset = 3.0f;
       
        // Y-axis parameters setting   
        axisSet.yAxis.majorIntervalLength = CPDecimalFromString(@"5");
        axisSet.yAxis.minorTicksPerInterval = 4;
        axisSet.yAxis.majorTickLineStyle = lineStyle;
        axisSet.yAxis.minorTickLineStyle = lineStyle;
        axisSet.yAxis.axisLineStyle = lineStyle;
        axisSet.yAxis.minorTickLength = 5.0f;
        axisSet.yAxis.majorTickLength = 7.0f;
        axisSet.yAxis.labelOffset = 3.0f;
       
       
        // This actually performs the plotting
        CPScatterPlot *xSquaredPlot = [[[CPScatterPlot alloc] init] autorelease];
//      CPScatterPlot *xSquaredPlot = [[[CPScatterPlot alloc]
//                                                                      initWithFrame:graph.defaultPlotSpace.plotAreaFrame] autorelease];
        CPMutableLineStyle *dataLineStyle = [CPMutableLineStyle lineStyle];
        xSquaredPlot.identifier = @"X Squared Plot";

        dataLineStyle.lineWidth = 1.0f;
        dataLineStyle.lineColor = [CPColor redColor];
        xSquaredPlot.dataLineStyle = dataLineStyle;
        xSquaredPlot.dataSource = self;
       
        CPPlotSymbol *greenCirclePlotSymbol = [CPPlotSymbol ellipsePlotSymbol];
        greenCirclePlotSymbol.fill = [CPFill fillWithColor:[CPColor greenColor]];
        greenCirclePlotSymbol.size = CGSizeMake(2.0, 2.0);
        xSquaredPlot.plotSymbol = greenCirclePlotSymbol;  
       
        // add plot to graph
        [graph addPlot:xSquaredPlot];
       

This is the change to the number of records method for the protocol. It has a different interface now.

// CorePlot protocol requiremnts satisfied here
-(NSUInteger)numberOfRecordsForPlot:(CPPlot *)plot {
        return 51;
}

reply

ning883
06/25/2011 - 20:36

Hi guys,

i'm an newbie on iphone. Trying to follow this,

"A core plot graph cannot be hosted in just any UIView - it has to be hosted in a CPLayerHostingView. To get this to happen we have to change the base type of our view. So pull open the xib file for the view for this view controller, and change the base type of the view to CPLayerHostingView in the Identity Inspector:"

But in my project i only have Mainwindow.xlib, after i followed all the steps.
I cannot find CPLayerHostingView in the list.

Base SDK is IOS Device 4.1
MAC OS 10.6.7

Any suggestions ?

reply

ravivatish
06/26/2011 - 00:20

Hi Guys,

I have downloaded this code and it is showing undeclared error for every library function.
What I found is following:

Most of Libery function is changed like:
CPPlot -> CPTPlot
CPXYGraph -> CPTXYGraph
CPGraphHostingView -> CPTGraphHostingView
etc..

I ll update the code once I finished with this example

reply

Anonymous
06/27/2011 - 17:33

Spent a lot of time with compile time error : "CorePlot-CocoaTouch.h" No such file or directory

- solved after renaming "Source Code" to "Source_Code" in the CorePlotInstall subfolder, and following the rest of the instructions in this site.

:( just wasted 4 hours of my life.

reply

rPedroso
07/11/2011 - 21:20

Just to report an issue I had with hostingView initialization. The app crashed and returned the following error:

2011-07-11 22:49:03.498 CorePlotTester[4222:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView setHostedGraph:]: unrecognized selector sent to instance 0x4e050e0'

My problem was solved with:

- (void)viewDidLoad {
  [super viewDidLoad];
 
  graph = [[CPTXYGraph alloc] initWithFrame: self.view.bounds];
       
  //CPTLayerHostingView *hostingView = (CPTLayerHostingView *)self.view;

  CPTGraphHostingView *hostingView = [[CPTGraphHostingView alloc] initWithFrame:self.view.bounds];

  [self.view addSubview:hostingView];

  hostingView.hostedLayer = graph;

Great post, by the way. Wouldn't have made without it.

Regards,

rPedroso

reply

rPedroso
07/11/2011 - 21:24

Sorry, I forgot to correct the last line:

hostingView.hostedGraph = graph;

reply

pkartheekmca
07/14/2011 - 02:53

what is mean by synchronous application in iphone ?

reply

Ramanamurty
07/20/2011 - 02:05

Can any one please help me out.

How to get each Bar CGMutablePathRef in Bar chart created by using Core Plot?

Thanks in advance

reply

Ramanamurty
07/25/2011 - 02:02

Got solution for my above question. By using below method we can get Each bar path,

-(CGMutablePathRef)newBarPathWithContext:(CGContextRef)context recordIndex:(NSUInteger)index

reply

JamerTheProgrammer
08/02/2011 - 14:54

I have followed every single step with complete accuracy.
QuartzCore seems to have allot missing...
136 errors all to do with importing missing classes.
Here are just some that im having problems with:
#import "CPTAnnotation.h"
#import "CPTAnnotationHostLayer.h"
#import "CPTAxis.h"
#import "CPTAxisLabel.h"
#import "CPTAxisLabelGroup.h"
#import "CPTAxisSet.h"
#import "CPTAxisTitle.h"
#import "CPTBarPlot.h"
#import "CPTBorderedLayer.h"
#import "CPTColor.h"
#import "CPTColorSpace.h"
#import "CPTConstrainedPosition.h"
#import "CPTDarkGradientTheme.h"
#import "CPTDefinitions.h"
#import "CPTExceptions.h"
#import "CPTFill.h"
#import "CPTGradient.h"
#import "CPTGraph.h"
#import "CPTGraphHostingView.h"
#import "CPTGridLines.h"
#import "CPTImage.h"
#import "CPTLayer.h"
#import "CPTLayerAnnotation.h"
#import "CPTLayoutManager.h"
#import "CPTLegend.h"
#import "CPTLegendEntry.h"
#import "CPTLimitBand.h"
#import "CPTLineCap.h"
#import "CPTLineStyle.h"
#import "CPTMutableLineStyle.h"
#import "CPTMutableNumericData.h"
#import "CPTMutableNumericData+TypeConversion.h"
#import "CPTMutableTextStyle.h"
#import "CPTNumericData.h"
#import "CPTNumericData+TypeConversion.h"
#import "CPTNumericDataType.h"
#import "CPTPieChart.h"
#import "CPTPlainBlackTheme.h"
#import "CPTPlainWhiteTheme.h"
#import "CPTPlatformSpecificDefines.h"
#import "CPTPlatformSpecificFunctions.h"
#import "CPTPlatformSpecificCategories.h"
#import "CPTPathExtensions.h"
#import "CPTPlot.h"
#import "CPTPlotArea.h"
#import "CPTPlotAreaFrame.h"
#import "CPTPlotGroup.h"
#import "CPTPlotRange.h"
#import "CPTPlotSpace.h"
#import "CPTPlotSpaceAnnotation.h"
#import "CPTPlotSymbol.h"
#import "CPTPolarPlotSpace.h"
#import "CPTRangePlot.h"
#import "CPTResponder.h"
#import "CPTScatterPlot.h"
#import "CPTSlateTheme.h"
#import "CPTSlateTheme.h"
#import "CPTStocksTheme.h"
#import "CPTTextLayer.h"
#import "CPTTextStyle.h"
#import "CPTTheme.h"
#import "CPTTimeFormatter.h"
#import "CPTTradingRangePlot.h"
#import "CPTUtilities.h"
#import "CPTXYAxis.h"
#import "CPTXYAxisSet.h"
#import "CPTXYGraph.h"
#import "CPTXYPlotSpace.h"
#import "CPTXYTheme.h"

reply

Nishi
08/03/2011 - 07:55

I m getting this is exit 1 status.Please let me know where should I have to resolve?

Build CorePlotApp of project CorePlotApp with configuration Debug

Ld build/Debug-iphonesimulator/CorePlotApp.app/CorePlotApp normal i386
cd /CorePlotApp
setenv MACOSX_DEPLOYMENT_TARGET 10.6
setenv PATH "/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2 -arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.1.sdk -L/CorePlotApp/build/Debug-iphonesimulator -F/CorePlotApp/build/Debug-iphonesimulator -filelist /CorePlotApp/build/CorePlotApp.build/Debug-iphonesimulator/CorePlotApp.build/Objects-normal/i386/CorePlotApp.LinkFileList -mmacosx-version-min=10.6 -ObjC -Xlinker -objc_abi_version -Xlinker 2 -framework Foundation -framework UIKit -framework CoreGraphics -framework QuartzCore -o /CorePlotApp/build/Debug-iphonesimulator/CorePlotApp.app/CorePlotApp

Undefined symbols:
"_OBJC_CLASS_$_CPTFill", referenced from:
objc-class-ref-to-CPTFill in CorePlotTesetViiewController.o
"_OBJC_CLASS_$_CPTPlotSymbol", referenced from:
objc-class-ref-to-CPTPlotSymbol in CorePlotTesetViiewController.o
"_OBJC_CLASS_$_CPTColor", referenced from:
objc-class-ref-to-CPTColor in CorePlotTesetViiewController.o
"_OBJC_CLASS_$_CPTLineStyle", referenced from:
objc-class-ref-to-CPTLineStyle in CorePlotTesetViiewController.o
"_OBJC_CLASS_$_CPTXYGraph", referenced from:
objc-class-ref-to-CPTXYGraph in CorePlotTesetViiewController.o
"_OBJC_CLASS_$_CPTScatterPlot", referenced from:
objc-class-ref-to-CPTScatterPlot in CorePlotTesetViiewController.o
"_CPTDecimalFromFloat", referenced from:
-[CorePlotTesetViiewController viewDidLoad] in CorePlotTesetViiewController.o
-[CorePlotTesetViiewController viewDidLoad] in CorePlotTesetViiewController.o
-[CorePlotTesetViiewController viewDidLoad] in CorePlotTesetViiewController.o
-[CorePlotTesetViiewController viewDidLoad] in CorePlotTesetViiewController.o
"_OBJC_CLASS_$_CPTPlotRange", referenced from:
objc-class-ref-to-CPTPlotRange in CorePlotTesetViiewController.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

reply

EynErgy
08/04/2011 - 03:57

I have simillar problem when trying to compile for Ipod Touch.
On the simulator it works, but it happens when target is device

reply

Laszlo
08/04/2011 - 18:15

Can you send me a copy of your working code? visualjazz@gmail.com

Thanks

reply

EynErgy
08/03/2011 - 15:11

And for me I got:

2011-08-03 22:08:41.633 CardsInventory MTG[9009:b603] -[NSDecimalNumber cgFloatValue]: unrecognized selector sent to instance 0x4e750c0
2011-08-03 22:08:41.635 CardsInventory MTG[9009:b603] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSDecimalNumber cgFloatValue]: unrecognized selector sent to instance 0x4e750c0'

on CPTXYPlotSpace at line
CGFloat viewCoordinate = viewLength * [[NSDecimalNumber decimalNumberWithDecimal:factor] cgFloatValue];

I suspect an error of my part on setting the UIView

reply

EynErgy
08/04/2011 - 03:57

Solved,

Forgot the -all_load flag

reply

nb
08/22/2011 - 07:56

Hi EynErgy,

I'm also getting same error. I'm not able to find out the problem as same code is working at some other place.
Pls, let me know the solution.

Thanks

reply

mondousage
08/04/2011 - 16:44

I've modified this code to run on xcode4, I have a view that I put into my ConsoleViewControllor.xib with its class as CPTGraphHostingView.

Compiles great, at runtime however, I get a SIGABRT at line
 hostingView.hostedGraph = graph; with the error

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView setHostedGraph:]: unrecognized selector sent to instance 0x5910d40'
*** Call stack at first throw:

Anyone else run into this issue? Thanks.

reply

JamerTheProgrammer
08/05/2011 - 04:21

IF ANY ONE HAS A PROBLEM WHERE 100 OR MORE CLASSES ARE MISSING (MIGHT NOT BE A FIX, BUT IT MIGHT BE):
Copy ALL the files from the Source folder to the framework folder.
Then it reduces to 6 errors.
Im working on getting those 6 files over to the framework folder.

Anything you do is your own responsibility.

reply

JamerTheProgrammer
08/05/2011 - 04:36

This will not solve anything.
Sorry.
Tried it as many times with as many things.
Sorry

reply

SSteve
08/09/2011 - 19:39

Take a look at this question on Stack Overflow. It should help:

http://stackoverflow.com/questions/6996863/getting-exc-bad-access-when-trying-to-compile-with-core-plot

Also, be sure to check the "Recursive" box when you add the header search path

reply

Paul
08/20/2011 - 10:49

Can someone who got this code running please make the source available. This tutorial is pretty much useless as it is currently.

reply

penfold
08/21/2011 - 17:22

Hope this helps anyone trying to follow this tutorial against the latest Core Plot trunk (as at 22/08/2011):
https://gist.github.com/1161262

reply

penfold
08/21/2011 - 17:23

Note: the data line style doesn't seem to work (lines are black not red/blue) and you need to add the -load_all linker flag as previous commenters have noted.

reply

Yasir
08/30/2011 - 17:10

I need to ask that the values do not take up the entire length of the y axis in core plot suppose i plot 5 minimum value and 15 maximum value the values do not take up entire length of the graph or probably exceeded from 15 max to 20 or 25 automatically so how would i use the entire length on y-axis on particular max and min values

reply

Anonymous
08/31/2011 - 18:16

To get this working for me, I followed the tutorial here:
http://recycled-parts.blogspot.com/2011/07/setting-up-coreplot-in-xcode-4.html?showComment=1314810959571#c1827020697114663107

Then I changed the ViewDidLoad code to look like this:

// Do any additional setup after loading the view from its nib.
    graph = [[CPTXYGraph alloc] initWithFrame: self.view.bounds];
   
    CPTGraphHostingView *hostingView = (CPTGraphHostingView *)self.view;
    hostingView.hostedGraph = graph;
    graph.paddingLeft = 20.0;
    graph.paddingTop = 20.0;
    graph.paddingRight = 20.0;
    graph.paddingBottom = 20.0;
   
    CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace;
    plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(-6)
                                                   length:CPTDecimalFromFloat(12)];
    plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(-5)
                                                   length:CPTDecimalFromFloat(30)];
   
    CPTXYAxisSet *axisSet = (CPTXYAxisSet *)graph.axisSet;
   
    CPTMutableLineStyle *lineStyle = [CPTMutableLineStyle lineStyle];
    lineStyle.lineColor = [CPTColor blackColor];
    lineStyle.lineWidth = 2.0f;

    axisSet.xAxis.majorIntervalLength = [[NSNumber numberWithInt:5] decimalValue];
    axisSet.xAxis.minorTicksPerInterval = 4;
    axisSet.xAxis.majorTickLineStyle = lineStyle;
    axisSet.xAxis.minorTickLineStyle = lineStyle;
    axisSet.xAxis.axisLineStyle = lineStyle;
    axisSet.xAxis.minorTickLength = 5.0f;
    axisSet.xAxis.majorTickLength = 7.0f;
    axisSet.xAxis.labelOffset = 3.0f;
   
    axisSet.yAxis.majorIntervalLength = [[NSNumber numberWithInt:5] decimalValue];
    axisSet.yAxis.minorTicksPerInterval = 4;
    axisSet.yAxis.majorTickLineStyle = lineStyle;
    axisSet.yAxis.minorTickLineStyle = lineStyle;
    axisSet.yAxis.axisLineStyle = lineStyle;
    axisSet.yAxis.minorTickLength = 5.0f;
    axisSet.yAxis.majorTickLength = 7.0f;
    axisSet.yAxis.labelOffset = 3.0f;
   
    CPTScatterPlot *xSquaredPlot = [[[CPTScatterPlot alloc] initWithFrame:graph.defaultPlotSpace.accessibilityFrame] autorelease];
    xSquaredPlot.identifier = @"X Squared Plot";
    CPTMutableLineStyle *ls1 = [CPTMutableLineStyle lineStyle];
    ls1.lineWidth = 1.0f;
    ls1.lineColor = [CPTColor redColor];
    xSquaredPlot.dataLineStyle = ls1;
    xSquaredPlot.dataSource = self;
    [graph addPlot:xSquaredPlot];
   
    CPTPlotSymbol *greenCirclePlotSymbol = [CPTPlotSymbol ellipsePlotSymbol];
    greenCirclePlotSymbol.fill = [CPTFill fillWithColor:[CPTColor greenColor]];
    greenCirclePlotSymbol.size = CGSizeMake(2.0, 2.0);
    xSquaredPlot.plotSymbol = greenCirclePlotSymbol;  
   
    CPTScatterPlot *xInversePlot = [[[CPTScatterPlot alloc] initWithFrame:graph.defaultPlotSpace.accessibilityFrame] autorelease];

    xInversePlot.identifier = @"X Inverse Plot";
    CPTMutableLineStyle *ls2 = [CPTMutableLineStyle lineStyle];
    ls2.lineWidth = 1.0f;
    ls2.lineColor = [CPTColor blueColor];
    xInversePlot.dataLineStyle = ls2;
    xInversePlot.dataSource = self;
    [graph addPlot:xInversePlot];

reply

combi83
10/13/2011 - 08:40

Thank you so much!!! It works!

reply

Anonymous
09/08/2011 - 06:35

The code which I downloaded from this tutorial is not working.It is giving 30 errors.One of it is "CorePlot-CocoaTouch.h"-No such file or directory.Can anyone help me please.

reply

Anonymous
12/17/2011 - 17:50

This code is working for me:

CorePlotTestViewController.h
-------------------------

//
//  CorePlotTestViewController.h
//  CorePlotTest
//

#import <UIKit/UIKit.h>
#import "CorePlot-CocoaTouch.h"

@interface CorePlotTestViewController : UIViewController <CPTPlotDataSource>
{
        CPTXYGraph *graph;
}

@end







CorePlotTestViewController.m
-------------------------

//
//  CorePlotTestViewController.m
//  CorePlotTest
//

#import "CorePlotTestViewController.h"


@implementation CorePlotTestViewController

- (void)viewDidLoad {
  [super viewDidLoad];
 
    // Do any additional setup after loading the view from its nib.
    graph = [[CPTXYGraph alloc] initWithFrame: self.view.bounds];
   
   // CPTGraphHostingView *hostingView = (CPTGraphHostingView *)self.view;
 
    CPTGraphHostingView *hostingView = [[CPTGraphHostingView alloc] initWithFrame:self.view.bounds];
   
    [self.view addSubview:hostingView];

   
    hostingView.hostedGraph = graph;
    graph.paddingLeft = 20.0;
    graph.paddingTop = 20.0;
    graph.paddingRight = 20.0;
    graph.paddingBottom = 20.0;
   
    CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace;
    plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(-6)
                                                    length:CPTDecimalFromFloat(12)];
    plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(-5)
                                                    length:CPTDecimalFromFloat(30)];
   
    CPTXYAxisSet *axisSet = (CPTXYAxisSet *)graph.axisSet;
   
    CPTMutableLineStyle *lineStyle = [CPTMutableLineStyle lineStyle];
    lineStyle.lineColor = [CPTColor blackColor];
    lineStyle.lineWidth = 2.0f;
   
    axisSet.xAxis.majorIntervalLength = [[NSNumber numberWithInt:5] decimalValue];
    axisSet.xAxis.minorTicksPerInterval = 4;
    axisSet.xAxis.majorTickLineStyle = lineStyle;
    axisSet.xAxis.minorTickLineStyle = lineStyle;
    axisSet.xAxis.axisLineStyle = lineStyle;
    axisSet.xAxis.minorTickLength = 5.0f;
    axisSet.xAxis.majorTickLength = 7.0f;
    axisSet.xAxis.labelOffset = 3.0f;
   
    axisSet.yAxis.majorIntervalLength = [[NSNumber numberWithInt:5] decimalValue];
    axisSet.yAxis.minorTicksPerInterval = 4;
    axisSet.yAxis.majorTickLineStyle = lineStyle;
    axisSet.yAxis.minorTickLineStyle = lineStyle;
    axisSet.yAxis.axisLineStyle = lineStyle;
    axisSet.yAxis.minorTickLength = 5.0f;
    axisSet.yAxis.majorTickLength = 7.0f;
    axisSet.yAxis.labelOffset = 3.0f;
   
    CPTScatterPlot *xSquaredPlot = [[[CPTScatterPlot alloc] initWithFrame:graph.defaultPlotSpace.accessibilityFrame] autorelease];
    xSquaredPlot.identifier = @"X Squared Plot";
    CPTMutableLineStyle *ls1 = [CPTMutableLineStyle lineStyle];
    ls1.lineWidth = 1.0f;
    ls1.lineColor = [CPTColor redColor];
    xSquaredPlot.dataLineStyle = ls1;
    xSquaredPlot.dataSource = self;
    [graph addPlot:xSquaredPlot];
   
    CPTPlotSymbol *greenCirclePlotSymbol = [CPTPlotSymbol ellipsePlotSymbol];
    greenCirclePlotSymbol.fill = [CPTFill fillWithColor:[CPTColor greenColor]];
    greenCirclePlotSymbol.size = CGSizeMake(2.0, 2.0);
    xSquaredPlot.plotSymbol = greenCirclePlotSymbol;  
   
    CPTScatterPlot *xInversePlot = [[[CPTScatterPlot alloc] initWithFrame:graph.defaultPlotSpace.accessibilityFrame] autorelease];
   
    xInversePlot.identifier = @"X Inverse Plot";
    CPTMutableLineStyle *ls2 = [CPTMutableLineStyle lineStyle];
    ls2.lineWidth = 1.0f;
    ls2.lineColor = [CPTColor blueColor];
    xInversePlot.dataLineStyle = ls2;
    xInversePlot.dataSource = self;
    [graph addPlot:xInversePlot];
}


-(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot {
    return 51;

}

-(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index {
  double val = (index/5.0)-5;
  if(fieldEnum == CPTScatterPlotFieldX)
  { return [NSNumber numberWithDouble:val]; }
  else
  {
    if(plot.identifier == @"X Squared Plot")
    { return [NSNumber numberWithDouble:val*val]; }
    else
    { return [NSNumber numberWithDouble:1/val]; }
  }
}

@end

reply

Anonymous
10/03/2011 - 03:40

Great Job!

We will start to develop a graph app using Core-Plot!Thanks for this tutorial.

reply

Manson
10/31/2011 - 05:11

i had problem with -[CPMutableNumericData setDataType:]:
i resolved it. The true way is to put -all_load -ObjC to others link flags.
Hope this help.

/* Mans

reply

Pravin
11/10/2011 - 00:12

Here is the configuration used:
Xcode 4.1 , Mac OS Lion 10.7, coreplot_0.9

My app is crashing with following error:
[NSDecimalNumber cgFloatValue]: unrecognized selector sent to instance...

I'm not able to find out the solution on this as same code is working on Xcode4.2 with Mac OS 10.6.7. Plz, let me know the solution.

reply

TheFinav
12/17/2011 - 04:37

I have exactly the same problem as Pravin... XCode 4.2, .Lion 10.7.2, code plot_0.9.

reply

Matt
12/27/2011 - 20:06

Great work guys...

I just installed CorePlot inside an XCode 4.2.1 app using the example from:

http://recycled-parts.blogspot.com/2011/07/setting-up-coreplot-in-xcode-4.html?showComment=1314810959571#c1827020697114663107

Then I found this tutorial. I got some errors then read some of the most recent posts, changed the viewDidLoad code to match Anonymous (12/17/11). I noticed the graph was upside down and reflected. I then copied Anonymous (8/31/11) viewDidLoad code and it built the graph as expected.

Thanks, and make sure to post your experience with this tutorial!

reply

theDuncs
01/12/2012 - 12:53

You're amazing. I spent all day on this, and your tutorial cleared loads of stuff up. No worries if its a bit out of date - good programmers can get through that stuff without a problem. THANK YOU.

reply

Add Comment

Put code snippets inside language tags:
[language] [/language]

Examples:
[javascript] [/javascript]
[actionscript] [/actionscript]
[csharp] [/csharp]

See here for supported languages.

Javascript must be enabled to submit anonymous comments - or you can login.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.