Merge pull request #208 from klauslanza/klauslanza-lineChartYlabelFormatter
Line chart ylabel formatter block
Showing
2 changed files
with
13 additions
and
2 deletions
| @@ -66,6 +66,11 @@ | @@ -66,6 +66,11 @@ | ||
| 66 | */ | 66 | */ |
| 67 | @property (nonatomic, strong) NSString *yLabelFormat; | 67 | @property (nonatomic, strong) NSString *yLabelFormat; |
| 68 | 68 | ||
| 69 | +/** | ||
| 70 | + * Block formatter for custom string in y-axis labels. If not set, defaults to yLabelFormat | ||
| 71 | + */ | ||
| 72 | +@property (nonatomic, copy) NSString* (^yLabelBlockFormatter)(CGFloat); | ||
| 73 | + | ||
| 69 | - (void)setXLabels:(NSArray *)xLabels withWidth:(CGFloat)width; | 74 | - (void)setXLabels:(NSArray *)xLabels withWidth:(CGFloat)width; |
| 70 | 75 | ||
| 71 | /** | 76 | /** |
| @@ -821,8 +821,14 @@ | @@ -821,8 +821,14 @@ | ||
| 821 | } | 821 | } |
| 822 | } | 822 | } |
| 823 | 823 | ||
| 824 | - | ||
| 825 | - (NSString*) formatYLabel:(double)value{ | 824 | - (NSString*) formatYLabel:(double)value{ |
| 825 | + | ||
| 826 | + if (self.yLabelBlockFormatter) | ||
| 827 | + { | ||
| 828 | + return self.yLabelBlockFormatter(value); | ||
| 829 | + } | ||
| 830 | + else | ||
| 831 | + { | ||
| 826 | if (!self.thousandsSeparator) { | 832 | if (!self.thousandsSeparator) { |
| 827 | NSString *format = self.yLabelFormat ? : @"%1.f"; | 833 | NSString *format = self.yLabelFormat ? : @"%1.f"; |
| 828 | return [NSString stringWithFormat:format,value]; | 834 | return [NSString stringWithFormat:format,value]; |
| @@ -832,9 +838,9 @@ | @@ -832,9 +838,9 @@ | ||
| 832 | [numberFormatter setFormatterBehavior: NSNumberFormatterBehavior10_4]; | 838 | [numberFormatter setFormatterBehavior: NSNumberFormatterBehavior10_4]; |
| 833 | [numberFormatter setNumberStyle: NSNumberFormatterDecimalStyle]; | 839 | [numberFormatter setNumberStyle: NSNumberFormatterDecimalStyle]; |
| 834 | return [numberFormatter stringFromNumber: [NSNumber numberWithDouble:value]]; | 840 | return [numberFormatter stringFromNumber: [NSNumber numberWithDouble:value]]; |
| 841 | + } | ||
| 835 | } | 842 | } |
| 836 | 843 | ||
| 837 | - | ||
| 838 | - (UIView*) getLegendWithMaxWidth:(CGFloat)mWidth{ | 844 | - (UIView*) getLegendWithMaxWidth:(CGFloat)mWidth{ |
| 839 | if ([self.chartData count] < 1) { | 845 | if ([self.chartData count] < 1) { |
| 840 | return nil; | 846 | return nil; |
-
Please register or login to post a comment