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

  • Home
  • SEARCH
  • 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 8936753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:16:57+00:00 2026-06-15T10:16:57+00:00

The bars on my barplots aren’t spread out across the whole graph, rather they

  • 0

The bars on my barplots aren’t spread out across the whole graph, rather they are confined to the first index!
enter image description here

- (UIView*)pagingScrollView:(BAGPagingScrollView*)pagingScrollView
       viewForPageIndex:(int)index;

{
NSLog(@"THE INDEX COMING THROUGH INTO THE PAGING SCROLL VIEW = %i",index);
      _index = index;

_graphBase = [[CPTGraphHostingView alloc]initWithFrame:_pagingView.frame];
[self updateGraph:_graphBase forIndex:_index];

}

-(void) updateGraph:(CPTGraphHostingView*)graph forIndex:(int) index
{
....
else if (index == 5){

    graph.allowPinchScaling = NO;
    _averageOfPar = [[NSArray alloc]initWithArray:[self getParForPlayerName]];
    _averageDataValuesMultiple = [[NSArray alloc]initWithArray:[self arrayOfAverageDataValuesFromTheUserMultiple]];
    NSLog(@"average data values %@", _averageDataValuesMultiple);
    NSLog(@"average of par = %@",_averageOfPar);
    [self barChartconfigureGraph:graph];
    [self barChartconfigurePlots:graph];
    [self barChartconfigureAxes:graph]; 

}

….
}

 -(void)barChartconfigureGraph:(CPTGraphHostingView*)hostView {

CPTGraph *graph = [[CPTXYGraph alloc] initWithFrame:hostView.bounds];
graph.plotAreaFrame.masksToBorder = NO;
hostView.hostedGraph = graph;

// 2 - Configure the graph

[graph applyTheme:[CPTTheme themeNamed:kCPTDarkGradientTheme]];
graph.plotAreaFrame.fill = [CPTFill fillWithColor:[CPTColor clearColor]];
graph.paddingBottom = 30.0f;
graph.paddingLeft  = 30.0f;
graph.paddingTop    = 0.0f;
graph.paddingRight  = 0.0f;

// 3 - Set up styles

CPTMutableTextStyle *titleStyle = [CPTMutableTextStyle textStyle];
titleStyle.color = [CPTColor whiteColor];
titleStyle.fontName = @"Helvetica-Bold";
titleStyle.fontSize = 16.0f;

// 4 - Set up title

NSString *title = @"Average Shot Compared To Par";
graph.title = title;
graph.titleTextStyle = titleStyle;
graph.titlePlotAreaFrameAnchor = CPTRectAnchorTop;
graph.titleDisplacement = CGPointMake(0.0f, -16.0f);
// 5 - Set up plot space
CGFloat xMin = 0.0f;
CGFloat xMax = (([_averageOfPar count])+0.2);
CGFloat yMin = 0.0f;
CGFloat yMax = ([self largestShotMade]);

CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *) graph.defaultPlotSpace;
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(xMin) length:CPTDecimalFromFloat(xMax)];
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(yMin) length:CPTDecimalFromFloat(yMax)];


  }

-(void)barChartconfigurePlots:(CPTGraphHostingView*)hostView{

// 1 - Set up the three plots

_personsShotPlot = [CPTBarPlot tubularBarPlotWithColor:[CPTColor blueColor] horizontalBars:NO];
_personsShotPlot.identifier = _nameComingThrough;
_parPlot = [CPTBarPlot tubularBarPlotWithColor:[CPTColor whiteColor] horizontalBars:NO];
_parPlot.identifier = PAR;

// 2 - Set up line style

CPTMutableLineStyle *barLineStyle = [[CPTMutableLineStyle alloc] init];
barLineStyle.lineColor = [CPTColor lightGrayColor];
barLineStyle.lineWidth = 0.5;

// 3 - Add plots to graph

CPTGraph *graph = hostView.hostedGraph;
CGFloat barX = CPDBarInitialXSecondForSplotMultiple;
NSArray *plots = [NSArray arrayWithObjects: self.parPlot,self.personsShotPlot, nil];

//NSLog(@"about to enter the plot for loop");

for (CPTBarPlot *plot in plots) {
    plot.dataSource = self;
   plot.delegate = self;
    plot.barWidth = CPTDecimalFromDouble(CPDBarInitialXSecondForSplotMultiple/* + [self widthNumToAdd]*/);
    plot.barOffset = CPTDecimalFromDouble(barX);
    plot.lineStyle = barLineStyle;
    [graph addPlot:plot toPlotSpace:graph.defaultPlotSpace];
    barX += CPDBarInitialXSecondForSplotMultiple/*+ [self widthNumToAdd]*/;
}
//[graph reloadDataIfNeeded];

}
-(void)barChartconfigurePlots:(CPTGraphHostingView*)hostView{

// 1 - Set up the three plots

_personsShotPlot = [CPTBarPlot tubularBarPlotWithColor:[CPTColor blueColor] horizontalBars:NO];
_personsShotPlot.identifier = _nameComingThrough;
_parPlot = [CPTBarPlot tubularBarPlotWithColor:[CPTColor whiteColor] horizontalBars:NO];
_parPlot.identifier = PAR;

// 2 - Set up line style

CPTMutableLineStyle *barLineStyle = [[CPTMutableLineStyle alloc] init];
barLineStyle.lineColor = [CPTColor lightGrayColor];
barLineStyle.lineWidth = 0.5;

// 3 - Add plots to graph

CPTGraph *graph = hostView.hostedGraph;
CGFloat barX = CPDBarInitialXSecondForSplotMultiple;
NSArray *plots = [NSArray arrayWithObjects: self.parPlot,self.personsShotPlot, nil];

//NSLog(@"about to enter the plot for loop");

for (CPTBarPlot *plot in plots) {
    plot.dataSource = self;
   plot.delegate = self;
    plot.barWidth = CPTDecimalFromDouble(CPDBarInitialXSecondForSplotMultiple/* + [self widthNumToAdd]*/);
    plot.barOffset = CPTDecimalFromDouble(barX);
    plot.lineStyle = barLineStyle;
    [graph addPlot:plot toPlotSpace:graph.defaultPlotSpace];
    barX += CPDBarInitialXSecondForSplotMultiple/*+ [self widthNumToAdd]*/;
}
//[graph reloadDataIfNeeded];

}

-(void)barChartconfigureAxes:(CPTGraphHostingView*)hostView {

// 1 - Configure styles

CPTMutableTextStyle *axisTitleStyle = [CPTMutableTextStyle textStyle];
axisTitleStyle.color = [CPTColor whiteColor];
axisTitleStyle.fontName = @"Helvetica-Bold";
axisTitleStyle.fontSize = 12.0f;
CPTMutableLineStyle *axisLineStyle = [CPTMutableLineStyle lineStyle];
axisLineStyle.lineWidth = 2.0f;
axisLineStyle.lineColor = [[CPTColor whiteColor] colorWithAlphaComponent:1];

// 2 - Get the graph's axis set

CPTXYAxisSet *axisSet = (CPTXYAxisSet *) hostView.hostedGraph.axisSet;

// 3 - Configure the x-axis

axisSet.xAxis.labelingPolicy = CPTAxisLabelingPolicyNone;
axisSet.xAxis.title = @"Hole Number";
axisSet.xAxis.titleTextStyle = axisTitleStyle;
axisSet.xAxis.titleOffset = 15.0f;
axisSet.xAxis.axisLineStyle = axisLineStyle;

CPTAxis *x = axisSet.xAxis;

NSMutableSet *xLabels = [NSMutableSet setWithCapacity:[_averageDataValues count]];
NSMutableSet *xLocations = [NSMutableSet setWithCapacity:[_averageDataValues count]];
NSInteger i = 0;

for (NSString *holeName in [self holeNames]) {


    CPTAxisLabel *label = [[CPTAxisLabel alloc] initWithText:holeName  textStyle:x.labelTextStyle];
    CGFloat location = i++;
    label.tickLocation = CPTDecimalFromCGFloat(location + .4);
    label.offset =-1;
    if (label) {
        [xLabels addObject:label];

        [xLocations addObject:[NSNumber numberWithFloat:location + .4]];
    }
}

x.axisLabels = xLabels;
x.majorTickLocations = xLocations;



// 4 - Configure the y-axis
axisSet.yAxis.labelingPolicy = CPTAxisLabelingPolicyNone;
axisSet.yAxis.title = @"Number Of Shots";
axisSet.yAxis.titleTextStyle = axisTitleStyle;
axisSet.yAxis.titleOffset = 5.0f;
axisSet.yAxis.axisLineStyle = axisLineStyle;

[hostView.hostedGraph reloadDataIfNeeded];

}

 -(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot {
  else if (_index == 5) return 18;//[_averageDataValuesMultiple count];

}



  -(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index {

else if (_index == 5) {

    if (fieldEnum == CPTBarPlotFieldBarTip) {
    if ([plot.identifier isEqual:_nameComingThrough]) {

    return [_averageDataValuesMultiple objectAtIndex:index];
        //return [NSNumber numberWithInt:5];

    } else if ([plot.identifier isEqual:PAR]) {

        return [_averageOfPar objectAtIndex:index];
        //return [NSNumber numberWithInt:2];

    }
}
}

I originally didn’t want to post the code because it is a bit complicated, I was hoping that it was a bug that had been seen before!

  • 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-15T10:16:59+00:00Added an answer on June 15, 2026 at 10:16 am

    Make sure your datasource provides values for the CPTBarPlotFieldBarLocation field in addition to CPTBarPlotFieldBarTip. It looks like you’re returning the same location value for every bar index which puts the bars on top of each other.

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

Sidebar

Related Questions

I have 6 graph bars with the prices. Each price number will represent its
I'm trying to take the scroll bars out of an <object> tag in HTML.
I want to annotate the bars in a graph with some text but if
I am modifying the width of bars in a graph by using (CPBarPlot *)barPlot.barWidth
I have 3 yellow bars. The bar should come from out of my boundary
I am working with action bars for the first time and would like to
I am trying to create a simple bar graph including two bars showing the
I have multiple 'bars' which I wish to resize and drag along a x-axis.
SO Post Current I've got 5 bars in my RS chart - in the
I want to use many bars like this one in my app (i don't

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.