Leii

Radar Chart

A radar chart is a graphical method of displaying multivariate data in
the form of a two-dimensional chart of three or more quantitative
variables represented on axes starting from the same point.
... ... @@ -18,3 +18,5 @@
#import "PNChartDelegate.h"
#import "PNPieChart.h"
#import "PNScatterChart.h"
#import "PNRadarChart.h"
#import "PNRadarChartDataItem.h"
... ...
//
// PNRadarChart.h
// PNChartDemo
//
// Created by Lei on 15/7/1.
// Copyright (c) 2015年 kevinzhow. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "PNGenericChart.h"
#import "PNRadarChartDataItem.h"
#define MAXCIRCLE 20
typedef NS_ENUM(NSUInteger, PNRadarChartLabelStyle) {
PNRadarChartLabelStyleCircle = 0,
PNRadarChartLabelStyleHorizontal,
PNRadarChartLabelStyleHidden,
};
@interface PNRadarChart : PNGenericChart
-(id)initWithFrame:(CGRect)frame items:(NSArray *)items valueDivider:(CGFloat)unitValue;
/**
*Draws the chart in an animated fashion.
*/
-(void)strokeChart;
/** Array of `RadarChartDataItem` objects, one for each corner. */
@property(nonatomic)NSArray *chartData;
/** The unit of this chart ,default is 1 */
@property(nonatomic)CGFloat valueDivider;
/** The maximum for the range of values to display on the chart */
@property(nonatomic)CGFloat maxValue;
/** Default is gray. */
@property(nonatomic)UIColor *webColor;
/** Default is green , with an alpha of 0.7 */
@property(nonatomic)UIColor *plotColor;
/** Default is black */
@property(nonatomic)UIColor *fontColor;
/** Default is orange */
@property(nonatomic)UIColor *graduationColor;
/** Default is 15 */
@property(nonatomic)CGFloat fontSize;
/** Controls the labels display style that around chart */
@property(nonatomic,assign)PNRadarChartLabelStyle labelStyle;
/** Tap the label will display detail value ,default is YES. */
@property(nonatomic,assign)BOOL isLabelTouchable;
/** is show graduation on the chart ,default is NO. */
@property(nonatomic,assign)BOOL isShowGraduation;
@end
... ...
//
// PNRadarChart.m
// PNChartDemo
//
// Created by Lei on 15/7/1.
// Copyright (c) 2015年 kevinzhow. All rights reserved.
//
#import "PNRadarChart.h"
@interface PNRadarChart()
@property(nonatomic)CGFloat centerX;
@property(nonatomic)CGFloat centerY;
@property(nonatomic)NSMutableArray *pointsToWebArrayArray;
@property(nonatomic)NSMutableArray *pointsToPlotArray;
@property(nonatomic)UILabel *detailLabel;
@property(nonatomic)CGFloat lengthUnit;
@property(nonatomic)CAShapeLayer *chartPlot;
@end
@implementation PNRadarChart
-(id)initWithFrame:(CGRect)frame items:(NSArray *)items valueDivider:(CGFloat)unitValue{
self=[super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor clearColor];
self.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
//Public iVar
if ([items count]< 3) {
NSLog( @"At least three items!");
NSArray *defaultArray = @[[PNRadarChartDataItem dataItemWithValue:0 description:@"Default"],
[PNRadarChartDataItem dataItemWithValue:0 description:@"Default"],
[PNRadarChartDataItem dataItemWithValue:0 description:@"Default"],
];
defaultArray = [defaultArray arrayByAddingObjectsFromArray:items];
_chartData = [NSArray arrayWithArray:defaultArray];
}else{
_chartData = [NSArray arrayWithArray:items];
}
_valueDivider = unitValue;
_maxValue = 1;
_webColor = [UIColor grayColor];
_plotColor = [UIColor colorWithRed:.4 green:.8 blue:.4 alpha:.7];
_fontColor = [UIColor blackColor];
_graduationColor = [UIColor orangeColor];
_fontSize = 15;
_labelStyle = PNRadarChartLabelStyleHorizontal;
_isLabelTouchable = YES;
_isShowGraduation = NO;
//Private iVar
_centerX = frame.size.width/2;
_centerY = frame.size.height/2;
_pointsToWebArrayArray = [NSMutableArray array];
_pointsToPlotArray = [NSMutableArray array];
_lengthUnit = 0;
_chartPlot = [CAShapeLayer layer];
_chartPlot.lineCap = kCALineCapButt;
_chartPlot.fillColor = _plotColor.CGColor;
_chartPlot.lineWidth = 1.0;
[self.layer addSublayer:_chartPlot];
//init detailLabel
_detailLabel = [[UILabel alloc] init];
_detailLabel.backgroundColor = [UIColor colorWithRed:.9 green:.9 blue:.1 alpha:.9];
_detailLabel.textAlignment = NSTextAlignmentCenter;
_detailLabel.textColor = [UIColor colorWithWhite:1 alpha:1];
_detailLabel.font = [UIFont systemFontOfSize:15];
[_detailLabel setHidden:YES];
[self addSubview:_detailLabel];
[self strokeChart];
}
return self;
}
#pragma mark - main
-(void)calculateChartPoints{
[_pointsToPlotArray removeAllObjects];
[_pointsToWebArrayArray removeAllObjects];
//init Descriptions , Values and Angles.
NSMutableArray *descriptions = [NSMutableArray array];
NSMutableArray *values = [NSMutableArray array];
NSMutableArray *angles = [NSMutableArray array];
for (int i=0;i<_chartData.count;i++) {
PNRadarChartDataItem *item = (PNRadarChartDataItem *)[_chartData objectAtIndex:i];
[descriptions addObject:item.textDescription];
[values addObject:[NSNumber numberWithFloat:item.value]];
CGFloat angleValue = (float)i/(float)[_chartData count]*2*M_PI;
[angles addObject:[NSNumber numberWithFloat:angleValue]];
}
//calculate all the lengths
_maxValue = [self getMaxValueFromArray:values];
CGFloat margin = 0;
if (_labelStyle==PNRadarChartLabelStyleCircle) {
margin = MIN(_centerX , _centerY)*3/10;
}else if (_labelStyle==PNRadarChartLabelStyleHorizontal) {
margin = [self getMaxWidthLabelFromArray:descriptions withFontSize:_fontSize];
}
CGFloat maxLength = ceil(MIN(_centerX, _centerY) - margin);
int plotCircles = (_maxValue/_valueDivider);
if (plotCircles > MAXCIRCLE) {
NSLog(@"Circle number is higher than max");
plotCircles = MAXCIRCLE;
_valueDivider = _maxValue/plotCircles;
}
_lengthUnit = maxLength/plotCircles;
NSArray *lengthArray = [self getLengthArrayWithCircleNum:(int)plotCircles];
//get all the points and plot
for (NSNumber *lengthNumber in lengthArray) {
CGFloat length = [lengthNumber floatValue];
[_pointsToWebArrayArray addObject:[self getWebPointWithLength:length angleArray:angles]];
}
int section = 0;
for (id value in values) {
CGFloat valueFloat = [value floatValue];
if (valueFloat>_maxValue) {
NSString *reason = [NSString stringWithFormat:@"Value number is higher than max -value: %f - maxValue: %f",valueFloat,_maxValue];
@throw [NSException exceptionWithName:NSInvalidArgumentException reason:reason userInfo:nil];
return;
}
CGFloat length = valueFloat/_maxValue*maxLength;
CGFloat angle = [[angles objectAtIndex:section] floatValue];
CGFloat x = _centerX +length*cos(angle);
CGFloat y = _centerY +length*sin(angle);
NSValue* point = [NSValue valueWithCGPoint:CGPointMake(x, y)];
[_pointsToPlotArray addObject:point];
section++;
}
//set the labels
[self drawLabelWithMaxLength:maxLength labelArray:descriptions angleArray:angles];
}
#pragma mark - Draw
- (void)drawRect:(CGRect)rect {
// Drawing code
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextClearRect(context, rect);
int section = 0;
//circles
for(NSArray *pointArray in _pointsToWebArrayArray){
//plot backgound
CGContextRef graphContext = UIGraphicsGetCurrentContext();
CGContextBeginPath(graphContext);
CGPoint beginPoint = [[pointArray objectAtIndex:0] CGPointValue];
CGContextMoveToPoint(graphContext, beginPoint.x, beginPoint.y);
for(NSValue* pointValue in pointArray){
CGPoint point = [pointValue CGPointValue];
CGContextAddLineToPoint(graphContext, point.x, point.y);
}
CGContextAddLineToPoint(graphContext, beginPoint.x, beginPoint.y);
CGContextSetStrokeColorWithColor(graphContext, _webColor.CGColor);
CGContextStrokePath(graphContext);
}
//cuts
NSArray *largestPointArray = [_pointsToWebArrayArray lastObject];
for (NSValue *pointValue in largestPointArray){
section++;
if (section==1&&_isShowGraduation)continue;
CGContextRef graphContext = UIGraphicsGetCurrentContext();
CGContextBeginPath(graphContext);
CGContextMoveToPoint(graphContext, _centerX, _centerY);
CGPoint point = [pointValue CGPointValue];
CGContextAddLineToPoint(graphContext, point.x, point.y);
CGContextSetStrokeColorWithColor(graphContext, _webColor.CGColor);
CGContextStrokePath(graphContext);
}
}
-(void)strokeChart{
[self calculateChartPoints];
[self setNeedsDisplay];
[_detailLabel setHidden:YES];
//Draw plot
[_chartPlot removeAllAnimations];
UIBezierPath *plotline = [UIBezierPath bezierPath];
CGPoint beginPoint = [[_pointsToPlotArray objectAtIndex:0] CGPointValue];
[plotline moveToPoint:CGPointMake(beginPoint.x, beginPoint.y)];
for(NSValue *pointValue in _pointsToPlotArray){
CGPoint point = [pointValue CGPointValue];
[plotline addLineToPoint:CGPointMake(point.x ,point.y)];
}
[plotline setLineWidth:1];
[plotline setLineCapStyle:kCGLineCapButt];
_chartPlot.path = plotline.CGPath;
CABasicAnimation *animateScale = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
animateScale.fromValue = [NSNumber numberWithFloat:0.f];
animateScale.toValue = [NSNumber numberWithFloat:1.0f];
CABasicAnimation *animateMove = [CABasicAnimation animationWithKeyPath:@"position"];
animateMove.fromValue = [NSValue valueWithCGPoint:CGPointMake(_centerX, _centerY)];
animateMove.toValue = [NSValue valueWithCGPoint:CGPointMake(0, 0)];
CABasicAnimation *animateAlpha = [CABasicAnimation animationWithKeyPath:@"opacity"];
animateAlpha.fromValue = [NSNumber numberWithFloat:0.f];
CAAnimationGroup *aniGroup = [CAAnimationGroup animation];
aniGroup.duration = 1.f;
aniGroup.repeatCount = 1;
aniGroup.animations = [NSArray arrayWithObjects:animateScale,animateMove,animateAlpha, nil];
aniGroup.removedOnCompletion = YES;
[_chartPlot addAnimation:aniGroup forKey:nil];
[self showGraduation];
}
#pragma mark - Helper
-(void)drawLabelWithMaxLength:(CGFloat)maxLength labelArray:(NSArray *)labelArray angleArray:(NSArray *)angleArray{
//set labels
int labelTag = 121;
while (true) {
UIView *label = [self viewWithTag:labelTag];
if(!label)break;
[label removeFromSuperview];
}
int section = 0;
CGFloat labelLength = maxLength + maxLength/10;
for (NSString *labelString in labelArray) {
CGFloat angle = [[angleArray objectAtIndex:section] floatValue];
CGFloat x = _centerX + labelLength *cos(angle);
CGFloat y = _centerY + labelLength *sin(angle);
UILabel *label = [[UILabel alloc] init] ;
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont systemFontOfSize:_fontSize];
label.text = labelString;
label.tag = labelTag;
CGSize detailSize = [labelString sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:_fontSize]}];
switch (_labelStyle) {
case PNRadarChartLabelStyleCircle:
label.frame = CGRectMake(x-5*_fontSize/2, y-_fontSize/2, 5*_fontSize, _fontSize);
label.transform = CGAffineTransformMakeRotation(((float)section/[labelArray count])*(2*M_PI)+M_PI_2);
label.textAlignment = NSTextAlignmentCenter;
break;
case PNRadarChartLabelStyleHorizontal:
if (x<_centerX) {
label.frame = CGRectMake(x-detailSize.width, y-detailSize.height/2, detailSize.width, detailSize.height);
label.textAlignment = NSTextAlignmentRight;
}else{
label.frame = CGRectMake(x, y-detailSize.height/2, detailSize.width , detailSize.height);
label.textAlignment = NSTextAlignmentLeft;
}
break;
case PNRadarChartLabelStyleHidden:
[label setHidden:YES];
break;
default:
break;
}
[label sizeToFit];
label.userInteractionEnabled = YES;
UITapGestureRecognizer *tapLabelGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapLabel:)];
[label addGestureRecognizer:tapLabelGesture];
[self addSubview:label];
section ++;
}
}
-(void)tapLabel:(UITapGestureRecognizer *)recognizer{
UILabel *label=(UILabel*)recognizer.view;
_detailLabel.frame = CGRectMake(label.frame.origin.x, label.frame.origin.y-30, 50, 25);
for (PNRadarChartDataItem *item in _chartData) {
if ([label.text isEqualToString:item.textDescription]) {
_detailLabel.text = [NSString stringWithFormat:@"%.2f", item.value];
break;
}
}
[_detailLabel setHidden:NO];
}
-(void)showGraduation{
int labelTag = 112;
while (true) {
UIView *label = [self viewWithTag:labelTag];
if(!label)break;
[label removeFromSuperview];
}
int section = 0;
for (NSArray *pointsArray in _pointsToWebArrayArray) {
section++;
CGPoint labelPoint = [[pointsArray objectAtIndex:0] CGPointValue];
UILabel *graduationLabel = [[UILabel alloc] initWithFrame:CGRectMake(labelPoint.x-_lengthUnit, labelPoint.y-_lengthUnit*5/8, _lengthUnit*5/8, _lengthUnit)];
graduationLabel.adjustsFontSizeToFitWidth = YES;
graduationLabel.tag = labelTag;
graduationLabel.font = [UIFont systemFontOfSize:ceil(_lengthUnit)];
graduationLabel.textColor = [UIColor orangeColor];
graduationLabel.text = [NSString stringWithFormat:@"%.0f",_valueDivider*section];
[self addSubview:graduationLabel];
if (_isShowGraduation) {
[graduationLabel setHidden:NO];
}else{
[graduationLabel setHidden:YES];}
}
}
-(NSArray *)getWebPointWithLength:(CGFloat)length angleArray:(NSArray *)angleArray{
NSMutableArray *pointArray = [NSMutableArray array];
for (NSNumber *angleNumber in angleArray) {
CGFloat angle = [angleNumber floatValue];
CGFloat x = _centerX + length*cos(angle);
CGFloat y = _centerY + length*sin(angle);
[pointArray addObject:[NSValue valueWithCGPoint:CGPointMake(x,y)]];
}
return pointArray;
}
-(NSArray *)getLengthArrayWithCircleNum:(int)plotCircles{
NSMutableArray *lengthArray = [NSMutableArray array];
CGFloat length = 0;
for (int i = 0; i < plotCircles; i++) {
length += _lengthUnit;
[lengthArray addObject:[NSNumber numberWithFloat:length]];
}
return lengthArray;
}
-(CGFloat)getMaxWidthLabelFromArray:(NSArray *)keyArray withFontSize:(CGFloat)size{
CGFloat maxWidth = 0;
for (NSString *str in keyArray) {
CGSize detailSize = [str sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:_fontSize]}];
maxWidth = MAX(maxWidth, detailSize.width);
}
return maxWidth;
}
-(CGFloat)getMaxValueFromArray:(NSArray *)valueArray{
CGFloat max = _maxValue;
for (NSNumber *valueNum in valueArray) {
CGFloat valueFloat = [valueNum floatValue];
max = MAX(valueFloat, max);
}
return ceil(max);
}
@end
... ...
//
// PNRadarChartDataItem.h
// PNChartDemo
//
// Created by Lei on 15/7/1.
// Copyright (c) 2015年 kevinzhow. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface PNRadarChartDataItem : NSObject
+ (instancetype)dataItemWithValue:(CGFloat)value
description:(NSString *)description;
@property (nonatomic) CGFloat value;
@property (nonatomic,copy) NSString *textDescription;
@end
... ...
//
// PNRadarChartDataItem.m
// PNChartDemo
//
// Created by Lei on 15/7/1.
// Copyright (c) 2015年 kevinzhow. All rights reserved.
//
#import "PNRadarChartDataItem.h"
@implementation PNRadarChartDataItem
+ (instancetype)dataItemWithValue:(CGFloat)value
description:(NSString *)description {
PNRadarChartDataItem *item = [PNRadarChartDataItem new];
item.value = value;
item.textDescription = description;
return item;
}
- (void)setValue:(CGFloat)value{
if (value<0) {
_value = 0;
NSLog(@"Value value can not be negative");
}
_value = value;
}
@end
... ...
... ... @@ -35,6 +35,8 @@
9FE15DF8190BB014004129F5 /* PNChartLabel.m in Sources */ = {isa = PBXBuildFile; fileRef = 9FE15DE9190BB014004129F5 /* PNChartLabel.m */; };
9FE15DFA190BB014004129F5 /* PNColor.m in Sources */ = {isa = PBXBuildFile; fileRef = 9FE15DEE190BB014004129F5 /* PNColor.m */; };
A9C75FA61A9F1DA900A54638 /* PNGenericChart.m in Sources */ = {isa = PBXBuildFile; fileRef = A9C75FA51A9F1DA900A54638 /* PNGenericChart.m */; };
ABD79D021B43700800A7C300 /* PNRadarChart.m in Sources */ = {isa = PBXBuildFile; fileRef = ABD79D011B43700800A7C300 /* PNRadarChart.m */; };
ABD79D051B43CF8000A7C300 /* PNRadarChartDataItem.m in Sources */ = {isa = PBXBuildFile; fileRef = ABD79D041B43CF8000A7C300 /* PNRadarChartDataItem.m */; };
E2C3ED5773A1409C8367CC70 /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3BA6321352024B1FBA0158B0 /* libPods.a */; };
/* End PBXBuildFile section */
... ... @@ -103,6 +105,10 @@
9FE15DEE190BB014004129F5 /* PNColor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PNColor.m; sourceTree = "<group>"; };
A9C75FA41A9F1DA900A54638 /* PNGenericChart.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PNGenericChart.h; sourceTree = "<group>"; };
A9C75FA51A9F1DA900A54638 /* PNGenericChart.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PNGenericChart.m; sourceTree = "<group>"; };
ABD79D001B43700800A7C300 /* PNRadarChart.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PNRadarChart.h; sourceTree = "<group>"; };
ABD79D011B43700800A7C300 /* PNRadarChart.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PNRadarChart.m; sourceTree = "<group>"; };
ABD79D031B43CF8000A7C300 /* PNRadarChartDataItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PNRadarChartDataItem.h; sourceTree = "<group>"; };
ABD79D041B43CF8000A7C300 /* PNRadarChartDataItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PNRadarChartDataItem.m; sourceTree = "<group>"; };
B0A0D7DDAB496680487BF1E5 /* libPods-PNChartTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-PNChartTests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
EFE4F6360943ED4001072124 /* Pods.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.debug.xcconfig; path = "Pods/Target Support Files/Pods/Pods.debug.xcconfig"; sourceTree = "<group>"; };
FB2FFF68E5C9B426137EDD03 /* Pods-PNChartTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-PNChartTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-PNChartTests/Pods-PNChartTests.debug.xcconfig"; sourceTree = "<group>"; };
... ... @@ -263,6 +269,10 @@
91177ED7198DFAC400017E27 /* PNPieChartDataItem.m */,
A9C75FA41A9F1DA900A54638 /* PNGenericChart.h */,
A9C75FA51A9F1DA900A54638 /* PNGenericChart.m */,
ABD79D001B43700800A7C300 /* PNRadarChart.h */,
ABD79D011B43700800A7C300 /* PNRadarChart.m */,
ABD79D031B43CF8000A7C300 /* PNRadarChartDataItem.h */,
ABD79D041B43CF8000A7C300 /* PNRadarChartDataItem.m */,
);
path = PNChart;
sourceTree = "<group>";
... ... @@ -434,11 +444,13 @@
files = (
91177EDE198DFAC400017E27 /* PNLineChart.m in Sources */,
9FE15DF8190BB014004129F5 /* PNChartLabel.m in Sources */,
ABD79D021B43700800A7C300 /* PNRadarChart.m in Sources */,
91177EDC198DFAC400017E27 /* PNCircleChart.m in Sources */,
9FE15DFA190BB014004129F5 /* PNColor.m in Sources */,
91177ED8198DFAC400017E27 /* PNBar.m in Sources */,
91177EE2198DFAC400017E27 /* PNLineChartDataItem.m in Sources */,
0AF7A8AF182AAEEF003645C4 /* PCChartViewController.m in Sources */,
ABD79D051B43CF8000A7C300 /* PNRadarChartDataItem.m in Sources */,
0A29228A1A423FB300A42BC4 /* PNScatterChartDataItem.m in Sources */,
A9C75FA61A9F1DA900A54638 /* PNGenericChart.m in Sources */,
91177EE6198DFAC400017E27 /* PNPieChartDataItem.m in Sources */,
... ...
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6254" systemVersion="14C109" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="9Rt-UT-IxH">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="7531" systemVersion="14D136" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="9Rt-UT-IxH">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6247"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7520"/>
</dependencies>
<scenes>
<!--PNChart-->
... ... @@ -45,13 +45,13 @@
</connections>
</switch>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Percentage" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="IKu-qh-ksi">
<rect key="frame" x="16" y="528" width="88" height="21"/>
<rect key="frame" x="16" y="528" width="121" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Show Labels" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Ifm-a9-Wkq">
<rect key="frame" x="211" y="527" width="99" height="21"/>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Show Labels" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Ifm-a9-Wkq">
<rect key="frame" x="192" y="527" width="118" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
... ... @@ -188,6 +188,26 @@
<segue destination="Tha-Wr-sPW" kind="push" identifier="scatterChart" id="V7s-JV-4Nx"/>
</connections>
</tableViewCell>
<tableViewCell contentMode="scaleToFill" selectionStyle="blue" accessoryType="disclosureIndicator" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" textLabel="Sjk-AS-XhW" style="IBUITableViewCellStyleDefault" id="bev-fA-J4Q">
<rect key="frame" x="0.0" y="196" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="bev-fA-J4Q" id="nSV-Wu-TAu">
<rect key="frame" x="0.0" y="0.0" width="287" height="43"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="left" text="RadarChart" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="Sjk-AS-XhW">
<rect key="frame" x="15" y="0.0" width="270" height="43"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="18"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
<connections>
<segue destination="Tha-Wr-sPW" kind="push" identifier="radarChart" id="4D9-t3-nzn"/>
</connections>
</tableViewCell>
</cells>
</tableViewSection>
</sections>
... ... @@ -220,6 +240,6 @@
<simulatedScreenMetrics key="destination" type="retina4"/>
</simulatedMetricsContainer>
<inferredMetricsTieBreakers>
<segue reference="V7s-JV-4Nx"/>
<segue reference="pvQ-oy-a9a"/>
</inferredMetricsTieBreakers>
</document>
... ...
... ... @@ -17,6 +17,7 @@
@property (nonatomic) PNCircleChart * circleChart;
@property (nonatomic) PNPieChart *pieChart;
@property (nonatomic) PNScatterChart *scatterChart;
@property (nonatomic) PNRadarChart *radarChart;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
... ...
... ... @@ -206,6 +206,29 @@
self.changeValueButton.hidden = YES;
[self.view addSubview:self.scatterChart];
}
else if ([self.title isEqualToString:@"Radar Chart"])
{
self.titleLabel.text = @"Radar Chart";
self.leftSwitch.hidden = NO;
self.rightSwitch.hidden = NO;
self.leftLabel.hidden = NO;
self.rightLabel.hidden = NO;
self.leftLabel.text = @"Labels Style";
self.rightLabel.text = @"Graduation";
NSArray *items = @[[PNRadarChartDataItem dataItemWithValue:3 description:@"Art"],
[PNRadarChartDataItem dataItemWithValue:2 description:@"Math"],
[PNRadarChartDataItem dataItemWithValue:8 description:@"Sports"],
[PNRadarChartDataItem dataItemWithValue:5 description:@"Literature"],
[PNRadarChartDataItem dataItemWithValue:4 description:@"Other"],
];
self.radarChart = [[PNRadarChart alloc] initWithFrame:CGRectMake(0, 135.0, SCREEN_WIDTH, 300.0) items:items valueDivider:1];
[self.radarChart strokeChart];
[self.view addSubview:self.radarChart];
}
}
... ... @@ -310,6 +333,15 @@
}
[self.pieChart strokeChart];
}
if ([self.title isEqualToString:@"Radar Chart"]){
UISwitch *showLabels = (UISwitch*) sender;
if (showLabels.on) {
self.radarChart.isShowGraduation = NO;
}else{
self.radarChart.isShowGraduation = YES;
}
[self.radarChart strokeChart];
}
}
- (IBAction)leftSwitchChanged:(id)sender {
... ... @@ -322,5 +354,14 @@
}
[self.pieChart strokeChart];
}
if ([self.title isEqualToString:@"Radar Chart"]){
UISwitch *showRelative = (UISwitch*) sender;
if (showRelative.on) {
self.radarChart.labelStyle = PNRadarChartLabelStyleHorizontal;
}else{
self.radarChart.labelStyle = PNRadarChartLabelStyleCircle;
}
[self.radarChart strokeChart];
}
}
@end
... ...
... ... @@ -45,6 +45,11 @@
//Add scatter chart
viewController.title = @"Scatter Chart";
}else if ([segue.identifier isEqualToString:@"radarChart"])
{
//Add radar chart
viewController.title = @"Radar Chart";
}
}
... ...