Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JHLineChart 中添加 hasPoint 实现 + xAndYNumberColor颜色的异常bug + 添加leavelLine为虚实线的配置属性 #64

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
type = "1"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.ExceptionBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
scope = "0"
stopOnStyle = "0">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>JHChartDemo.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
</dict>
</plist>
10 changes: 9 additions & 1 deletion JHChartDemo/JHChart/JHLineChart.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
*/
Expand Down
30 changes: 20 additions & 10 deletions JHChartDemo/JHChart/JHLineChart.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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];

Expand Down Expand Up @@ -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];
Expand All @@ -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];
Expand All @@ -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) {
Expand Down Expand Up @@ -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];
Expand All @@ -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) {
Expand Down Expand Up @@ -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];
Expand All @@ -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];
Expand Down Expand Up @@ -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];
Expand All @@ -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) {
Expand Down Expand Up @@ -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];
Expand Down
35 changes: 35 additions & 0 deletions JHChartDemo/JHChart/JHRingChart.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,40 @@
// Copyright © 2016年 JH. All rights reserved.
//

#import <Foundation/Foundation.h>
#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
*/
Expand All @@ -27,4 +56,10 @@
* Ring Chart width
*/
@property (nonatomic, assign) CGFloat ringWidth;

/**
* 中心评分 (0 - 100分)
*/
@property (nonatomic, strong) NSString * ringScore;

@end
Loading