Search code examples
iphonecore-plotlinegraphbar-chart

How to draw lineGraph using CorePlot framework in iPhone?


I have downloaded Core-Plot Header 9.0and added in my new Project. I am very new to draw graphs and using Core-Plot framework. I have downloaded sample project CPTTestApp-iPhone from core-plot sample projects. I opened this project it is contains CorePlot-Cocoa Touch.xcodeproj If i tried to run this project from XCode4.2 automatically XCode3.2.4 App opens. I just copied the source code from CPTTestAppScatterPlotController.h and pasted in my new project. The CPTTestAppScatterPlotController.h having a nib file, but i dont ve any nib files for this and also i want to do it programmatically. So, i just changed these lines from CPTTestAppScatterPlotController.h in my project as likes below code,

graph = [[CPTXYGraph alloc] initWithFrame:CGRectZero];
    CPTTheme *theme = [CPTTheme themeNamed:kCPTDarkGradientTheme];
    [graph applyTheme:theme];

    CPTGraphHostingView *hostingView = [[CPTGraphHostingView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
    hostingView.hostedGraph = graph;
    hostingView.collapsesLayers = NO;
    //hostingView.collapsesLayers = YES; // Setting to YES reduces GPU memory usage, but can slow drawing/scrolling
    [self.view addSubview:hostingView];

But, the all functionalities i didn't change from CPTTestAppScatterPlotController.h. Still the project not running and it shows Build Succeeded. My doubt is i need to import CorePlot-Cocoa Touch.xcodeproj in my new project? and how can i run my project? Please help me to run my project. I searched a lot in google and all are suggested this project for beginners CPTTestApp-iPhone. Am also trying this project only. Thanks in advance. Waiting for your great solutions. This is the error occur when i'm running the project *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSDecimalNumber cgFloatValue]: unrecognized selector sent to instance.


Solution

  • Thanks to all. I have solved this problem. I just forgot to add -ObjC -all_load in mu project Target Build settings. Pelase follow below steps to avoid my problem,

    1. Copy the CorePlotHeaders to your Xcode project
    
    2. Copy libCorePlotCocoaTouch.a to your Xcode project
    
    3. Add to Other Linker Flags in your target build settings:
    
    -ObjC -all_load
    

    Thanks.