olunx

Add PNLineChart with setYLabels.

... ... @@ -47,6 +47,8 @@
@property (nonatomic) CGFloat chartCavanWidth;
@property (nonatomic) CGFloat chartMargin;
@property (nonatomic) BOOL showLabel;
@property (nonatomic) BOOL showGenYLabels;
/**
* Controls whether to show the coordinate axis. Default is NO.
... ...
... ... @@ -52,7 +52,7 @@
#pragma mark instance methods
- (void)setYLabels:(NSArray *)yLabels
- (void)setYLabels
{
CGFloat yStep = (_yValueMax - _yValueMin) / _yLabelNum;
CGFloat yStepHeight = _chartCavanHeight / _yLabelNum;
... ... @@ -104,6 +104,54 @@
}
}
- (void)setYLabels:(NSArray *)yLabels
{
_showGenYLabels = NO;
_yLabelNum = yLabels.count - 1;
CGFloat yLabelHeight;
if (_showLabel) {
yLabelHeight = _chartCavanHeight / [yLabels count];
} else {
yLabelHeight = (self.frame.size.height) / [yLabels count];
}
return [self setYLabels:yLabels withHeight:yLabelHeight];
}
- (void)setYLabels:(NSArray *)yLabels withHeight:(CGFloat)height
{
_yLabels = yLabels;
_yLabelHeight = height;
if (_yChartLabels) {
for (PNChartLabel * label in _yChartLabels) {
[label removeFromSuperview];
}
}else{
_yChartLabels = [NSMutableArray new];
}
NSString *labelText;
if (_showLabel) {
CGFloat yStepHeight = _chartCavanHeight / _yLabelNum;
for (int index = 0; index < yLabels.count; index++) {
labelText = yLabels[index];
#warning modify origin
NSInteger y = (NSInteger)(_chartCavanHeight - index * yStepHeight);
PNChartLabel *label = [[PNChartLabel alloc] initWithFrame:CGRectMake(0.0, y, (NSInteger)_chartMargin, (NSInteger)_yLabelHeight)];
[label setTextAlignment:NSTextAlignmentRight];
label.text = labelText;
[self setCustomStyleForYLabel:label];
[self addSubview:label];
[_yChartLabels addObject:label];
}
}
}
- (CGFloat)computeEqualWidthForXLabels:(NSArray *)xLabels
{
CGFloat xLabelWidth;
... ... @@ -548,8 +596,8 @@
_yValueMin = _yFixedValueMin ? _yFixedValueMin : yMin ;
_yValueMax = _yFixedValueMax ? _yFixedValueMax : yMax + yMax / 10.0;
if (_showLabel) {
[self setYLabels:yLabelsArray];
if (_showGenYLabels) {
[self setYLabels];
}
}
... ... @@ -683,6 +731,7 @@
self.clipsToBounds = YES;
self.chartLineArray = [NSMutableArray new];
_showLabel = YES;
_showGenYLabels = YES;
_pathPoints = [[NSMutableArray alloc] init];
_endPointsOfPath = [[NSMutableArray alloc] init];
self.userInteractionEnabled = YES;
... ...
... ... @@ -33,11 +33,22 @@
//Use yFixedValueMax and yFixedValueMin to Fix the Max and Min Y Value
//Only if you needed
self.lineChart.yFixedValueMax = 500.0;
self.lineChart.yFixedValueMin = 1.0;
self.lineChart.yFixedValueMax = 300.0;
self.lineChart.yFixedValueMin = 0.0;
[self.lineChart setYLabels:@[
@"0 min",
@"50 min",
@"100 min",
@"150 min",
@"200 min",
@"250 min",
@"300 min",
]
];
// Line Chart #1
NSArray * data01Array = @[@60.1, @160.1, @126.4, @262.2, @186.2, @127.2, @176.2];
NSArray * data01Array = @[@60.1, @160.1, @126.4, @0.0, @186.2, @127.2, @176.2];
PNLineChartData *data01 = [PNLineChartData new];
data01.dataTitle = @"Alpha";
data01.color = PNFreshGreen;
... ... @@ -50,7 +61,7 @@
};
// Line Chart #2
NSArray * data02Array = @[@20.1, @180.1, @26.4, @202.2, @126.2, @167.2, @276.2];
NSArray * data02Array = @[@0.0, @180.1, @26.4, @202.2, @126.2, @167.2, @276.2];
PNLineChartData *data02 = [PNLineChartData new];
data02.dataTitle = @"Beta Beta Beta Beta";
data02.color = PNTwitterColor;
... ...