kevinzhow

Lots of new API for Bar Chart

//
// PNBarChart.h
// PNChartDemo
//
// Created by kevin on 11/7/13.
// Copyright (c) 2013年 kevinzhow. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "PNChartDelegate.h"
#define chartMargin 10
#define xLabelMargin 15
#define yLabelMargin 15
#define yLabelHeight 11
#define xLabelHeight 20
@interface PNBarChart : UIView
/**
* This method will call and stroke the line in animation
*/
- (void)strokeChart;
@property (nonatomic) NSArray *xLabels;
@property (nonatomic) NSArray *yLabels;
@property (nonatomic) NSArray *yValues;
@property (nonatomic) CGFloat xLabelWidth;
@property (nonatomic) int yValueMax;
@property (nonatomic) UIColor *strokeColor;
@property (nonatomic) NSArray *strokeColors;
@property (nonatomic) UIColor *barBackgroundColor;
@property (nonatomic) BOOL showLabel;
@property (nonatomic, retain) id<PNChartDelegate> delegate;
@end
//
// PNBarChart.m
// PNChartDemo
//
// Created by kevin on 11/7/13.
// Copyright (c) 2013年 kevinzhow. All rights reserved.
//
#import "PNBarChart.h"
#import "PNColor.h"
#import "PNChartLabel.h"
#import "PNBar.h"
@interface PNBarChart () {
NSMutableArray *_bars;
NSMutableArray *_labels;
}
- (UIColor *)barColorAtIndex:(NSUInteger)index;
@end
@implementation PNBarChart
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
self.backgroundColor = [UIColor whiteColor];
self.clipsToBounds = YES;
_showLabel = YES;
_barBackgroundColor = PNLightGrey;
_labels = [NSMutableArray array];
_bars = [NSMutableArray array];
}
return self;
}
- (void)setYValues:(NSArray *)yValues
{
_yValues = yValues;
[self setYLabels:yValues];
_xLabelWidth = (self.frame.size.width - chartMargin * 2) / [_yValues count];
}
- (void)setYLabels:(NSArray *)yLabels
{
NSInteger max = 0;
for (NSString *valueString in yLabels) {
NSInteger value = [valueString integerValue];
if (value > max) {
max = value;
}
}
//Min value for Y label
if (max < 5) {
max = 5;
}
_yValueMax = (int)max;
}
- (void)setXLabels:(NSArray *)xLabels
{
_xLabels = xLabels;
if (_showLabel) {
_xLabelWidth = (self.frame.size.width - chartMargin * 2) / [xLabels count];
}
}
- (void)setStrokeColor:(UIColor *)strokeColor
{
_strokeColor = strokeColor;
}
- (void)strokeChart
{
[self viewCleanupForCollection:_labels];
for (int index = 0; index < _xLabels.count; index++) {
NSString *labelText = _xLabels[index];
PNChartLabel *label = [[PNChartLabel alloc] initWithFrame:CGRectMake((index * _xLabelWidth + chartMargin), self.frame.size.height - xLabelHeight - chartMargin, _xLabelWidth, xLabelHeight)];
[label setTextAlignment:NSTextAlignmentCenter];
label.text = labelText;
[_labels addObject:label];
[self addSubview:label];
}
[self viewCleanupForCollection:_bars];
CGFloat chartCavanHeight = self.frame.size.height - chartMargin * 2 - xLabelHeight * 2;
NSInteger index = 0;
for (NSString *valueString in _yValues) {
float value = [valueString floatValue];
float grade = (float)value / (float)_yValueMax;
PNBar *bar;
if (_showLabel) {
bar = [[PNBar alloc] initWithFrame:CGRectMake((index * _xLabelWidth + chartMargin + _xLabelWidth * 0.25), self.frame.size.height - chartCavanHeight - xLabelHeight - chartMargin, _xLabelWidth * 0.5, chartCavanHeight)];
}
else {
bar = [[PNBar alloc] initWithFrame:CGRectMake((index * _xLabelWidth + chartMargin + _xLabelWidth * 0.25), self.frame.size.height - chartCavanHeight, _xLabelWidth * 0.6, chartCavanHeight)];
}
bar.backgroundColor = _barBackgroundColor;
bar.barColor = [self barColorAtIndex:index];
bar.grade = grade;
bar.tag = index;
[_bars addObject:bar];
[self addSubview:bar];
index += 1;
}
}
- (void)viewCleanupForCollection:(NSMutableArray *)array
{
if (array.count) {
[array makeObjectsPerformSelector:@selector(removeFromSuperview)];
[array removeAllObjects];
}
}
#pragma mark - Class extension methods
- (UIColor *)barColorAtIndex:(NSUInteger)index
{
if ([self.strokeColors count] == [self.yValues count]) {
return self.strokeColors[index];
}
else {
return self.strokeColor;
}
}
#pragma mark - Touch detection
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[self touchPoint:touches withEvent:event];
[super touchesBegan:touches withEvent:event];
}
- (void)touchPoint:(NSSet *)touches withEvent:(UIEvent *)event
{
//Get the point user touched
UITouch *touch = [touches anyObject];
CGPoint touchPoint = [touch locationInView:self];
UIView *subview = [self hitTest:touchPoint withEvent:nil];
if ([subview isKindOfClass:[PNBar class]] && [self.delegate respondsToSelector:@selector(userClickedOnBarCharIndex:)]) {
[self.delegate userClickedOnBarCharIndex:subview.tag];
}
}
@end
... ... @@ -16,4 +16,6 @@
@property (nonatomic) float grade;
@property (nonatomic) CAShapeLayer *chartLine;
@property (nonatomic) UIColor *barColor;
@property (nonatomic) CGFloat barRadius;
@end
... ...
... ... @@ -24,12 +24,18 @@
_chartLine.strokeEnd = 0.0;
self.clipsToBounds = YES;
[self.layer addSublayer:_chartLine];
self.layer.cornerRadius = 2.0;
self.barRadius = 2.0;
}
return self;
}
-(void)setBarRadius:(CGFloat)barRadius
{
_barRadius = barRadius;
self.layer.cornerRadius = _barRadius;
}
- (void)setGrade:(float)grade
{
... ...
//
// PNBarChart.h
// PNChartDemo
//
// Created by kevin on 11/7/13.
// Copyright (c) 2013年 kevinzhow. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "PNChartDelegate.h"
#define xLabelMargin 15
#define yLabelMargin 15
#define yLabelHeight 11
#define xLabelHeight 20
typedef NSString *(^PNyLabelFromatter)(CGFloat yLabelValue);
@interface PNBarChart : UIView
/**
* This method will call and stroke the line in animation
*/
- (void)strokeChart;
@property (nonatomic) NSArray *xLabels;
@property (nonatomic) NSArray *yLabels;
@property (nonatomic) NSArray *yValues;
@property (nonatomic) CGFloat xLabelWidth;
@property (nonatomic) int yValueMax;
@property (nonatomic) UIColor *strokeColor;
@property (nonatomic) NSArray *strokeColors;
/*
chartMargin changes chart margin
*/
@property (nonatomic) CGFloat yChartLabelWidth;
/*
yLabelFormatter will format the ylabel text
*/
@property (copy) PNyLabelFromatter yLabelFormatter;
/*
chartMargin changes chart margin
*/
@property (nonatomic) CGFloat chartMargin;
/*
showLabelDefines if the Labels should be deplay
*/
@property (nonatomic) BOOL showLabel;
/*
showChartBorder if the chart border Line should be deplay
*/
@property (nonatomic) BOOL showChartBorder;
/*
chartBottomLine the Line at the chart bottom
*/
@property (nonatomic) CAShapeLayer * chartBottomLine;
/*
chartLeftLine the Line at the chart left
*/
@property (nonatomic) CAShapeLayer * chartLeftLine;
/*
barRadius changes the bar corner radius
*/
@property (nonatomic) CGFloat barRadius;
/*
barWidth changes the width of the bar
*/
@property (nonatomic) CGFloat barWidth;
/*
labelMarginTop changes the width of the bar
*/
@property (nonatomic) CGFloat labelMarginTop;
/*
barBackgroundColor changes the bar background color
*/
@property (nonatomic) UIColor * barBackgroundColor;
/*
labelTextColor changes the bar label text color
*/
@property (nonatomic) UIColor * labelTextColor;
/*
labelFont changes the bar label font
*/
@property (nonatomic) UIFont * labelFont;
/*
xLabelSkip define the label skip number
*/
@property (nonatomic) NSInteger xLabelSkip;
/*
yLabelSum define the label skip number
*/
@property (nonatomic) NSInteger yLabelSum;
/*
yMaxValue define the max value of the chart
*/
@property (nonatomic) CGFloat yMaxValue;
@property (nonatomic, retain) id<PNChartDelegate> delegate;
@end
... ...
//
// PNBarChart.m
// PNChartDemo
//
// Created by kevin on 11/7/13.
// Copyright (c) 2013年 kevinzhow. All rights reserved.
//
#import "PNBarChart.h"
#import "PNColor.h"
#import "PNChartLabel.h"
#import "PNBar.h"
@interface PNBarChart () {
NSMutableArray *_bars;
NSMutableArray *_labels;
}
- (UIColor *)barColorAtIndex:(NSUInteger)index;
@end
@implementation PNBarChart
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
self.backgroundColor = [UIColor whiteColor];
self.clipsToBounds = YES;
_showLabel = YES;
_barBackgroundColor = PNLightGrey;
_labelTextColor = [UIColor grayColor];
_labelFont = [UIFont systemFontOfSize:11.0f];
_labels = [NSMutableArray array];
_bars = [NSMutableArray array];
_xLabelSkip = 1;
_yLabelSum = 4;
_labelMarginTop = 0;
_chartMargin = 15.0;
_barRadius = 2.0;
_showChartBorder = NO;
_yChartLabelWidth = 18;
}
return self;
}
- (void)setYValues:(NSArray *)yValues
{
_yValues = yValues;
if (_yMaxValue) {
_yValueMax = _yMaxValue;
}else{
[self getYValueMax:yValues];
}
_xLabelWidth = (self.frame.size.width - _chartMargin * 2) / [_yValues count];
}
- (void)getYValueMax:(NSArray *)yLabels
{
NSInteger max = 0;
for (NSString *valueString in yLabels) {
NSInteger value = [valueString integerValue];
if (value > max) {
max = value;
}
}
//Min value for Y label
if (max < 5) {
max = 5;
}
_yValueMax = (int)max;
}
- (void)setYLabels:(NSArray *)yLabels
{
}
- (void)setXLabels:(NSArray *)xLabels
{
_xLabels = xLabels;
if (_showLabel) {
_xLabelWidth = (self.frame.size.width - _chartMargin * 2) / [xLabels count];
}
}
- (void)setStrokeColor:(UIColor *)strokeColor
{
_strokeColor = strokeColor;
}
- (void)strokeChart
{
[self viewCleanupForCollection:_labels];
//Add Labels
if (_showLabel) {
//Add x labels
int labelAddCount = 0;
for (int index = 0; index < _xLabels.count; index++) {
labelAddCount += 1;
if (labelAddCount == _xLabelSkip) {
NSString *labelText = _xLabels[index];
PNChartLabel * label = [[PNChartLabel alloc] initWithFrame:CGRectZero];
label.font = _labelFont;
label.textColor = _labelTextColor;
[label setTextAlignment:NSTextAlignmentCenter];
label.text = labelText;
NSLog(@"Label text is %@",labelText);
[label sizeToFit];
CGFloat labelXPosition;
if (label.frame.size.width < _xLabelWidth) {
labelXPosition = (index * _xLabelWidth + _chartMargin + _xLabelWidth /2.0 );
}else{
labelXPosition = (index * _xLabelWidth + _chartMargin + label.frame.size.width /2.0 );
}
label.center = CGPointMake(labelXPosition,
self.frame.size.height - xLabelHeight - _chartMargin + label.frame.size.height /2.0 + _labelMarginTop);
labelAddCount = 0;
[_labels addObject:label];
[self addSubview:label];
}
}
//Add y labels
float yLabelSectionHeight = (self.frame.size.height - _chartMargin * 2 - xLabelHeight) / _yLabelSum;
for (int index = 0; index < _yLabelSum; index++) {
NSString *labelText = _yLabelFormatter((float)_yValueMax * ( (_yLabelSum - index) / (float)_yLabelSum ));
PNChartLabel * label = [[PNChartLabel alloc] initWithFrame:CGRectMake(0,
yLabelSectionHeight * index + _chartMargin - yLabelHeight/2.0,
_yChartLabelWidth,
yLabelHeight)];
label.font = _labelFont;
label.textColor = _labelTextColor;
[label setTextAlignment:NSTextAlignmentRight];
label.text = labelText;
[_labels addObject:label];
[self addSubview:label];
}
}
[self viewCleanupForCollection:_bars];
//Add bars
CGFloat chartCavanHeight = self.frame.size.height - _chartMargin * 2 - xLabelHeight;
NSInteger index = 0;
for (NSString *valueString in _yValues) {
float value = [valueString floatValue];
float grade = (float)value / (float)_yValueMax;
PNBar *bar;
CGFloat barWidth;
CGFloat barXPosition;
if (_barWidth) {
barWidth = _barWidth;
barXPosition = index * _xLabelWidth + _chartMargin + _xLabelWidth /2.0 - _barWidth /2.0;
}else{
barXPosition = index * _xLabelWidth + _chartMargin + _xLabelWidth * 0.25;
if (_showLabel) {
barWidth = _xLabelWidth * 0.5;
}
else {
barWidth = _xLabelWidth * 0.6;
}
}
bar = [[PNBar alloc] initWithFrame:CGRectMake(barXPosition, //Bar X position
self.frame.size.height - chartCavanHeight - xLabelHeight - _chartMargin, //Bar Y position
barWidth, // Bar witdh
chartCavanHeight)]; //Bar height
//Change Bar Radius
bar.barRadius = _barRadius;
//Change Bar Background color
bar.backgroundColor = _barBackgroundColor;
//Bar StrokColor First
if (self.strokeColor) {
bar.barColor = self.strokeColor;
}else{
bar.barColor = [self barColorAtIndex:index];
}
//Height Of Bar
bar.grade = grade;
//For Click Index
bar.tag = index;
[_bars addObject:bar];
[self addSubview:bar];
index += 1;
}
//Add chart border lines
if (_showChartBorder) {
_chartBottomLine = [CAShapeLayer layer];
_chartBottomLine.lineCap = kCALineCapButt;
_chartBottomLine.fillColor = [[UIColor whiteColor] CGColor];
_chartBottomLine.lineWidth = 1.0;
_chartBottomLine.strokeEnd = 0.0;
UIBezierPath *progressline = [UIBezierPath bezierPath];
[progressline moveToPoint:CGPointMake(_chartMargin, self.frame.size.height - xLabelHeight - _chartMargin)];
[progressline addLineToPoint:CGPointMake(self.frame.size.width - _chartMargin, self.frame.size.height - xLabelHeight - _chartMargin)];
[progressline setLineWidth:1.0];
[progressline setLineCapStyle:kCGLineCapSquare];
_chartBottomLine.path = progressline.CGPath;
_chartBottomLine.strokeColor = PNLightGrey.CGColor;
CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
pathAnimation.duration = 0.5;
pathAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
pathAnimation.fromValue = [NSNumber numberWithFloat:0.0f];
pathAnimation.toValue = [NSNumber numberWithFloat:1.0f];
[_chartBottomLine addAnimation:pathAnimation forKey:@"strokeEndAnimation"];
_chartBottomLine.strokeEnd = 1.0;
[self.layer addSublayer:_chartBottomLine];
//Add left Chart Line
_chartLeftLine = [CAShapeLayer layer];
_chartLeftLine.lineCap = kCALineCapButt;
_chartLeftLine.fillColor = [[UIColor whiteColor] CGColor];
_chartLeftLine.lineWidth = 1.0;
_chartLeftLine.strokeEnd = 0.0;
UIBezierPath *progressLeftline = [UIBezierPath bezierPath];
[progressLeftline moveToPoint:CGPointMake(_chartMargin, self.frame.size.height - xLabelHeight - _chartMargin)];
[progressLeftline addLineToPoint:CGPointMake(_chartMargin, _chartMargin)];
[progressLeftline setLineWidth:1.0];
[progressLeftline setLineCapStyle:kCGLineCapSquare];
_chartLeftLine.path = progressLeftline.CGPath;
_chartLeftLine.strokeColor = PNLightGrey.CGColor;
CABasicAnimation *pathLeftAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
pathLeftAnimation.duration = 0.5;
pathLeftAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
pathLeftAnimation.fromValue = [NSNumber numberWithFloat:0.0f];
pathLeftAnimation.toValue = [NSNumber numberWithFloat:1.0f];
[_chartLeftLine addAnimation:pathLeftAnimation forKey:@"strokeEndAnimation"];
_chartLeftLine.strokeEnd = 1.0;
[self.layer addSublayer:_chartLeftLine];
}
}
- (void)viewCleanupForCollection:(NSMutableArray *)array
{
if (array.count) {
[array makeObjectsPerformSelector:@selector(removeFromSuperview)];
[array removeAllObjects];
}
}
#pragma mark - Class extension methods
- (UIColor *)barColorAtIndex:(NSUInteger)index
{
if ([self.strokeColors count] == [self.yValues count]) {
return self.strokeColors[index];
}
else {
return self.strokeColor;
}
}
#pragma mark - Touch detection
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[self touchPoint:touches withEvent:event];
[super touchesBegan:touches withEvent:event];
}
- (void)touchPoint:(NSSet *)touches withEvent:(UIEvent *)event
{
//Get the point user touched
UITouch *touch = [touches anyObject];
CGPoint touchPoint = [touch locationInView:self];
UIView *subview = [self hitTest:touchPoint withEvent:nil];
if ([subview isKindOfClass:[PNBar class]] && [self.delegate respondsToSelector:@selector(userClickedOnBarCharIndex:)]) {
[self.delegate userClickedOnBarCharIndex:subview.tag];
}
}
@end
... ...
... ... @@ -17,13 +17,10 @@
if (self) {
// Initialization code
[self setLineBreakMode:NSLineBreakByWordWrapping];
[self setMinimumScaleFactor:11.0f];
[self setNumberOfLines:0];
[self setFont:[UIFont boldSystemFontOfSize:11.0f]];
[self setTextColor:PNDeepGrey];
self.backgroundColor = [UIColor clearColor];
[self setTextAlignment:NSTextAlignmentLeft];
[self setTextAlignment:NSTextAlignmentCenter];
self.userInteractionEnabled = YES;
}
... ...
... ... @@ -11,4 +11,5 @@
+ (PNLineChartDataItem *)dataItemWithY:(CGFloat)y;
@property (readonly) CGFloat y; // should be within the y range
@end
... ...
... ... @@ -22,15 +22,15 @@
0AF7A891182AA9F6003645C4 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 0AF7A88F182AA9F6003645C4 /* InfoPlist.strings */; };
0AF7A893182AA9F6003645C4 /* PNChartDemoTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 0AF7A892182AA9F6003645C4 /* PNChartDemoTests.m */; };
0AF7A8AF182AAEEF003645C4 /* PCChartViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 0AF7A8AE182AAEEF003645C4 /* PCChartViewController.m */; };
9F02DE5018C05E9A00CDED9A /* PNBar.m in Sources */ = {isa = PBXBuildFile; fileRef = 9F02DE3F18C05E9A00CDED9A /* PNBar.m */; };
9F02DE5118C05E9A00CDED9A /* PNBarChart.m in Sources */ = {isa = PBXBuildFile; fileRef = 9F02DE4118C05E9A00CDED9A /* PNBarChart.m */; };
9F02DE5218C05E9A00CDED9A /* PNChartLabel.m in Sources */ = {isa = PBXBuildFile; fileRef = 9F02DE4518C05E9A00CDED9A /* PNChartLabel.m */; };
9F02DE5318C05E9A00CDED9A /* PNCircleChart.m in Sources */ = {isa = PBXBuildFile; fileRef = 9F02DE4718C05E9A00CDED9A /* PNCircleChart.m */; };
9F02DE5418C05E9A00CDED9A /* PNColor.m in Sources */ = {isa = PBXBuildFile; fileRef = 9F02DE4918C05E9A00CDED9A /* PNColor.m */; };
9F02DE5518C05E9A00CDED9A /* PNLineChart.m in Sources */ = {isa = PBXBuildFile; fileRef = 9F02DE4B18C05E9A00CDED9A /* PNLineChart.m */; };
9F02DE5618C05E9A00CDED9A /* PNLineChartData.m in Sources */ = {isa = PBXBuildFile; fileRef = 9F02DE4D18C05E9A00CDED9A /* PNLineChartData.m */; };
9F02DE5718C05E9A00CDED9A /* PNLineChartDataItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 9F02DE4F18C05E9A00CDED9A /* PNLineChartDataItem.m */; };
9FA23B10184A5944002DBBA4 /* PCChartsTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9FA23B0F184A5944002DBBA4 /* PCChartsTableViewController.m */; };
9FE15DF6190BB014004129F5 /* PNBar.m in Sources */ = {isa = PBXBuildFile; fileRef = 9FE15DE3190BB014004129F5 /* PNBar.m */; };
9FE15DF7190BB014004129F5 /* PNBarChart.m in Sources */ = {isa = PBXBuildFile; fileRef = 9FE15DE5190BB014004129F5 /* PNBarChart.m */; };
9FE15DF8190BB014004129F5 /* PNChartLabel.m in Sources */ = {isa = PBXBuildFile; fileRef = 9FE15DE9190BB014004129F5 /* PNChartLabel.m */; };
9FE15DF9190BB014004129F5 /* PNCircleChart.m in Sources */ = {isa = PBXBuildFile; fileRef = 9FE15DEC190BB014004129F5 /* PNCircleChart.m */; };
9FE15DFA190BB014004129F5 /* PNColor.m in Sources */ = {isa = PBXBuildFile; fileRef = 9FE15DEE190BB014004129F5 /* PNColor.m */; };
9FE15DFB190BB014004129F5 /* PNLineChart.m in Sources */ = {isa = PBXBuildFile; fileRef = 9FE15DF1190BB014004129F5 /* PNLineChart.m */; };
9FE15DFC190BB014004129F5 /* PNLineChartData.m in Sources */ = {isa = PBXBuildFile; fileRef = 9FE15DF3190BB014004129F5 /* PNLineChartData.m */; };
9FE15DFD190BB014004129F5 /* PNLineChartDataItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 9FE15DF5190BB014004129F5 /* PNLineChartDataItem.m */; };
E2C3ED5773A1409C8367CC70 /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3BA6321352024B1FBA0158B0 /* libPods.a */; };
/* End PBXBuildFile section */
... ... @@ -66,26 +66,26 @@
0AF7A8AD182AAEEF003645C4 /* PCChartViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PCChartViewController.h; sourceTree = "<group>"; };
0AF7A8AE182AAEEF003645C4 /* PCChartViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PCChartViewController.m; sourceTree = "<group>"; };
3BA6321352024B1FBA0158B0 /* libPods.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPods.a; sourceTree = BUILT_PRODUCTS_DIR; };
9F02DE3E18C05E9A00CDED9A /* PNBar.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PNBar.h; sourceTree = "<group>"; };
9F02DE3F18C05E9A00CDED9A /* PNBar.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PNBar.m; sourceTree = "<group>"; };
9F02DE4018C05E9A00CDED9A /* PNBarChart.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PNBarChart.h; sourceTree = "<group>"; };
9F02DE4118C05E9A00CDED9A /* PNBarChart.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PNBarChart.m; sourceTree = "<group>"; };
9F02DE4218C05E9A00CDED9A /* PNChart.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PNChart.h; sourceTree = "<group>"; };
9F02DE4318C05E9A00CDED9A /* PNChartDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PNChartDelegate.h; sourceTree = "<group>"; };
9F02DE4418C05E9A00CDED9A /* PNChartLabel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PNChartLabel.h; sourceTree = "<group>"; };
9F02DE4518C05E9A00CDED9A /* PNChartLabel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PNChartLabel.m; sourceTree = "<group>"; };
9F02DE4618C05E9A00CDED9A /* PNCircleChart.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PNCircleChart.h; sourceTree = "<group>"; };
9F02DE4718C05E9A00CDED9A /* PNCircleChart.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PNCircleChart.m; sourceTree = "<group>"; };
9F02DE4818C05E9A00CDED9A /* PNColor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PNColor.h; sourceTree = "<group>"; };
9F02DE4918C05E9A00CDED9A /* PNColor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PNColor.m; sourceTree = "<group>"; };
9F02DE4A18C05E9A00CDED9A /* PNLineChart.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PNLineChart.h; sourceTree = "<group>"; };
9F02DE4B18C05E9A00CDED9A /* PNLineChart.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PNLineChart.m; sourceTree = "<group>"; };
9F02DE4C18C05E9A00CDED9A /* PNLineChartData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PNLineChartData.h; sourceTree = "<group>"; };
9F02DE4D18C05E9A00CDED9A /* PNLineChartData.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PNLineChartData.m; sourceTree = "<group>"; };
9F02DE4E18C05E9A00CDED9A /* PNLineChartDataItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PNLineChartDataItem.h; sourceTree = "<group>"; };
9F02DE4F18C05E9A00CDED9A /* PNLineChartDataItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PNLineChartDataItem.m; sourceTree = "<group>"; };
9FA23B0E184A5944002DBBA4 /* PCChartsTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PCChartsTableViewController.h; sourceTree = "<group>"; };
9FA23B0F184A5944002DBBA4 /* PCChartsTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PCChartsTableViewController.m; sourceTree = "<group>"; };
9FE15DE2190BB014004129F5 /* PNBar.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PNBar.h; sourceTree = "<group>"; };
9FE15DE3190BB014004129F5 /* PNBar.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PNBar.m; sourceTree = "<group>"; };
9FE15DE4190BB014004129F5 /* PNBarChart.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PNBarChart.h; sourceTree = "<group>"; };
9FE15DE5190BB014004129F5 /* PNBarChart.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PNBarChart.m; sourceTree = "<group>"; };
9FE15DE6190BB014004129F5 /* PNChart.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PNChart.h; sourceTree = "<group>"; };
9FE15DE7190BB014004129F5 /* PNChartDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PNChartDelegate.h; sourceTree = "<group>"; };
9FE15DE8190BB014004129F5 /* PNChartLabel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PNChartLabel.h; sourceTree = "<group>"; };
9FE15DE9190BB014004129F5 /* PNChartLabel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PNChartLabel.m; sourceTree = "<group>"; };
9FE15DEB190BB014004129F5 /* PNCircleChart.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PNCircleChart.h; sourceTree = "<group>"; };
9FE15DEC190BB014004129F5 /* PNCircleChart.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PNCircleChart.m; sourceTree = "<group>"; };
9FE15DED190BB014004129F5 /* PNColor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PNColor.h; sourceTree = "<group>"; };
9FE15DEE190BB014004129F5 /* PNColor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PNColor.m; sourceTree = "<group>"; };
9FE15DF0190BB014004129F5 /* PNLineChart.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PNLineChart.h; sourceTree = "<group>"; };
9FE15DF1190BB014004129F5 /* PNLineChart.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PNLineChart.m; sourceTree = "<group>"; };
9FE15DF2190BB014004129F5 /* PNLineChartData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PNLineChartData.h; sourceTree = "<group>"; };
9FE15DF3190BB014004129F5 /* PNLineChartData.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PNLineChartData.m; sourceTree = "<group>"; };
9FE15DF4190BB014004129F5 /* PNLineChartDataItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PNLineChartDataItem.h; sourceTree = "<group>"; };
9FE15DF5190BB014004129F5 /* PNLineChartDataItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PNLineChartDataItem.m; sourceTree = "<group>"; };
F161CF4F7A8C4BD2AB65FB4F /* Pods.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.xcconfig; path = Pods/Pods.xcconfig; sourceTree = "<group>"; };
/* End PBXFileReference section */
... ... @@ -118,7 +118,7 @@
0AF7A85B182AA9F5003645C4 = {
isa = PBXGroup;
children = (
9F02DE3D18C05E9A00CDED9A /* PNChart */,
9FE15DE0190BB014004129F5 /* PNChart */,
0AF7A86D182AA9F6003645C4 /* PNChartDemo */,
0AF7A88C182AA9F6003645C4 /* PNChartDemoTests */,
0AF7A866182AA9F6003645C4 /* Frameworks */,
... ... @@ -202,31 +202,55 @@
name = PCChartViewController;
sourceTree = "<group>";
};
9F02DE3D18C05E9A00CDED9A /* PNChart */ = {
9FE15DE0190BB014004129F5 /* PNChart */ = {
isa = PBXGroup;
children = (
9F02DE3E18C05E9A00CDED9A /* PNBar.h */,
9F02DE3F18C05E9A00CDED9A /* PNBar.m */,
9F02DE4018C05E9A00CDED9A /* PNBarChart.h */,
9F02DE4118C05E9A00CDED9A /* PNBarChart.m */,
9F02DE4218C05E9A00CDED9A /* PNChart.h */,
9F02DE4318C05E9A00CDED9A /* PNChartDelegate.h */,
9F02DE4418C05E9A00CDED9A /* PNChartLabel.h */,
9F02DE4518C05E9A00CDED9A /* PNChartLabel.m */,
9F02DE4618C05E9A00CDED9A /* PNCircleChart.h */,
9F02DE4718C05E9A00CDED9A /* PNCircleChart.m */,
9F02DE4818C05E9A00CDED9A /* PNColor.h */,
9F02DE4918C05E9A00CDED9A /* PNColor.m */,
9F02DE4A18C05E9A00CDED9A /* PNLineChart.h */,
9F02DE4B18C05E9A00CDED9A /* PNLineChart.m */,
9F02DE4C18C05E9A00CDED9A /* PNLineChartData.h */,
9F02DE4D18C05E9A00CDED9A /* PNLineChartData.m */,
9F02DE4E18C05E9A00CDED9A /* PNLineChartDataItem.h */,
9F02DE4F18C05E9A00CDED9A /* PNLineChartDataItem.m */,
9FE15DE1190BB014004129F5 /* PNBarChart */,
9FE15DE6190BB014004129F5 /* PNChart.h */,
9FE15DE7190BB014004129F5 /* PNChartDelegate.h */,
9FE15DE8190BB014004129F5 /* PNChartLabel.h */,
9FE15DE9190BB014004129F5 /* PNChartLabel.m */,
9FE15DEA190BB014004129F5 /* PNCircleChart */,
9FE15DED190BB014004129F5 /* PNColor.h */,
9FE15DEE190BB014004129F5 /* PNColor.m */,
9FE15DEF190BB014004129F5 /* PNLineChart */,
);
path = PNChart;
sourceTree = "<group>";
};
9FE15DE1190BB014004129F5 /* PNBarChart */ = {
isa = PBXGroup;
children = (
9FE15DE2190BB014004129F5 /* PNBar.h */,
9FE15DE3190BB014004129F5 /* PNBar.m */,
9FE15DE4190BB014004129F5 /* PNBarChart.h */,
9FE15DE5190BB014004129F5 /* PNBarChart.m */,
);
path = PNBarChart;
sourceTree = "<group>";
};
9FE15DEA190BB014004129F5 /* PNCircleChart */ = {
isa = PBXGroup;
children = (
9FE15DEB190BB014004129F5 /* PNCircleChart.h */,
9FE15DEC190BB014004129F5 /* PNCircleChart.m */,
);
path = PNCircleChart;
sourceTree = "<group>";
};
9FE15DEF190BB014004129F5 /* PNLineChart */ = {
isa = PBXGroup;
children = (
9FE15DF0190BB014004129F5 /* PNLineChart.h */,
9FE15DF1190BB014004129F5 /* PNLineChart.m */,
9FE15DF2190BB014004129F5 /* PNLineChartData.h */,
9FE15DF3190BB014004129F5 /* PNLineChartData.m */,
9FE15DF4190BB014004129F5 /* PNLineChartDataItem.h */,
9FE15DF5190BB014004129F5 /* PNLineChartDataItem.m */,
);
path = PNLineChart;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
... ... @@ -360,17 +384,17 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
9F02DE5518C05E9A00CDED9A /* PNLineChart.m in Sources */,
9F02DE5218C05E9A00CDED9A /* PNChartLabel.m in Sources */,
9F02DE5418C05E9A00CDED9A /* PNColor.m in Sources */,
9F02DE5018C05E9A00CDED9A /* PNBar.m in Sources */,
9FE15DFB190BB014004129F5 /* PNLineChart.m in Sources */,
9FE15DF8190BB014004129F5 /* PNChartLabel.m in Sources */,
9FE15DFA190BB014004129F5 /* PNColor.m in Sources */,
9FE15DF6190BB014004129F5 /* PNBar.m in Sources */,
0AF7A8AF182AAEEF003645C4 /* PCChartViewController.m in Sources */,
9F02DE5718C05E9A00CDED9A /* PNLineChartDataItem.m in Sources */,
9FE15DFD190BB014004129F5 /* PNLineChartDataItem.m in Sources */,
9FA23B10184A5944002DBBA4 /* PCChartsTableViewController.m in Sources */,
9F02DE5318C05E9A00CDED9A /* PNCircleChart.m in Sources */,
9FE15DF9190BB014004129F5 /* PNCircleChart.m in Sources */,
0AF7A874182AA9F6003645C4 /* main.m in Sources */,
9F02DE5618C05E9A00CDED9A /* PNLineChartData.m in Sources */,
9F02DE5118C05E9A00CDED9A /* PNBarChart.m in Sources */,
9FE15DFC190BB014004129F5 /* PNLineChartData.m in Sources */,
9FE15DF7190BB014004129F5 /* PNBarChart.m in Sources */,
0AF7A878182AA9F6003645C4 /* PCAppDelegate.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
... ...
... ... @@ -106,6 +106,12 @@
PNBarChart * barChart = [[PNBarChart alloc] initWithFrame:CGRectMake(0, 135.0, SCREEN_WIDTH, 200.0)];
barChart.backgroundColor = [UIColor clearColor];
barChart.yLabelFormatter = ^(CGFloat yValue){
CGFloat yValueParsed = yValue;
NSString * labelText = [NSString stringWithFormat:@"%1.f",yValueParsed];
return labelText;
};
barChart.labelMarginTop = 5.0;
[barChart setXLabels:@[@"SEP 1",@"SEP 2",@"SEP 3",@"SEP 4",@"SEP 5",@"SEP 6",@"SEP 7"]];
[barChart setYValues:@[@1,@24,@12,@18,@30,@10,@21]];
[barChart setStrokeColors:@[PNGreen,PNGreen,PNRed,PNGreen,PNGreen,PNYellow,PNGreen]];
... ... @@ -129,18 +135,13 @@
circleChartLabel.font = [UIFont fontWithName:@"Avenir-Medium" size:23.0];
circleChartLabel.textAlignment = NSTextAlignmentCenter;
PNCircleChart * circleChart = [[PNCircleChart alloc] initWithFrame:CGRectMake(0, 80.0, SCREEN_WIDTH, 100.0) andTotal:[NSNumber numberWithInt:100] andCurrent:[NSNumber numberWithInt:60] andClockwise:YES andShadow:NO];
PNCircleChart * circleChart = [[PNCircleChart alloc] initWithFrame:CGRectMake(0, 80.0, SCREEN_WIDTH, 100.0) andTotal:[NSNumber numberWithInt:100] andCurrent:[NSNumber numberWithInt:60] andClockwise:YES andShadow:YES];
circleChart.backgroundColor = [UIColor clearColor];
[circleChart setStrokeColor:PNGreen];
[circleChart strokeChart];
PNCircleChart * circleChart2 = [[PNCircleChart alloc] initWithFrame:CGRectMake(0, 80.0, SCREEN_WIDTH, 100.0) andTotal:[NSNumber numberWithInt:100] andCurrent:[NSNumber numberWithInt:90] andClockwise:YES andShadow:YES];
circleChart2.backgroundColor = [UIColor clearColor];
[circleChart2 setStrokeColor:PNBlue];
[circleChart2 strokeChart];
[viewController.view addSubview:circleChartLabel];
[viewController.view addSubview:circleChart2];
[viewController.view addSubview:circleChart];
viewController.title = @"Circle Chart";
... ...