Nuno Dias

Added yLabelFormat property to define the y axis label formatting.

... ... @@ -63,4 +63,9 @@
@property (nonatomic, strong) NSString *xUnit;
@property (nonatomic, strong) NSString *yUnit;
/**
* String formatter for float values in y labels. If not set, defaults to @"%1.f"
*/
@property (nonatomic, strong) NSString *yLabelFormat;
@end
... ...
... ... @@ -72,7 +72,8 @@
while (num > 0) {
PNChartLabel *label = [[PNChartLabel alloc] initWithFrame:CGRectMake(0.0, (_chartCavanHeight - index * yStepHeight), _chartMargin, _yLabelHeight)];
[label setTextAlignment:NSTextAlignmentRight];
label.text = [NSString stringWithFormat:@"%1.f", _yValueMin + (yStep * index)];
NSString *yLabelFormat = self.yLabelFormat ? self.yLabelFormat : @"%1.f";
label.text = [NSString stringWithFormat:yLabelFormat, _yValueMin + (yStep * index)];
[self addSubview:label];
index += 1;
num -= 1;
... ... @@ -368,7 +369,7 @@
_yLabelNum = 5.0;
_yLabelHeight = [[[[PNChartLabel alloc] init] font] pointSize];
_chartMargin = 30;
_chartMargin = 40;
_chartCavanWidth = self.frame.size.width - _chartMargin * 2;
_chartCavanHeight = self.frame.size.height - _chartMargin * 2;
... ...
... ... @@ -61,6 +61,7 @@
lineChartLabel.textAlignment = NSTextAlignmentCenter;
PNLineChart * lineChart = [[PNLineChart alloc] initWithFrame:CGRectMake(0, 135.0, SCREEN_WIDTH, 200.0)];
lineChart.yLabelFormat = @"%1.1f";
lineChart.backgroundColor = [UIColor clearColor];
[lineChart setXLabels:@[@"SEP 1",@"SEP 2",@"SEP 3",@"SEP 4",@"SEP 5",@"SEP 6",@"SEP 7"]];
... ...