Showing
3 changed files
with
32 additions
and
3 deletions
| @@ -24,7 +24,8 @@ | @@ -24,7 +24,8 @@ | ||
| 24 | @property (nonatomic) UIColor *axisColor; | 24 | @property (nonatomic) UIColor *axisColor; |
| 25 | @property (nonatomic) CGFloat axisWidth; | 25 | @property (nonatomic) CGFloat axisWidth; |
| 26 | 26 | ||
| 27 | -/** String formatter for float values in y-axis labels. If not set, defaults to @"%1.f" */ | 27 | +/** String formatter for float values in x-axis/y-axis labels. If not set, defaults to @"%1.f" */ |
| 28 | +@property (nonatomic, strong) NSString *xLabelFormat; | ||
| 28 | @property (nonatomic, strong) NSString *yLabelFormat; | 29 | @property (nonatomic, strong) NSString *yLabelFormat; |
| 29 | 30 | ||
| 30 | /** Default is true. */ | 31 | /** Default is true. */ |
| @@ -53,6 +54,8 @@ | @@ -53,6 +54,8 @@ | ||
| 53 | 54 | ||
| 54 | - (void) setAxisXWithMinimumValue:(CGFloat)minVal andMaxValue:(CGFloat)maxVal toTicks:(int)numberOfTicks; | 55 | - (void) setAxisXWithMinimumValue:(CGFloat)minVal andMaxValue:(CGFloat)maxVal toTicks:(int)numberOfTicks; |
| 55 | - (void) setAxisYWithMinimumValue:(CGFloat)minVal andMaxValue:(CGFloat)maxVal toTicks:(int)numberOfTicks; | 56 | - (void) setAxisYWithMinimumValue:(CGFloat)minVal andMaxValue:(CGFloat)maxVal toTicks:(int)numberOfTicks; |
| 57 | +- (void) setAxisXLabel:(NSArray *)array; | ||
| 58 | +- (void) setAxisYLabel:(NSArray *)array; | ||
| 56 | - (void) setup; | 59 | - (void) setup; |
| 57 | - (void) drawLineFromPoint : (CGPoint) startPoint ToPoint : (CGPoint) endPoint WithLineWith : (CGFloat) lineWidth AndWithColor : (UIColor*) color; | 60 | - (void) drawLineFromPoint : (CGPoint) startPoint ToPoint : (CGPoint) endPoint WithLineWith : (CGFloat) lineWidth AndWithColor : (UIColor*) color; |
| 58 | 61 |
| @@ -123,7 +123,7 @@ | @@ -123,7 +123,7 @@ | ||
| 123 | _AxisX_partNumber = numberOfTicks - 1; | 123 | _AxisX_partNumber = numberOfTicks - 1; |
| 124 | _AxisX_step = (float)((maxVal - minVal)/_AxisX_partNumber); | 124 | _AxisX_step = (float)((maxVal - minVal)/_AxisX_partNumber); |
| 125 | 125 | ||
| 126 | - NSString *LabelFormat = self.yLabelFormat ? : @"%1.f"; | 126 | + NSString *LabelFormat = self.xLabelFormat ? : @"%1.f"; |
| 127 | CGFloat tempValue = minVal ; | 127 | CGFloat tempValue = minVal ; |
| 128 | UILabel *label = [[UILabel alloc] init]; | 128 | UILabel *label = [[UILabel alloc] init]; |
| 129 | label.text = [NSString stringWithFormat:LabelFormat,minVal] ; | 129 | label.text = [NSString stringWithFormat:LabelFormat,minVal] ; |
| @@ -156,6 +156,28 @@ | @@ -156,6 +156,28 @@ | ||
| 156 | } | 156 | } |
| 157 | } | 157 | } |
| 158 | 158 | ||
| 159 | +- (void)setAxisXLabel:(NSArray *)array { | ||
| 160 | + if(array.count == ++_AxisX_partNumber){ | ||
| 161 | + [_axisX_labels removeAllObjects]; | ||
| 162 | + for(int i=0;i<array.count;i++){ | ||
| 163 | + UILabel *label = [[UILabel alloc] init]; | ||
| 164 | + label.text = [array objectAtIndex:i]; | ||
| 165 | + [_axisX_labels addObject:label]; | ||
| 166 | + } | ||
| 167 | + } | ||
| 168 | +} | ||
| 169 | + | ||
| 170 | +- (void)setAxisYLabel:(NSArray *)array { | ||
| 171 | + if(array.count == ++_AxisY_partNumber){ | ||
| 172 | + [_axisY_labels removeAllObjects]; | ||
| 173 | + for(int i=0;i<array.count;i++){ | ||
| 174 | + UILabel *label = [[UILabel alloc] init]; | ||
| 175 | + label.text = [array objectAtIndex:i]; | ||
| 176 | + [_axisY_labels addObject:label]; | ||
| 177 | + } | ||
| 178 | + } | ||
| 179 | +} | ||
| 180 | + | ||
| 159 | - (void) vectorXSetup | 181 | - (void) vectorXSetup |
| 160 | { | 182 | { |
| 161 | _AxisX_partNumber += 1; | 183 | _AxisX_partNumber += 1; |
| @@ -129,9 +129,12 @@ | @@ -129,9 +129,12 @@ | ||
| 129 | self.titleLabel.text = @"Scatter Chart"; | 129 | self.titleLabel.text = @"Scatter Chart"; |
| 130 | 130 | ||
| 131 | self.scatterChart = [[PNScatterChart alloc] initWithFrame:CGRectMake(SCREEN_WIDTH /6.0 - 30, 135, 280, 200)]; | 131 | self.scatterChart = [[PNScatterChart alloc] initWithFrame:CGRectMake(SCREEN_WIDTH /6.0 - 30, 135, 280, 200)]; |
| 132 | +// self.scatterChart.yLabelFormat = @"xxx %1.1f"; | ||
| 132 | [self.scatterChart setAxisXWithMinimumValue:20 andMaxValue:100 toTicks:6]; | 133 | [self.scatterChart setAxisXWithMinimumValue:20 andMaxValue:100 toTicks:6]; |
| 133 | [self.scatterChart setAxisYWithMinimumValue:30 andMaxValue:50 toTicks:5]; | 134 | [self.scatterChart setAxisYWithMinimumValue:30 andMaxValue:50 toTicks:5]; |
| 134 | - | 135 | + [self.scatterChart setAxisXLabel:@[@"x1", @"x2", @"x3", @"x4", @"x5", @"x6"]]; |
| 136 | + [self.scatterChart setAxisYLabel:@[@"y1", @"y2", @"y3", @"y4", @"y5"]]; | ||
| 137 | + | ||
| 135 | NSArray * data01Array = [self randomSetOfObjects]; | 138 | NSArray * data01Array = [self randomSetOfObjects]; |
| 136 | PNScatterChartData *data01 = [PNScatterChartData new]; | 139 | PNScatterChartData *data01 = [PNScatterChartData new]; |
| 137 | data01.strokeColor = PNGreen; | 140 | data01.strokeColor = PNGreen; |
| @@ -141,6 +144,7 @@ | @@ -141,6 +144,7 @@ | ||
| 141 | data01.inflexionPointStyle = PNScatterChartPointStyleCircle; | 144 | data01.inflexionPointStyle = PNScatterChartPointStyleCircle; |
| 142 | __block NSMutableArray *XAr1 = [NSMutableArray arrayWithArray:[data01Array objectAtIndex:0]]; | 145 | __block NSMutableArray *XAr1 = [NSMutableArray arrayWithArray:[data01Array objectAtIndex:0]]; |
| 143 | __block NSMutableArray *YAr1 = [NSMutableArray arrayWithArray:[data01Array objectAtIndex:1]]; | 146 | __block NSMutableArray *YAr1 = [NSMutableArray arrayWithArray:[data01Array objectAtIndex:1]]; |
| 147 | + | ||
| 144 | data01.getData = ^(NSUInteger index) { | 148 | data01.getData = ^(NSUInteger index) { |
| 145 | CGFloat xValue = [[XAr1 objectAtIndex:index] floatValue]; | 149 | CGFloat xValue = [[XAr1 objectAtIndex:index] floatValue]; |
| 146 | CGFloat yValue = [[YAr1 objectAtIndex:index] floatValue]; | 150 | CGFloat yValue = [[YAr1 objectAtIndex:index] floatValue]; |
-
Please register or login to post a comment