diff --git a/JHChartDemo.xcodeproj/project.xcworkspace/xcuserdata/frank.xcuserdatad/UserInterfaceState.xcuserstate b/JHChartDemo.xcodeproj/project.xcworkspace/xcuserdata/frank.xcuserdatad/UserInterfaceState.xcuserstate
new file mode 100644
index 0000000..aee3401
Binary files /dev/null and b/JHChartDemo.xcodeproj/project.xcworkspace/xcuserdata/frank.xcuserdatad/UserInterfaceState.xcuserstate differ
diff --git a/JHChartDemo.xcodeproj/xcuserdata/frank.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/JHChartDemo.xcodeproj/xcuserdata/frank.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
new file mode 100644
index 0000000..8f94031
--- /dev/null
+++ b/JHChartDemo.xcodeproj/xcuserdata/frank.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
+
+
diff --git a/JHChartDemo.xcodeproj/xcuserdata/frank.xcuserdatad/xcschemes/xcschememanagement.plist b/JHChartDemo.xcodeproj/xcuserdata/frank.xcuserdatad/xcschemes/xcschememanagement.plist
new file mode 100644
index 0000000..d40c537
--- /dev/null
+++ b/JHChartDemo.xcodeproj/xcuserdata/frank.xcuserdatad/xcschemes/xcschememanagement.plist
@@ -0,0 +1,14 @@
+
+
+
+
+ SchemeUserState
+
+ JHChartDemo.xcscheme
+
+ orderHint
+ 0
+
+
+
+
diff --git a/JHChartDemo/JHChart/JHLineChart.h b/JHChartDemo/JHChart/JHLineChart.h
index e2cc274..30dec62 100644
--- a/JHChartDemo/JHChart/JHLineChart.h
+++ b/JHChartDemo/JHChart/JHLineChart.h
@@ -56,6 +56,11 @@ typedef NS_ENUM(NSInteger,JHLineChartQuadrantType){
@interface JHLineChart :JHChart
+
+/**
+ 折线图上部描述文字(设置顶部偏移量之后才可显示)
+ */
+@property (nonatomic, strong)NSString * topDesc;
/**
* X axis scale data of a broken line graph, the proposed use of NSNumber or the number of strings
*/
@@ -172,7 +177,10 @@ typedef NS_ENUM(NSInteger,JHLineChartQuadrantType){
*/
@property (nonatomic,assign) BOOL showYLine ;
-
+/**
+ * whether this chart level lines is dottedLine or not.Default is YES
+ */
+@property (nonatomic, assign) BOOL leavelLineIsDotted;
/**
* whether this chart shows the Y level lines or not.Default is NO
*/
diff --git a/JHChartDemo/JHChart/JHLineChart.m b/JHChartDemo/JHChart/JHLineChart.m
index 5d9a610..f70956f 100644
--- a/JHChartDemo/JHChart/JHLineChart.m
+++ b/JHChartDemo/JHChart/JHLineChart.m
@@ -54,6 +54,7 @@ -(instancetype)initWithFrame:(CGRect)frame andLineChartType:(JHLineChartType)lin
_layerArr = [NSMutableArray array];
_showYLine = YES;
_showYLevelLine = NO;
+ _leavelLineIsDotted = YES;
_showValueLeadingLine = YES;
_valueFontSize = 8.0;
_showPointDescription = YES;
@@ -452,6 +453,7 @@ - (void)drawXAndYLineWithContext:(CGContextRef)context{
label.text = [NSString stringWithFormat:@"%@",_xLineDataArr[i]];
label.font = [UIFont systemFontOfSize:self.xDescTextFontSize];
label.numberOfLines = 0;
+ label.textColor = _xAndYNumberColor;
label.transform = CGAffineTransformRotate(label.transform, _xDescriptionAngle);
[self addSubview:label];
@@ -483,7 +485,7 @@ - (void)drawXAndYLineWithContext:(CGContextRef)context{
CGFloat len = [self sizeOfStringWithMaxSize:CGSizeMake(CGFLOAT_MAX, 30) textFont:self.yDescTextFontSize aimString:leftArray[i]].width;
CGFloat hei = [self sizeOfStringWithMaxSize:CGSizeMake(CGFLOAT_MAX, 30) textFont:self.yDescTextFontSize aimString:leftArray[i]].height;
if (_showYLevelLine) {
- [self drawLineWithContext:context andStarPoint:p andEndPoint:P_M(self.contentInsets.left+_xLength, p.y) andIsDottedLine:YES andColor:self.xAndYLineColor];
+ [self drawLineWithContext:context andStarPoint:p andEndPoint:P_M(self.contentInsets.left+_xLength, p.y) andIsDottedLine:self.leavelLineIsDotted andColor:self.xAndYLineColor];
}else{
[self drawLineWithContext:context andStarPoint:p andEndPoint:P_M(p.x+3, p.y) andIsDottedLine:NO andColor:self.xAndYLineColor];
@@ -510,7 +512,7 @@ - (void)drawXAndYLineWithContext:(CGContextRef)context{
CGFloat len = [self sizeOfStringWithMaxSize:CGSizeMake(CGFLOAT_MAX, 30) textFont:self.yDescTextFontSize aimString:_yLineDataArr[i]].width;
CGFloat hei = [self sizeOfStringWithMaxSize:CGSizeMake(CGFLOAT_MAX, 30) textFont:self.yDescTextFontSize aimString:_yLineDataArr[i]].height;
if (_showYLevelLine) {
- [self drawLineWithContext:context andStarPoint:p andEndPoint:P_M(self.contentInsets.left+_xLength, p.y) andIsDottedLine:YES andColor:self.xAndYLineColor];
+ [self drawLineWithContext:context andStarPoint:p andEndPoint:P_M(self.contentInsets.left+_xLength, p.y) andIsDottedLine:self.leavelLineIsDotted andColor:self.xAndYLineColor];
}else{
[self drawLineWithContext:context andStarPoint:p andEndPoint:P_M(p.x+3, p.y) andIsDottedLine:NO andColor:self.xAndYLineColor];
@@ -527,7 +529,7 @@ - (void)drawXAndYLineWithContext:(CGContextRef)context{
[self drawLineWithContext:context andStarPoint:P_M(self.contentInsets.left, self.chartOrigin.y) andEndPoint:P_M(self.contentInsets.left+_xLength, self.chartOrigin.y) andIsDottedLine:NO andColor:self.xAndYLineColor];
if (_showYLine) {
- [self drawLineWithContext:context andStarPoint:self.chartOrigin andEndPoint:P_M(self.chartOrigin.x,self.chartOrigin.y-_yLength) andIsDottedLine:NO andColor:self.xAndYLineColor];
+ [self drawLineWithContext:context andStarPoint:self.chartOrigin andEndPoint:P_M(self.chartOrigin.x,self.chartOrigin.y-_yLength) andIsDottedLine:self.leavelLineIsDotted andColor:self.xAndYLineColor];
}
if (_xLineDataArr.count == 2) {
@@ -580,7 +582,7 @@ - (void)drawXAndYLineWithContext:(CGContextRef)context{
CGFloat len = [self sizeOfStringWithMaxSize:CGSizeMake(CGFLOAT_MAX, 30) textFont:self.yDescTextFontSize aimString:_yLineDataArr[i]].width;
CGFloat hei = [self sizeOfStringWithMaxSize:CGSizeMake(CGFLOAT_MAX, 30) textFont:self.yDescTextFontSize aimString:_yLineDataArr[i]].height;
if (_showYLevelLine) {
- [self drawLineWithContext:context andStarPoint:P_M(self.contentInsets.left, p.y) andEndPoint:P_M(self.contentInsets.left+_xLength, p.y) andIsDottedLine:YES andColor:self.xAndYLineColor];
+ [self drawLineWithContext:context andStarPoint:P_M(self.contentInsets.left, p.y) andEndPoint:P_M(self.contentInsets.left+_xLength, p.y) andIsDottedLine:self.leavelLineIsDotted andColor:self.xAndYLineColor];
}else
[self drawLineWithContext:context andStarPoint:p andEndPoint:P_M(p.x+3, p.y) andIsDottedLine:NO andColor:self.xAndYLineColor];
[self drawText:[NSString stringWithFormat:@"%@",_yLineDataArr[i]] andContext:context atPoint:P_M(p.x-len-3, p.y-hei / 2) WithColor:_xAndYNumberColor andFontSize:self.yDescTextFontSize];
@@ -592,7 +594,7 @@ - (void)drawXAndYLineWithContext:(CGContextRef)context{
[self drawLineWithContext:context andStarPoint:self.chartOrigin andEndPoint:P_M(self.contentInsets.left+_xLength, self.chartOrigin.y) andIsDottedLine:NO andColor:self.xAndYLineColor];
if (_showYLine) {
- [self drawLineWithContext:context andStarPoint:P_M(self.contentInsets.left,CGRectGetHeight(self.frame)-self.contentInsets.bottom) andEndPoint:P_M(self.contentInsets.left,self.contentInsets.top) andIsDottedLine:NO andColor:self.xAndYLineColor];
+ [self drawLineWithContext:context andStarPoint:P_M(self.contentInsets.left,CGRectGetHeight(self.frame)-self.contentInsets.bottom) andEndPoint:P_M(self.contentInsets.left,self.contentInsets.top) andIsDottedLine:self.leavelLineIsDotted andColor:self.xAndYLineColor];
}
if (_xLineDataArr.count>0) {
@@ -632,7 +634,7 @@ - (void)drawXAndYLineWithContext:(CGContextRef)context{
CGFloat len = [self sizeOfStringWithMaxSize:XORYLINEMAXSIZE textFont:self.yDescTextFontSize aimString:topArr[i]].width;
CGFloat hei = [self sizeOfStringWithMaxSize:CGSizeMake(CGFLOAT_MAX, 30) textFont:self.yDescTextFontSize aimString:topArr[i]].height;
if (_showYLevelLine) {
- [self drawLineWithContext:context andStarPoint:p andEndPoint:P_M(self.contentInsets.left+_xLength, p.y) andIsDottedLine:YES andColor:self.xAndYLineColor];
+ [self drawLineWithContext:context andStarPoint:p andEndPoint:P_M(self.contentInsets.left+_xLength, p.y) andIsDottedLine:self.leavelLineIsDotted andColor:self.xAndYLineColor];
}else
[self drawLineWithContext:context andStarPoint:p andEndPoint:P_M(p.x+3, p.y) andIsDottedLine:NO andColor:self.xAndYLineColor];
[self drawText:[NSString stringWithFormat:@"%@",topArr[i]] andContext:context atPoint:P_M(p.x-len-3, p.y-hei / 2) WithColor:_xAndYNumberColor andFontSize:self.yDescTextFontSize];
@@ -646,7 +648,7 @@ - (void)drawXAndYLineWithContext:(CGContextRef)context{
CGFloat hei = [self sizeOfStringWithMaxSize:CGSizeMake(CGFLOAT_MAX, 30) textFont:self.yDescTextFontSize aimString:bottomArr[i]].height;
if (_showYLevelLine) {
- [self drawLineWithContext:context andStarPoint:p andEndPoint:P_M(self.contentInsets.left+_xLength, p.y) andIsDottedLine:YES andColor:self.xAndYLineColor];
+ [self drawLineWithContext:context andStarPoint:p andEndPoint:P_M(self.contentInsets.left+_xLength, p.y) andIsDottedLine:self.leavelLineIsDotted andColor:self.xAndYLineColor];
}else{
[self drawLineWithContext:context andStarPoint:p andEndPoint:P_M(p.x+3, p.y) andIsDottedLine:NO andColor:self.xAndYLineColor];
@@ -1075,7 +1077,10 @@ - (void)drawPositionLineWithContext:(CGContextRef)context{
return;
}
-
+ if (self.topDesc && self.contentInsets.top > 0) {
+
+ [self drawText:self.topDesc andContext:context atPoint:P_M(self.contentInsets.left,self.contentInsets.top/2) WithColor:[UIColor whiteColor] andFontSize:self.valueFontSize + 5.f];
+ }
for (NSInteger m = 0;m<_valueArr.count;m++) {
NSArray *arr = _drawDataArr[m];
@@ -1091,8 +1096,8 @@ - (void)drawPositionLineWithContext:(CGContextRef)context{
if (_showValueLeadingLine) {
- [self drawLineWithContext:context andStarPoint:P_M(self.chartOrigin.x, p.y) andEndPoint:p andIsDottedLine:YES andColor:positionLineColor];
- [self drawLineWithContext:context andStarPoint:P_M(p.x, self.chartOrigin.y) andEndPoint:p andIsDottedLine:YES andColor:positionLineColor];
+ [self drawLineWithContext:context andStarPoint:P_M(self.chartOrigin.x, p.y) andEndPoint:p andIsDottedLine:self.leavelLineIsDotted andColor:positionLineColor];
+ [self drawLineWithContext:context andStarPoint:P_M(p.x, self.chartOrigin.y) andEndPoint:p andIsDottedLine:self.leavelLineIsDotted andColor:positionLineColor];
}
if (!_showPointDescription) {
@@ -1180,6 +1185,11 @@ -(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{
*/
- (void)drawPoint{
+ // 实现不显示点时的逻辑
+ if (self.hasPoint == NO) {
+ return;
+ }
+
for (NSInteger m = 0;m<_drawDataArr.count;m++) {
NSArray *arr = _drawDataArr[m];
diff --git a/JHChartDemo/JHChart/JHRingChart.h b/JHChartDemo/JHChart/JHRingChart.h
index 714a668..8bcce66 100644
--- a/JHChartDemo/JHChart/JHRingChart.h
+++ b/JHChartDemo/JHChart/JHRingChart.h
@@ -6,11 +6,40 @@
// Copyright © 2016年 JH. All rights reserved.
//
+#import
#import "JHChart.h"
+/**
+ 圆环展示样式
+
+ - RingChartType_Default: 默认,有模块指示线百分比
+ - RingChartType_BottomTips: 指示线百分比在圆环下方显示
+ */
+typedef NS_ENUM(NSUInteger, RingChartType) {
+
+ RingChartType_Default = 0,
+ RingChartType_BottomTips,
+
+};
+
+
@interface JHRingChart : JHChart
#define k_Width_Scale (self.frame.size.width / [UIScreen mainScreen].bounds.size.width)
+
+/**
+ * Description of each segment of a pie graph
+ */
+@property (nonatomic, strong) NSArray * descArr;
+
+/**
+ 圆环展示样式
+ */
+@property (nonatomic, assign) RingChartType ringShowType;
+/**
+ 圆环模块间隔, 默认为 10
+ */
+@property (nonatomic, assign) CGFloat ringItemsSpace;
/**
* Data source Array
*/
@@ -27,4 +56,10 @@
* Ring Chart width
*/
@property (nonatomic, assign) CGFloat ringWidth;
+
+/**
+ * 中心评分 (0 - 100分)
+ */
+@property (nonatomic, strong) NSString * ringScore;
+
@end
diff --git a/JHChartDemo/JHChart/JHRingChart.m b/JHChartDemo/JHChart/JHRingChart.m
index e4e0221..06a26f9 100644
--- a/JHChartDemo/JHChart/JHRingChart.m
+++ b/JHChartDemo/JHChart/JHRingChart.m
@@ -10,7 +10,10 @@
#define k_COLOR_STOCK @[[UIColor colorWithRed:1.000 green:0.783 blue:0.371 alpha:1.000], [UIColor colorWithRed:1.000 green:0.562 blue:0.968 alpha:1.000],[UIColor colorWithRed:0.313 green:1.000 blue:0.983 alpha:1.000],[UIColor colorWithRed:0.560 green:1.000 blue:0.276 alpha:1.000],[UIColor colorWithRed:0.239 green:0.651 blue:0.170 alpha:1.000]]
@interface JHRingChart ()
-
+{
+ // 中心评分控件
+ UILabel *_percentLabel;
+}
//环图间隔 单位为π
@property (nonatomic,assign)CGFloat itemsSpace;
@@ -19,6 +22,14 @@ @interface JHRingChart ()
@property (nonatomic,assign) CGFloat redius;
+
+@property (assign , nonatomic) NSInteger allValueCount ;
+// 下方小标签 宽度
+@property (assign , nonatomic) CGFloat chartArcLength ;
+
+
+
+
@end
@@ -32,11 +43,27 @@ -(instancetype)initWithFrame:(CGRect)frame {
self.chartOrigin = CGPointMake(CGRectGetWidth(self.frame) / 2, CGRectGetHeight(self.frame)/2);
_redius = (CGRectGetHeight(self.frame) -60*k_Width_Scale)/4;
_ringWidth = 40;
+ _ringItemsSpace = 10;
+ _chartArcLength = 8.0;
+ [self initUI];
}
return self;
}
-
+-(void)initUI
+{
+ _percentLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, _redius, _redius)];
+ _percentLabel.textColor = [UIColor whiteColor];
+ _percentLabel.textAlignment = NSTextAlignmentCenter;
+ _percentLabel.font = [UIFont boldSystemFontOfSize:50];
+ _percentLabel.text = @"95分";
+ _percentLabel.backgroundColor = [UIColor redColor];
+ [self addSubview:_percentLabel];
+// [self bringSubviewToFront:_percentLabel];
+// [self.layer addSublayer:_percentLabel.layer];
+
+
+}
-(void)setValueDataArr:(NSArray *)valueDataArr{
@@ -46,11 +73,14 @@ -(void)setValueDataArr:(NSArray *)valueDataArr{
[self configBaseData];
}
-
+- (void)setRingItemsSpace:(CGFloat)ringItemsSpace {
+ _ringItemsSpace = ringItemsSpace;
+ [self configBaseData];
+}
- (void)configBaseData{
_totolCount = 0;
- _itemsSpace = (M_PI * 2.0 * 10 / 360)/_valueDataArr.count ;
+ _itemsSpace = (M_PI * 2.0 * _ringItemsSpace / 360)/_valueDataArr.count ;
for (id obj in _valueDataArr) {
_totolCount += [obj floatValue];
@@ -69,6 +99,9 @@ - (void)showAnimation{
[layer removeFromSuperlayer];
}
+ if (_ringShowType == RingChartType_BottomTips) {
+ self.chartOrigin = CGPointMake(self.chartOrigin.x, self.chartOrigin.y * 2 / 3 );
+ }
CGFloat lastBegin = -M_PI/2;
@@ -109,11 +142,67 @@ - (void)showAnimation{
}
-
+- (void)countAllValue{
+ _allValueCount = 0;
+ for (NSString *obj in _valueDataArr) {
+
+ _allValueCount += obj.integerValue;
+
+ }
+}
+- (void)drawText:(NSString *)text andContext:(CGContextRef )context atPoint:(CGPoint )rect WithColor:(UIColor *)color andTextFontSize:(CGFloat )fontSize{
+
+
+ [[NSString stringWithFormat:@"%@",text] drawAtPoint:rect withAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:fontSize],NSForegroundColorAttributeName:color}];
+
+
+ [color setFill];
+ CGContextDrawPath(context, kCGPathFill);
+
+}
-(void)drawRect:(CGRect)rect{
CGContextRef contex = UIGraphicsGetCurrentContext();
+
+ // 绘制中心评分
+ if (self.ringScore.length > 0) {
+
+ CGSize txtSize = [self getTextWithWhenDrawWithText:self.ringScore fontSize:30*k_Width_Scale maxSize:CGSizeMake(_redius, _redius)];
+ [self drawText:self.ringScore andContext:contex atPoint:P_M(self.chartOrigin.x - txtSize.width/2,self.chartOrigin.y - txtSize.height/2) WithColor:[UIColor whiteColor] andTextFontSize:30*k_Width_Scale];
+ }
+
+
+ if (!_descArr) {
+ NSMutableArray * arr = [NSMutableArray arrayWithCapacity:_valueDataArr.count];
+ [_valueDataArr enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
+ [arr addObject:@""];
+ }];
+ _descArr = arr;
+ }
+
+ // 绘制底部标签
+ if (_valueDataArr.count>0 && _ringShowType == RingChartType_BottomTips) {
+
+ NSArray *colors = nil;
+
+ if (_fillColorArray.count==_valueDataArr.count) {
+ colors = _fillColorArray;
+ }else{
+ colors = k_COLOR_STOCK;
+ }
+
+ for (NSInteger i = 0; i<_descArr.count; i++) {
+
+ [self drawQuartWithColor:colors[i%colors.count] andBeginPoint:P_M(20+15+self.frame.size.width/3*(i%3), 20*(i/3 )+ self.chartOrigin.y * 2 + 25+_chartArcLength*2) andContext:contex];
+
+ CGFloat present = [_valueDataArr[i] floatValue] / _totolCount * 100;
+ [self drawText:[NSString stringWithFormat:@"%@ 占比:%.1f%c",_descArr[i],present,'%'] andContext:contex atPoint:P_M(30+self.frame.size.width/3*(i%3)+20, 20*(i/3)+ self.chartOrigin.y * 2 + 25+_chartArcLength*2) WithColor:[UIColor whiteColor] andTextFontSize:10*k_Width_Scale];
+ }
+
+
+ }
+
CGFloat lastBegin = 0;
CGFloat longLen = _redius +30*k_Width_Scale;
@@ -122,44 +211,59 @@ -(void)drawRect:(CGRect)rect{
CGFloat currentSpace = [obj floatValue] / _totolCount * (M_PI * 2 - _itemsSpace * _valueDataArr.count);;
NSLog(@"%f",currentSpace);
CGFloat midSpace = lastBegin + currentSpace / 2;
-
+
CGPoint begin = CGPointMake(self.chartOrigin.x + sin(midSpace) * _redius, self.chartOrigin.y - cos(midSpace)*_redius);
CGPoint endx = CGPointMake(self.chartOrigin.x + sin(midSpace) * longLen, self.chartOrigin.y - cos(midSpace)*longLen);
-
+
NSLog(@"%@%@",NSStringFromCGPoint(begin),NSStringFromCGPoint(endx));
lastBegin += _itemsSpace + currentSpace;
-
+
UIColor *color;
-
+
if (_fillColorArray.count<_valueDataArr.count) {
color = k_COLOR_STOCK[i%k_COLOR_STOCK.count];
}else{
color = _fillColorArray[i];
}
-
- [self drawLineWithContext:contex andStarPoint:begin andEndPoint:endx andIsDottedLine:NO andColor:color];
-
-
- CGPoint secondP = CGPointZero;
-
- CGSize size = [[NSString stringWithFormat:@"%.02f%c",[obj floatValue] / _totolCount * 100,'%'] boundingRectWithSize:CGSizeMake(200, 100) options:NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:10*k_Width_Scale]} context:nil].size;
-
- if (midSpace
+@property (nonatomic, strong)JHLineChart * lineChart;
+
@end
@implementation JHShowController
@@ -23,7 +25,9 @@ - (void)viewDidLoad {
switch (_index) {
case 0:
{
- [self showFirstQuardrant];
+ [self addBtn];
+ [self showFirstWithIndex:0];
+
}
break;
case 1:
@@ -49,7 +53,7 @@ - (void)viewDidLoad {
break;
case 5:
{
- [self showRingChartView];
+ [self showRingChart];
}
break;
case 6:
@@ -75,8 +79,128 @@ - (void)viewDidLoad {
}
-
-
+NSArray * xLineDatas() {
+ return @[
+ @[@"9",@"10",@"11",@"12",@"13",@"14",@"15",@"16"],
+ @[@"四月",@"五月",@"六月",@"七月",@"八月",@"九月",@"十月",@"十一月"]
+ ];
+}
+NSArray * valueDatas() {
+
+ return @[
+ @[@[@"10",@"22",@"1",@6,@4,@9,@6,@7]],
+ @[@[@"20",@"12",@"30",@6,@14,@9,@3,@30]]
+ ];
+}
+- (void)addBtn {
+
+ NSArray * titles = @[@"周",@"月"];
+ CGFloat width = (CGRectGetWidth(self.view.frame) - 20)/2 ;
+
+ for (NSInteger i = 0; i < titles.count; i++) {
+
+ UIButton * btn = [UIButton buttonWithType:UIButtonTypeSystem];
+ [btn setTitle:titles[i] forState:UIControlStateNormal];
+ btn.frame = CGRectMake(10 + i * width, 500, width, 30);
+ btn.tag = i + 1;
+ [btn addTarget:self action:@selector(changeBtnClick:) forControlEvents:UIControlEventTouchUpInside];
+ [self.view addSubview:btn];
+ }
+}
+- (void)changeBtnClick:(UIButton *)btn {
+
+
+ [self showFirstWithIndex:btn.tag - 1];
+
+}
+- (JHLineChart *)lineChart {
+
+ if (!_lineChart) {
+ _lineChart = [[JHLineChart alloc] initWithFrame:CGRectMake(10, 60, k_MainBoundsWidth-20, 300) andLineChartType:JHChartLineValueNotForEveryX];
+ [self.view addSubview:_lineChart];
+ }
+ return _lineChart;
+}
+- (void)showFirstWithIndex:(NSInteger)index {
+ /* Create object */
+// JHLineChart *lineChart = [[JHLineChart alloc] initWithFrame:CGRectMake(10, 60, k_MainBoundsWidth-20, 300) andLineChartType:JHChartLineValueNotForEveryX];
+
+ /* The scale value of the X axis can be passed into the NSString or NSNumber type and the data structure changes with the change of the line chart type. The details look at the document or other quadrant X axis data source sample.*/
+
+ JHLineChart * lineChart = self.lineChart;
+
+ [lineChart clear];
+
+ // x 轴坐标显示 yLineDataArr
+ lineChart.xLineDataArr = xLineDatas()[index];
+ // 偏移量
+ lineChart.contentInsets = UIEdgeInsetsMake(50, 25, 35, 25);
+ lineChart.topDesc = @"平均心率 65次,心脏骤停0次";
+ /* The different types of the broken line chart, according to the quadrant division, different quadrant correspond to different X axis scale data source and different value data source. */
+ // 分布象限
+ lineChart.lineChartQuadrantType = JHLineChartQuadrantTypeFirstQuardrant;
+
+ // 需要绘制的数据(对应每个 x 点坐标的 y 值)
+ lineChart.valueArr = valueDatas()[index];
+ // lineChart.valueBaseRightYLineArray = @[@[@"3",@"1",@"2",@1,@2,@3,@2,@5]];
+
+ // 绘制线条宽度
+ lineChart.animationPathWidth = 1;
+ // 是否显示绘制点
+ lineChart.hasPoint = YES;
+ // 显示 y轴水平线
+ lineChart.showYLevelLine = YES;
+ // 是否显示 Y 轴,默认为 YES
+ lineChart.showYLine = YES;
+
+ // 是否显示 双 Y 轴
+ lineChart.showDoubleYLevelLine = NO;
+
+ // Y 轴显示对应的坐标值 单 y 轴时,无需填写
+ // lineChart.yLineDataArr = @[@[@5,@10,@15,@20,@25,@30],@[@1,@2,@3,@4,@5,@6]];
+
+ // lineChart.yLineDataArr = @[@5,@10,@15,@20,@25,@30];
+ // lineChart.drawPathFromXIndex = 1;
+
+ // 动画绘制时间
+ lineChart.animationDuration = 2.0;
+ // 是否显示标尺线
+ lineChart.showValueLeadingLine = NO;
+ // 标尺线是否为 虚线
+ lineChart.leavelLineIsDotted = NO;
+ // 点值字号大小
+ lineChart.valueFontSize = 9.0;
+ lineChart.backgroundColor = [UIColor colorWithRed:26 / 255.0 green:49 / 255.0 blue:100 / 255.0 alpha:1.0];
+
+ // 显示点值 描述
+ lineChart.showPointDescription = YES;
+
+ // 垂直显示 X轴 坐标(此时布局为 UILabel)
+ lineChart.showXDescVertical = NO;
+ // 垂直显示是的最大宽度
+ lineChart.xDescMaxWidth = 15;
+
+ /* 折线颜色 */
+ lineChart.valueLineColorArr =@[ [UIColor colorWithWhite:0.8 alpha:0.5]];
+ /* 描点颜色*/
+ lineChart.pointColorArr = @[[UIColor redColor]];
+ /* XY 轴线颜色 */
+ lineChart.xAndYLineColor = [UIColor grayColor];
+ /* XY 轴线坐标颜色 */
+ lineChart.xAndYNumberColor = [UIColor whiteColor];
+// /* Dotted line color of the coordinate point */
+// lineChart.positionLineColorArr = @[[UIColor whiteColor]];
+ /* 是否需要颜色填充 */
+ lineChart.contentFill = YES;
+ /* 是否为曲线 */
+ lineChart.pathCurve = YES;
+ /* 填充色 */
+ lineChart.contentFillColorArr = @[[UIColor colorWithRed:55/255.0 green:90/255.0 blue:150/255.0 alpha:0.5]];
+// [self.view addSubview:lineChart];
+ /* Start animation */
+ [lineChart showAnimation];
+
+}
//第一象限折线图
- (void)showFirstQuardrant{
/* Create object */
@@ -248,7 +372,7 @@ - (void)showPieChartUpView{
[self.view addSubview:pie];
/* When touching a pie chart, the animation offset value */
pie.positionChangeLengthWhenClick = 15;
- pie.showDescripotion = NO;
+ pie.showDescripotion = YES;
pie.animationType = JHPieChartAnimationByOrder;
// pie.colorArr = @[[UIColor redColor],[UIColor redColor],[UIColor redColor],[UIColor redColor],[UIColor redColor],[UIColor redColor],[UIColor redColor],[UIColor yellowColor]];
/* Start animation */
@@ -256,7 +380,28 @@ - (void)showPieChartUpView{
}
+//环状图
+- (void)showRingChart{
+ JHRingChart *ring = [[JHRingChart alloc] initWithFrame:CGRectMake(0, 100, k_MainBoundsWidth, k_MainBoundsWidth)];
+ /* background color */
+ ring.backgroundColor = [UIColor colorWithRed:26 / 255.0 green:49 / 255.0 blue:100 / 255.0 alpha:1.0];
+ /* Data source array, only the incoming value, the corresponding ratio will be automatically calculated */
+ ring.ringItemsSpace = 0;
+ ring.ringShowType = RingChartType_BottomTips;
+ ring.ringScore = @"100分";
+ // 顺时针排序
+ ring.valueDataArr = @[@"27",@"20",@"53"];
+ ring.descArr = @[@"浅眠",@"中度",@"深度"];
+ /* Width of ring graph */
+ ring.ringWidth = 35.0;
+ /* Fill color for each section of the ring diagram */
+ ring.fillColorArray = @[[UIColor colorWithRed:25/255.0 green:203/255.0 blue:168/255.0 alpha:1.0], [UIColor colorWithRed:4/255.0 green:145/255.0 blue:240/255.0 alpha:1.0],[UIColor colorWithRed:175/255.0 green:161/255.0 blue:110/255.0 alpha:1.0]];
+ /* Start animation */
+ [ring showAnimation];
+ [self.view addSubview:ring];
+
+}
//环状图
- (void)showRingChartView{
JHRingChart *ring = [[JHRingChart alloc] initWithFrame:CGRectMake(0, 100, k_MainBoundsWidth, k_MainBoundsWidth)];