gujjula / core-plot

Automatically exported from code.google.com/p/core-plot
0 stars 0 forks source link

Bar Plots are cut off on the side regardless of barOffset value #290

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Creating a bar chart, image attached. X range is from 0 to 6.5 (0.5 is for the 
second half of the bar on the right side.) Bar plot is created using this code:

        // Create bar plot
        CPBarPlot *barPlot = [CPBarPlot tubularBarPlotWithColor:[CPColor whiteColor] horizontalBars:NO];
        barPlot.fill = [CPFill fillWithColor:[CPColor colorWithCGColor:[kYellowColor CGColor]]];
        barPlot.baseValue = CPDecimalFromString(@"0");
        barPlot.dataSource = self;
        barPlot.baseValue = CPDecimalFromFloat(0.0);
        barPlot.barOffset = 0.5;
        barPlot.cornerRadius = 2.0;
        barPlot.lineStyle = nil;
        [graph addPlot:barPlot toPlotSpace:plotSpace];

The left bar is half cut-off, and the position doesn't change no matter what 
the bar offset is set to. Not sure if this is a bug in Core Plot, or a bug in 
my graph implementation. I'm not 100% sure what version of Core Plot I'm using, 
but it's pretty recent. I've had to make a few minor changes to CPLayer to get 
Core Plot to render vector graphs to PDF.

Original issue reported on code.google.com by cory.imd...@gmail.com on 8 Jun 2011 at 12:44

Attachments:

GoogleCodeExporter commented 9 years ago
Hey, please show us your numberForPlot delegate method. I think you return 
something like

-(NSNumber *) numberForPlot:(CPPlot *)plot field:(NSUInteger)fieldEnum 
recordIndex:(NSUInteger)index { 
   switch(fieldEnum)
     case CPBarPlotFieldBarLocation:
            return = index;

whereby you should do a return of index + 0.5;
-> this will center your bar between index and index +1
this is quite useful since touch events also refer to these zones. (a touch 
between 0 and 1 will result in a zero)

Original comment by Wrede....@gmail.com on 8 Jun 2011 at 12:28

GoogleCodeExporter commented 9 years ago
This took care of the issue for me, but it feels like a hack. Seems like I'm 
feeding the graph false data so it shows up properly. Shouldn't Core Plot just 
handle this situation gracefully and adjust accordingly?

Anyway, thanks for the feedback - this is perfect in the meantime.

Original comment by cory.imd...@gmail.com on 8 Jun 2011 at 8:55

GoogleCodeExporter commented 9 years ago
Another possible solution is to change the x plot range to start at -0.5 and 
increase the length accordingly. Core Plot does not automatically adjust the 
plot range for you.

Original comment by eskr...@mac.com on 9 Jun 2011 at 1:31