Jonathan Tron

Allow setting Top/Bottom/Left/Right margins independently in PNBarChart

... ... @@ -46,7 +46,10 @@ typedef NSString *(^PNYLabelFormatter)(CGFloat yLabelValue);
/** Formats the ylabel text. */
@property (copy) PNYLabelFormatter yLabelFormatter;
@property (nonatomic) CGFloat chartMargin;
@property (nonatomic) CGFloat chartMarginLeft;
@property (nonatomic) CGFloat chartMarginRight;
@property (nonatomic) CGFloat chartMarginTop;
@property (nonatomic) CGFloat chartMarginBottom;
/** Controls whether labels should be displayed. */
@property (nonatomic) BOOL showLabel;
... ...
This diff is collapsed. Click to expand it.
... ... @@ -91,20 +91,33 @@
}
else if ([self.title isEqualToString:@"Bar Chart"])
{
static NSNumberFormatter *barChartFormatter;
if (!barChartFormatter){
barChartFormatter = [[NSNumberFormatter alloc] init];
barChartFormatter.numberStyle = NSNumberFormatterCurrencyStyle;
barChartFormatter.allowsFloats = NO;
barChartFormatter.maximumFractionDigits = 0;
}
self.titleLabel.text = @"Bar Chart";
self.barChart = [[PNBarChart alloc] initWithFrame:CGRectMake(0, 135.0, SCREEN_WIDTH, 200.0)];
// self.barChart.showLabel = NO;
self.barChart.backgroundColor = [UIColor clearColor];
self.barChart.yLabelFormatter = ^(CGFloat yValue){
CGFloat yValueParsed = yValue;
NSString * labelText = [NSString stringWithFormat:@"%0.f",yValueParsed];
return labelText;
return [barChartFormatter stringFromNumber:[NSNumber numberWithFloat:yValue]];
};
self.barChart.yChartLabelWidth = 60.0;
self.barChart.chartMarginLeft = 70.0;
self.barChart.chartMarginRight = 10.0;
self.barChart.chartMarginTop = 5.0;
self.barChart.chartMarginBottom = 10.0;
self.barChart.labelMarginTop = 5.0;
self.barChart.showChartBorder = YES;
[self.barChart setXLabels:@[@"2",@"3",@"4",@"5",@"2",@"3",@"4",@"5"]];
// self.barChart.yLabels = @[@-10,@0,@10];
// [self.barChart setYValues:@[@10000.0,@30000.0,@10000.0,@100000.0,@500000.0,@1000000.0,@1150000.0,@2150000.0]];
[self.barChart setYValues:@[@10.82,@1.88,@6.96,@33.93,@10.82,@1.88,@6.96,@33.93]];
[self.barChart setStrokeColors:@[PNGreen,PNGreen,PNRed,PNGreen,PNGreen,PNGreen,PNRed,PNGreen]];
self.barChart.isGradientShow = NO;
... ...