Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7923843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T17:26:59+00:00 2026-06-03T17:26:59+00:00

Am a newbie to iOS programming and to Core Plot. Am using XCode 4.2

  • 0

Am a newbie to iOS programming and to Core Plot. Am using XCode 4.2 and iOS 5, and testing the iPhone App using iOS Simulator.

I know am overlooking something here (breaking my head on this for more than a day & tried google’ing a lot & tried out various possible solutions, all in vain). Can someone please help or any pointers?

Am trying to do something very simple -> adding a pie chart (done using Core Plot) as a subview. Initially, I was displaying the pie chart as a modal view & it worked fine. Now, in the same view I want to add few buttons and so I created a view (which will get displayed on pressing a button) in which I added the 2 buttons and also tried to add this pie chart too. The buttons display fine but the pie chart is not to be seen!

This is the XIB file of the view called ‘GraphView’ which gets displayed when a button’s pressed:

XIB screenshot showing the UI Components

In the above screenshot, the highlighted view ‘View’ is a UIView object within which I want to display the piechart. The entire view ‘GraphView’ gets displayed fine; the two buttons appear, but the piechart that I added to the subview doesn’t. The UIView object that I added as subview in the above figure also gets displayed fine (I checked it by setting a background color for it). This is the code:

GRAPHVIEW.H

#import <UIKit/UIKit.h>
#import "PieChartView.h"

@interface GraphView : UIViewController

    @property (strong, nonatomic) PieChartView *pieChartView;
    // gView is the view which is linked to the 'UIView' subview in IB
    // in the above figure
    @property (strong, nonatomic) IBOutlet UIView *gView;
    @property (strong, nonatomic) IBOutlet UIButton *buttonBack;
    @property (strong, nonatomic) IBOutlet UIButton *buttonMail;

    -(void) setHistoryData:(NSArray *)history;
    ...
    ...
@end

GRAPHVIEW.M

...
...
@synthesize gView;
@synthesize buttonBack;
@synthesize buttonMail;
...
...
-(void) setHistoryData:(NSArray *)history {
    NSLog(@"GraphView: setHistoryData");
    [pieChartView setHistoryData:history];
    [gView addSubview:pieChartView];
}


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
  self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  if (self) {
      // Custom initialization
  }
  pieChartView = [[PieChartView alloc] init];
  return self;
}
...
...

#pragma mark – View lifecycle

- (void)viewDidLoad
{
  NSLog(@"GraphView: viewDidLoad");
  [super viewDidLoad];

  [pieChartView initializeGraph];
}

- (void)viewDidUnload
{
  [super viewDidUnload];
  // Release any retained subviews of the main view.
  // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
  // Return YES for supported orientations
  return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end

PIECHARTVIEW.H
This is the one that draws (that which is ‘supposed to’ draw) the pie chart!

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

// I tied subclassing 'UIViewController' or just 'UIView'...all in vain
@interface PieChartView : CPTGraphHostingView <CPTPlotDataSource> {
   CPTXYGraph *graph;
   CPTPieChart *pieChart;
}

@property (nonatomic, retain) CPTXYGraph *graph;

-(void) initializeGraph;
-(void) initializePieChart;
-(void) setHistoryData:(NSArray *)history;

@end

PIECHARTVIEW.m

...
@implementation PieChartView

@synthesize graph;

NSArray *historyData;


// I added the NSLog to see if these get called, but they don't seem to get called!
// So, this means that the pie chart is not being drawn actually!
-(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot {
     NSLog(@"numberOfRecordsForPlot: History count: %d", (int)[historyData count]);
     return [historyData count];
}


 // This too isn't getting called
-(NSNumber *) numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index {   
    NSLog(@"historyView: numberForPlot");
    return [historyData objectAtIndex:index];
}


// This too is not getting called! OMG!
-(CPTLayer *)dataLabelForPlot:(CPTPlot *)plot recordIndex:(NSUInteger)index {
   NSLog(@"HistoryView: dataLabelForPlot");
   ...
}


// This method is getting called. Am seeing the log messages
-(void) initializeGraph {

   NSLog(@"HistoryView: initializeGraph");

   graph = [[CPTXYGraph alloc] init];

   CPTTheme *theme = [CPTTheme themeNamed:kCPTDarkGradientTheme];
   [graph applyTheme:theme];

  CPTGraphHostingView *hostingView = (CPTGraphHostingView *) self;
  hostingView.hostedGraph = graph;  
  //hostingView.bounds = CGRectMake(5, 5, 70, 70);
  [self initializePieChart];  
}


// This method is also getting called. I see the log messages from this method too
/** 
 * Initialize the pie chart for display
 */
-(void) initializePieChart {

  NSLog(@"HistoryView: initializePieChart");
  pieChart = [[CPTPieChart alloc] init];
  pieChart.dataSource = self;
  pieChart.pieRadius = 100.0;
  pieChart.opaque = FALSE;
  //pieChart.pieRadius = 60;
  pieChart.shadowOffset = CGSizeMake(-1, 1);
  pieChart.identifier = @"PieChart";
  pieChart.startAngle = M_PI_4;
  pieChart.sliceDirection = CPTPieDirectionCounterClockwise;
  pieChart.labelOffset = -0.6;
  [graph addPlot:pieChart];
  NSLog(@"added pie chart to the graph view");
}


// This also is getting called
-(void) setHistoryData:(NSArray *)history {
    NSLog(@"HistoryView: setHistoryData");
    historyData = history;
}

...
...
@end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T17:27:00+00:00Added an answer on June 3, 2026 at 5:27 pm

    You don’t need the gView property. Remove it and change the pieChartView declaration to:

    @property (strong, nonatomic) IBOutlet PieChartView *pieChartView;
    

    Link the custom view to this property instead of gView and change the class in IB to PieChartView. Also remove the initialization of this property from -initWithNibName:bundle:—the view will be initialized automatically when the nib is loaded.

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

Sidebar

Related Questions

Newbie here programming my first app (having made several tutorial apps). I am using
I'm a newbie to Xcode, Objective-C and iOS programming (fully comfortable in R however,
I am a complete newbie to iOS development but not to programming. I am
Newbie here (to C, objective-C, and iOS)... For this code in my AppDelegate.m, why
I'm a newbie to iOS programming, I have a project and my requirements are
I'm newbie on iOS development and I'm currently testing RestKit 0.9.3 for iOS with
I am an iOS newbie. I am using a checkmark to in a UITableView,
I'm a newbie programming iOS and I've a problem adding a new cell to
I am newbie to iphone programming and trying to learn iphone programming.I need experts
I am both new here and in IOS programming, so please bear with my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.