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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:51:23+00:00 2026-05-30T19:51:23+00:00

Problem I am drawing a bar chart with Core Plot . My implementation of

  • 0

Problem

I am drawing a bar chart with Core Plot. My implementation of the numberForPlot as the data source seems to return the values correctly. However, depending on the setting of barPlot.Offset the chart starts with the wrong value.

Datasource implementation

I have implemented the datasource as follows:

- (NSArray *)numbersForPlot:(CPTPlot *)plot 
                 field:(NSUInteger)fieldEnum 
      recordIndexRange:(NSRange)indexRange; 

if(fieldEnum == 3) {

NSString *coa = [[NSString alloc] init];
coa = (NSString*)[plot identifier];

NSMutableArray *values = [[NSMutableArray alloc] init] ;
for (IBFinPeriod *fp in periodsArray) {
    NSNumber *value = [self.company valueForCoa:coa FiscalYear:[fp FiscalYear] FiscalPeriod:[fp FiscalPeriod]];
    [values addObject:value];
    }
NSLog(@"plot values: %@",values);
return values;

}
else

    return    [[NSArray alloc]initWithObjects:[NSDecimalNumber numberWithFloat:1.0],
               [NSDecimalNumber numberWithFloat:2.0],
               [NSDecimalNumber numberWithFloat:3.0],
               [NSDecimalNumber numberWithFloat:4.0],
               [NSDecimalNumber numberWithFloat:5.0],
               nil]; 
}

This code returns the y-values: “1841.059”,
“2492.619”,
“3011.582”,
“2643.865”,
“2914.845”,
“3470.457”, which is correct.

Barplot offset

However, only when barPlot.barOffset = CPTDecimalFromFloat(-0.50f);
the plot starts correctly with the first value on the left.

chart with barPlot.offset = -0.50f

If barPlot.barOffset
is set to 0, it starts with the left half of the last value (3470.57):

chart with barPlot.offset = 0.00f

Chart set-up

This is the code to set-up the chart:

- (void) setChart;

{
graph1 = [[CPTXYGraph alloc] initWithFrame: self.view.bounds];

CPTTheme *theme = [CPTTheme themeNamed:kCPTPlainWhiteTheme];
[graph1 applyTheme:theme];
self.chartLeft.hostedGraph = graph1;
graph1.plotAreaFrame.masksToBorder = NO;


// Border
graph1.plotAreaFrame.borderLineStyle = nil;
graph1.plotAreaFrame.cornerRadius = 5.0f;

// Paddings
graph1.paddingLeft  = 10.0;
graph1.paddingTop   = 10.0;
graph1.paddingRight = 10.0;
graph1.paddingBottom = 10.0;

graph1.plotAreaFrame.paddingLeft = 50.0;
graph1.plotAreaFrame.paddingTop = 20.0;
graph1.plotAreaFrame.paddingRight = 20.0;
graph1.plotAreaFrame.paddingBottom = 50.0;
graph1.plotAreaFrame.backgroundColor = nil;

graph1.paddingLeft = 20.0;
graph1.paddingTop = 20.0;
graph1.paddingRight = 20.0;
graph1.paddingBottom = 20.0;

// Setup plot space
// The plot space determines the data ranges that are visible in the graph, not its physical size in the view
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph1.defaultPlotSpace;
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0f) length:CPTDecimalFromFloat(4000.0f)];
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0f) length:CPTDecimalFromFloat(5.0f)];

CPTXYAxisSet *axisSet = (CPTXYAxisSet *)graph1.axisSet;
CPTXYAxis *x          = axisSet.xAxis;
x.axisLineStyle               = nil;
x.majorTickLineStyle          = nil;
x.minorTickLineStyle          = nil;
x.majorIntervalLength         = CPTDecimalFromString(@"1");
x.orthogonalCoordinateDecimal = CPTDecimalFromString(@"0");
x.title                       = @"X Axis";
x.titleLocation               = CPTDecimalFromFloat(7.5f);
x.titleOffset                 = 55.0f;

// Custom labels omitted...

CPTXYAxis *y = axisSet.yAxis;
y.axisLineStyle               = nil;
y.majorTickLineStyle          = nil;
y.minorTickLineStyle          = nil;
y.majorIntervalLength         = CPTDecimalFromString(@"1000");
y.orthogonalCoordinateDecimal = CPTDecimalFromString(@"0");
y.title                       = @"Y Axis";
y.titleOffset                 = 45.0f;
y.titleLocation               = CPTDecimalFromFloat(150.0f);

// First bar plot
CPTBarPlot *barPlot = [CPTBarPlot tubularBarPlotWithColor:[CPTColor darkGrayColor] horizontalBars:NO];
barPlot.baseValue  = CPTDecimalFromString(@"0");
barPlot.barOffset  = CPTDecimalFromFloat(-0.50f);
barPlot.identifier = @"SOPI";
barPlot.dataSource = self;
[graph1 addPlot:barPlot toPlotSpace:plotSpace];    

}

Question

What is wrong with my implementation?

  • 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-05-30T19:51:25+00:00Added an answer on May 30, 2026 at 7:51 pm

    I found the solution to my problem:

    My return statement for the x values was missing numberWithFloat 6.0

    return    [[NSArray alloc]initWithObjects:[NSDecimalNumber numberWithFloat:1.0],
               [NSDecimalNumber numberWithFloat:2.0],
               [NSDecimalNumber numberWithFloat:3.0],
               [NSDecimalNumber numberWithFloat:4.0],
               [NSDecimalNumber numberWithFloat:5.0],
               nil]; 
    

    In addition, the length in plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0f) length:CPTDecimalFromFloat(5.0f)]was only 5. However, I have 6 x-values. I have set the length to 6.5 now. However, when setting it to 6.0, the right bar is shown

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

Sidebar

Related Questions

I have a problem drawing the legend of a pieChart with Core-Plot, because the
Here I stuck with a problem in drawing the pie chart using coreplot in
I have a problem drawing something quickly in .NET. I don't think that any
I am working on kind of drawing program but I have a problem with
I have a complex SQL problem in MS SQL Server, and in drawing on
I've encountered a problem drawing SFML Text. In my application, I use views as
I'm having a graphics problem on drawing lines in Flash Player, where two lines
Problem in drawing a semi transparent PNG image on TBitmap object. If the TBitmap's
There's a problem with drawing gridlines in listview with common controls 6. It happens
I have problem optimizing drawing Google-like map. It works OK for hundreds of points,

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.