You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

92 lines
3.1 KiB

//
// 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;
}
- (void)setLineGraphView_DayWeekWithData:(NSArray<Step *> *)dataList{
if (_LineGraphView) {
[_LineGraphView removeFromSuperview];
}
// 初始化折线图
_LineGraphView = [[FBYLineGraphView alloc] initWithFrame:CGRectMake(0 , 0, _lineChartContentView.size.width, _lineChartContentView.size.height)];
[self.lineChartContentView addSubview:_LineGraphView];
// 设置折线图属性
// _LineGraphView.title = @"周统计图"; // 折线图名称
_LineGraphView.X_UnintTitle = @"时间(日)";
_LineGraphView.MainColor = mainColor;
_LineGraphView.XYAxisColor = [UIColor lightGrayColor];
NSMutableArray *tempDataList = [NSMutableArray array];
NSMutableArray *numArr =[NSMutableArray new];
for (Step* item in dataList)
{
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);
NSNumber *newTimeNumber = [NSNumber numberWithString:[UICommon getTimeStrWithString:item.date]];
[tempDic setValue:newTimeNumber forKey:@"timestamp"];
[tempDic setValue:item.num forKey:@"data"];
[tempDataList addObject:tempDic];
[numArr addObject:item.num];
}
float max = [[numArr valueForKeyPath:@"@max.floatValue"] floatValue];
NSInteger size = F(@"%.0f",max).length;
int backPrecentCount = 4;
if(size == 5){
backPrecentCount = 5;
} else if(size == 4) {
backPrecentCount = 6;
}else{
backPrecentCount = 4;
}
_LineGraphView.maxValue = max+10; // Y轴最大值
_LineGraphView.Ycount = backPrecentCount; // Y轴分割个数(包含0在内的)
[_LineGraphView setXMarkTitlesDayAndValues:tempDataList titleKey:@"timestamp" valueKey:@"data"]; // X轴刻度标签及相应的值
//LineGraphView.xScaleMarkLEN = 60;
//设置完数据等属性后绘图折线图
[_LineGraphView mapping];
}
/// 设置计步数组 绘制统计图
-(void)setStepDataList:(NSArray<Step *> *)dataList WithTodayData:(int)todayData{
[_todayLable animationFromnum:0 toNum:todayData 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