// // NewStepChartCell.m // tongxin // // Created by Apple on 2020/4/10. // Copyright © 2020 xTT. All rights reserved. // #import "NewStepChartCell.h" #import "UILabel+BezierAnimation.h" #import "FBYLineGraphView.h" @interface NewStepChartCell() /// 折线图 @property (strong, nonatomic)FBYLineGraphView *LineGraphView; @end @implementation NewStepChartCell - (void)awakeFromNib { [super awakeFromNib]; self.selectionStyle = UITableViewCellSelectionStyleNone; UIImageView *topimg = [UICommon ui_imageView:CGRectZero fileName:@"icon_details_step_bg"]; [self.contentView addSubview:topimg]; [topimg mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(self.contentView); make.top.equalTo(self.contentView).offset(60); make.size.mas_equalTo(CGSizeMake(Adapted(176), Adapted(176))); }]; UIImageView *topimg1 = [UICommon ui_imageView:CGRectZero fileName:@"icon_details_step_ren"]; [self.contentView addSubview:topimg1]; [topimg1 mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(self.contentView); make.top.equalTo(self.contentView).offset(28); make.size.mas_equalTo(CGSizeMake(56, 56)); }]; UILabel *todayLable = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:FontBold_(48) textColor:KKBlack20 text:@"0" Radius:0]; self.todayLable = todayLable; [self.contentView addSubview:todayLable]; [todayLable mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(self.contentView); make.top.equalTo(topimg1.mas_bottom).offset(30); }]; UILabel *titleLable = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:FontBold_(14) textColor:mainColor text:@"今日步数" Radius:0]; [self.contentView addSubview:titleLable]; [titleLable mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(self.contentView); make.top.equalTo(todayLable.mas_bottom).offset(5); }]; UILabel *titleLable1 = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:Font_(12) textColor:KKGrey102 text:@"- 最近一周计步数 -" Radius:0]; [self.contentView addSubview:titleLable1]; [titleLable1 mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(self.contentView); make.top.equalTo(topimg.mas_bottom).offset(56); }]; //self.lineChartContentView.backgroundColor = RGBA(35, 128, 255, 0.2); [self.lineChartContentView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.equalTo(self.contentView).inset(5); make.top.equalTo(titleLable1.mas_bottom).offset(30); make.height.mas_equalTo(246); }]; } - (void)setLineGraphView_DayWeekWithData:(NSArray *)dataList { if (_LineGraphView) { [_LineGraphView removeFromSuperview]; } // 初始化折线图 _LineGraphView = [[FBYLineGraphView alloc] initWithFrame:CGRectMake(0 , 0, _lineChartContentView.size.width, 236)]; [self.lineChartContentView addSubview:_LineGraphView]; // 设置折线图属性 // _LineGraphView.title = @"周统计图"; // 折线图名称 //_LineGraphView.X_UnintTitle = @"时间(日)"; _LineGraphView.MainColor = mainColor; _LineGraphView.minValue = 0; _LineGraphView.XYAxisColor = [UIColor lightGrayColor]; NSMutableArray *tempDataList = [NSMutableArray array]; NSMutableArray *numArr =[NSMutableArray new]; for (Step* item in dataList) { // item.num = [[NSNumber alloc] initWithInteger:(arc4random() % 3000) + 12000]; NSMutableDictionary *tempDic = [NSMutableDictionary dictionary]; NSDateFormatter*dateFormatter = [[NSDateFormatter alloc]init]; [dateFormatter setDateFormat:@"yyyy-MM-dd"]; // NSString *dayStr = [myHelper getDateFormatWithStr:@"yyyy-MM-dd" date:[NSDate dateWithTimeIntervalSince1970:item.timestamp.doubleValue]]; NSNumber *newTimeNumber = @([dateFormatter dateFromString:item.date].timeIntervalSince1970); [tempDic setValue:newTimeNumber forKey:@"timestamp"]; [tempDic setValue:item.num forKey:@"data"]; [tempDataList addObject:tempDic]; [numArr addObject:item.num]; } // NSArray *tempArr = @[ // @{@"timestamp":@(1689341022),@"data":@1198}, // @{@"timestamp":@(1689427422),@"data":@3000}, // @{@"timestamp":@(1689513822),@"data":@500}, // @{@"timestamp":@(1689600222),@"data":@7500}, // @{@"timestamp":@(1689686622),@"data":@2300}, // @{@"timestamp":@(1689773022),@"data":@8900}, // @{@"timestamp":@(1689859422),@"data":@13500}, // ]; // tempArr = [[tempArr reverseObjectEnumerator] allObjects]; int backPrecentCount = 0; if(numArr.count > 0) { float max = [[numArr valueForKeyPath:@"@max.floatValue"] floatValue]; NSInteger size = [NSString stringWithFormat:@"%.0f",max].length; backPrecentCount = 4; if(size == 5){ backPrecentCount = 5; } else if(size == 4) { backPrecentCount = 6; }else{ backPrecentCount = 4; } _LineGraphView.maxValue = max+1000; // Y轴最大值 _LineGraphView.Ycount = backPrecentCount; // Y轴分割个数(包含0在内的) } else { _LineGraphView.maxValue = 15000; // Y轴最大值 _LineGraphView.Ycount = 6; // Y轴分割个数(包含0在内的) } [_LineGraphView setXMarkTitlesDayAndValues:tempDataList titleKey:@"timestamp" valueKey:@"data"]; // X轴刻度标签及相应的值 //LineGraphView.xScaleMarkLEN = 60; //设置完数据等属性后绘图折线图 [_LineGraphView mapping]; } /// 设置计步数组 绘制统计图 -(void)setStepDataList:(NSArray *)dataList WithTodayData:(int)todayData{ [_todayLable animationFromnum:0 toNum:0 duration:0.5 precision:@"%d"]; [self setLineGraphView_DayWeekWithData:dataList]; } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } @end