klauslanza

Merge pull request #2 from klauslanza/klauslanza-lineChartYlabelFormatter

Klauslanza line chart ylabel formatter
... ... @@ -66,6 +66,11 @@
*/
@property (nonatomic, strong) NSString *yLabelFormat;
/**
* Block formatter for custom string in y-axis labels. If not set, defaults to yLabelFormat
*/
@property (nonatomic, copy) NSString* (^yLabelBlockFormatter)(CGFloat);
- (void)setXLabels:(NSArray *)xLabels withWidth:(CGFloat)width;
/**
... ...
... ... @@ -821,20 +821,26 @@
}
}
- (NSString*) formatYLabel:(double)value{
if (!self.thousandsSeparator) {
NSString *format = self.yLabelFormat ? : @"%1.f";
return [NSString stringWithFormat:format,value];
if (self.yLabelBlockFormatter)
{
return self.yLabelBlockFormatter(value);
}
else
{
if (!self.thousandsSeparator) {
NSString *format = self.yLabelFormat ? : @"%1.f";
return [NSString stringWithFormat:format,value];
}
NSNumberFormatter* numberFormatter = [[NSNumberFormatter alloc] init];
[numberFormatter setFormatterBehavior: NSNumberFormatterBehavior10_4];
[numberFormatter setNumberStyle: NSNumberFormatterDecimalStyle];
return [numberFormatter stringFromNumber: [NSNumber numberWithDouble:value]];
}
NSNumberFormatter* numberFormatter = [[NSNumberFormatter alloc] init];
[numberFormatter setFormatterBehavior: NSNumberFormatterBehavior10_4];
[numberFormatter setNumberStyle: NSNumberFormatterDecimalStyle];
return [numberFormatter stringFromNumber: [NSNumber numberWithDouble:value]];
}
- (UIView*) getLegendWithMaxWidth:(CGFloat)mWidth{
if ([self.chartData count] < 1) {
return nil;
... ...