iOS折线图左右滑动 基于BEMSimpleLineGraph

基于BEMSimpleLineGraph的横向可滑动折线图

LNLineChartView实现功能

  • 横线滚动,x轴为日期,最近一次展示在最后边,查看以前的需要右滑.默认选中最近一次节点
  • 节点可点击
  • 分页绘制,绘制时占用内存

BEChart为BEMSimpleLineGraph中实现

代码实现

//创建折线图
- (void)createLineChartView{

  chartView = [[LNLineChartView alloc] initWithFrame:CGRectMake(0, 100, self.view.frame.size.width, 208)];
    chartView.delegate = self;
    [self.view addSubview:chartView];
    
    NSMutableArray *chartDataArr = [[NSMutableArray alloc] init];
    for (int i = 0; i<100; i++) {
        NSMutableDictionary *dict = [NSMutableDictionary dictionary];
        if (i<20) {
            dict[@"star"] = [NSNumber numberWithInt:i%4];
            dict[@"playDate"] = @"2017-06-01 18:05:51";
        }else{
            dict[@"star"] = [NSNumber numberWithInt:i%4];
            dict[@"playDate"] = @"2017-06-04 18:05:51";
        }
        [chartDataArr addObject:dict];
    }
    
     chartView.starInfoArr = chartDataArr;
}

//实现折线图代理方法
#pragma mark - 
//默认选中最近一次节点触发代理方法
- (void)refreshLatestObjectWithDateStr:(NSString *)dateStr star:(NSInteger)star
{
    
}
//节点点击事件触发的代理方法
- (void)chartViewDotsTouchWithIndex:(NSInteger)index model:(LNLineChartModel *)model
{
    [self refreshLatestObjectWithDateStr:model.playDate star:model.star];
}
iOS折线图左右滑动 基于BEMSimpleLineGraph_第1张图片
linechart.png

附: demo github 下载地址 https://github.com/KrystalNa/LNLineChart

你可能感兴趣的:(iOS折线图左右滑动 基于BEMSimpleLineGraph)