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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:42:56+00:00 2026-06-08T08:42:56+00:00

I have 4 files, BarPlot.h and BarPlot.m, BarPlotViewController.h and BarPlotViewController.m and my(probably very straight

  • 0

I have 4 files, BarPlot.h and BarPlot.m, BarPlotViewController.h and BarPlotViewController.m
and my(probably very straight forward to you guys)is I cant get the BarplotViewController to display my graph.

I’ve made sure that the correct view controller is being called in the storyboard.

I’ve gone over the code multiple times but I just cant figure out why the view is not showing up when I run the app in simulator..

I have included the files below.

Any and all help is greatly appreciated.

BarPlotViewController.h

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

@interface BarPlotViewController : UIViewController {
    CPTGraphHostingView *_graphHostingView;
}

@property (nonatomic, retain) BarPlot *barPlot;

@end

BarPlotViewController.m

#import "BarPlotViewController.h"

@implementation BarPlotViewController
@synthesize barPlot = _barPlot;


- (void)viewWillAppear:(BOOL)animated
{   
    self.barPlot = [[BarPlot alloc] initWithHostingView:_graphHostingView];
    [self.barPlot generateBarPlot];
}

@end

BarPlot.h

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

@interface BarPlot : UIViewController <CPTBarPlotDataSource, CPTBarPlotDelegate> {
    CPTGraphHostingView *_hostingView;  
CPTXYGraph *_graph;
}

@property (nonatomic, retain) NSMutableArray *data;
@property (nonatomic, retain) CPTGraphHostingView *hostingView;
@property (nonatomic, retain) CPTXYGraph *graph;


// Methods to create this object and attach it to it's hosting view.
-(id)initWithHostingView:(CPTGraphHostingView *)hostingView;


// Generate the bar plot
- (void) generateBarPlot;

@end

BarPlot.m

#import "BarPlot.h"

@implementation BarPlot

#define BAR_POSITION @"POSITION"
#define BAR_HEIGHT @"HEIGHT"
#define COLOR @"COLOR"
#define CATEGORY @"CATEGORY"

#define AXIS_START 0
#define AXIS_END 50

@synthesize data;
@synthesize hostingView = _hostingView;
@synthesize graph = _graph;


// Initialise the bar plot in the provided hosting
-(id)initWithHostingView:(CPTGraphHostingView *)hostingView
{
    self = [super init];

if ( self != nil ) {
    self.hostingView = hostingView;
    self.graph = nil;
}


NSLog(@"Bar Plot: I'm in the initWithHostingView (in the barplot.m file)");

return self;
}


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {

    self.data = [NSMutableArray array];

    int bar_heights[] = {20,30};


    UIColor *colors[] = {
        [UIColor redColor],
        [UIColor blueColor],
        [UIColor orangeColor],
        [UIColor purpleColor]};


    NSString *categories[] = {@"", @""};



    for (int i = 0; i < 2 ; i++){
        double position = i*20; //Bars will be 10 pts away from each other
        double height = bar_heights[i];

        NSDictionary *bar = [NSDictionary dictionaryWithObjectsAndKeys:
                             [NSNumber numberWithDouble:position],BAR_POSITION,
                             [NSNumber numberWithDouble:height],BAR_HEIGHT,
                             colors[i],COLOR,
                             categories[i],CATEGORY,
                             nil];
        [self.data addObject:bar];

    }
    [self generateBarPlot];
}
return self;
}


- (void)generateBarPlot
{
//Create host view
/*self.hostingView = [[CPTGraphHostingView alloc] 
                    initWithFrame:[[UIScreen mainScreen]bounds]];
[self.view addSubview:self.hostingView];



//Create graph and set it as host view's graph
self.graph = [[CPTXYGraph alloc] initWithFrame:self.hostingView.bounds];
[self.hostingView setHostedGraph:self.graph];*/



// Create a graph object which we will use to host just one scatter plot.
CGRect frame = [self.hostingView bounds];
self.graph = [[CPTXYGraph alloc] initWithFrame:frame];

// Tie the graph we've created with the hosting view.
self.hostingView.hostedGraph = self.graph;



//set graph padding and theme
self.graph.plotAreaFrame.paddingTop = 20.0f;
self.graph.plotAreaFrame.paddingRight = 20.0f;
self.graph.plotAreaFrame.paddingBottom = 70.0f;
self.graph.plotAreaFrame.paddingLeft = 70.0f;
[self.graph applyTheme:[CPTTheme themeNamed:kCPTDarkGradientTheme]];



// Gets rid of decimal on years
NSNumberFormatter *labelFormatter = [[NSNumberFormatter alloc] init];
labelFormatter.maximumFractionDigits = 0;



//set axes ranges
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)self.graph.defaultPlotSpace;
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:
                    CPTDecimalFromFloat(AXIS_START)
                                                length:CPTDecimalFromFloat((AXIS_END - AXIS_START))];
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:
                    CPTDecimalFromFloat(AXIS_START)
                                                length:CPTDecimalFromFloat((AXIS_END - AXIS_START))];




CPTXYAxisSet *axisSet = (CPTXYAxisSet *)self.graph.axisSet;
//set axes' title, labels and their text styles
CPTMutableTextStyle *textStyle = [CPTMutableTextStyle textStyle];
textStyle.fontName = @"Helvetica";
textStyle.fontSize = 14;
textStyle.color = [CPTColor whiteColor];



axisSet.xAxis.title = @"A";
axisSet.yAxis.title = @"B";
axisSet.xAxis.titleTextStyle = textStyle;
axisSet.yAxis.titleTextStyle = textStyle;
axisSet.xAxis.titleOffset = 30.0f;
axisSet.yAxis.titleOffset = 40.0f;
axisSet.xAxis.labelTextStyle = textStyle;
axisSet.yAxis.labelTextStyle = textStyle;
axisSet.xAxis.labelOffset = 3.0f;
axisSet.yAxis.labelOffset = 3.0f;



//set axes' line styles and interval ticks
CPTMutableLineStyle *lineStyle = [CPTMutableLineStyle lineStyle];
lineStyle.lineColor = [CPTColor whiteColor];
lineStyle.lineWidth = 3.0f;
axisSet.xAxis.axisLineStyle = lineStyle;
axisSet.yAxis.axisLineStyle = lineStyle;
axisSet.xAxis.majorTickLineStyle = lineStyle;
axisSet.yAxis.majorTickLineStyle = lineStyle;
axisSet.xAxis.majorIntervalLength = CPTDecimalFromFloat(5.0f);
axisSet.yAxis.majorIntervalLength = CPTDecimalFromFloat(5.0f);
axisSet.xAxis.majorTickLength = 10.0f;
axisSet.yAxis.majorTickLength = 10.0f;
axisSet.xAxis.minorTickLineStyle = lineStyle;
axisSet.yAxis.minorTickLineStyle = lineStyle;
axisSet.xAxis.minorTicksPerInterval = 1;
axisSet.yAxis.minorTicksPerInterval = 1;
axisSet.xAxis.minorTickLength = .0f;
axisSet.yAxis.minorTickLength = .0f;
axisSet.xAxis.labelFormatter = labelFormatter;
axisSet.yAxis.labelFormatter = labelFormatter;



// Create bar plot and add it to the graph
CPTBarPlot *plot = [[CPTBarPlot alloc] init] ;
plot.delegate = self;
plot.dataSource = self;
plot.barWidth = [[NSDecimalNumber decimalNumberWithString:@"5.0"]
                 decimalValue];
plot.barOffset = [[NSDecimalNumber decimalNumberWithString:@"10.0"]
                  decimalValue];
plot.barCornerRadius = 5.0;



// Remove bar outlines
CPTMutableLineStyle *borderLineStyle = [CPTMutableLineStyle lineStyle];
borderLineStyle.lineColor = [CPTColor clearColor];
plot.lineStyle = borderLineStyle;



// Identifiers are handy if you want multiple plots in one graph
plot.identifier = @"chocoplot";
[self.graph addPlot:plot];
}



-(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot
{
if ( [plot.identifier isEqual:@"chocoplot"] ) 
{
    return [self.data count];
}

return 0;
}



-(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index
{
if ( [plot.identifier isEqual:@"chocoplot"] )
{

    NSDictionary *bar = [self.data objectAtIndex:index];


    if( fieldEnum == 2 ) {
        return [bar valueForKey:BAR_POSITION];
        //return [NSNumber numberWithDouble:20];
    }
    else if( fieldEnum == 3 ) {
        return [bar valueForKey:BAR_HEIGHT];
        //return [NSNumber numberWithDouble:20];
    }

}
NSLog(@"numberForPlot return before");
return [NSNumber numberWithDouble:15];
}

@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-08T08:42:58+00:00Added an answer on June 8, 2026 at 8:42 am

    Well, the first thing I notice is that you never call addSubview. That’s the code that actually “adds the view”, so I’d start there. Also, see this question, the second answer looks like it might help: Adding CPTGraphHostingView as a subview

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

Sidebar

Related Questions

I have files with texts an constants. How can I get constant name and
Suppose I have files a.cpp and b.cpp and I get warnings in a.cpp and
Suppose you have files like: NewFile.part01.zip NewFile.part02.zip NewFile.part04.zip NewFile.part06.zip NewFile.part07.zip How do you get
I have files served like so: AJAX request handler -> Include file I would
I have files which have many empty cells which appear as NaNs when I
I have files on the server. Originally their names are readable and users put
I have files a1 a2 a3 b1 b2 b3 and I need to exclude
In my Visual Studio 2010 project I have files with .mm file extension, that
Let's assume that I have files a.cpp b.cpp and file c.h. Both of the
Let's say I have Directory 1 and Directory 2, and each can have files

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.