首页 > 其他分享 >曲线图

曲线图

时间:2023-07-03 20:56:56浏览次数:33  
标签:曲线图 self new changeBtn sleepView frame view

//
//  ViewController.m
//  AAChartKitDemo
//
//  Created by bairui on 2023/6/28.
//

#import "ViewController.h"
#import <AAChartKit/AAChartKit.h>

@interface ViewController ()

@property(nonatomic,strong)AAChartView *sleepView;
@property(nonatomic,strong)UIButton *changeBtn;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
    CGFloat chartViewWidth  = self.view.frame.size.width;
    CGFloat chartViewHeight = self.view.frame.size.height - 250;
    self.sleepView = [[AAChartView alloc]init];
    self.sleepView.frame = CGRectMake(0, 60, chartViewWidth, chartViewHeight);
    ////禁用 AAChartView 滚动效果(默认不禁用)
    //self.aaChartView.scrollEnabled = NO;
    [self.view addSubview:self.sleepView];
    
    AAChartModel *aaChartModel = AAChartModel.new
        .chartTypeSet(AAChartTypeLine)//设置图表的类型(这里以设置的为折线面积图为例)
        .titleSet(@"ECG Paper Style Chart")//设置图表标题
        .colorsThemeSet(@[@"#fe117c"])//设置主题颜色数组
        .yAxisLabelsEnabledSet(false)
        .xAxisLabelsEnabledSet(false)
        .legendEnabledSet(false)
        .subtitleSet(@"虚拟数据 虚拟数据  虚拟数据  虚拟数据")//设置图表副标题
//        .categoriesSet(@[@"00:00",@"3",@"5",@"7", @"9",@"11",@"13",@"15",@"17"])//图表x轴的内容
//        .xAxisTickIntervalSet(@3) //设置 X轴坐标点的间隔数,默认是1
        .seriesSet(@[
            AASeriesElement.new
                .nameSet(@"2017")
                .dataSet(@[@7.0, @6.9, @9.5, @14.5, @18.2, @21.5, @25.2, @26.5, @23.3, @18.3, @13.9, @9.6]),
            
        ]);
    [self.sleepView aa_drawChartWithChartModel:aaChartModel];
    
    self.changeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.changeBtn.backgroundColor = [UIColor blueColor];
    [self.changeBtn setTitle:@"修改数据" forState:UIControlStateNormal];
    [self.view addSubview:self.changeBtn];
    self.changeBtn.frame = CGRectMake(20, chartViewHeight +80, self.view.frame.size.width-40, 40);
    [ self.changeBtn addTarget:self action:@selector(clickChangeDataBtn:) forControlEvents:UIControlEventTouchUpInside];
}

//刷新数据
-(void)clickChangeDataBtn:(UIButton *)btn{
    NSArray* aaChartModelSeriesArray = @[
        AASeriesElement.new
            .dataSet(@[@0.2, @0.8, @5.7, @11.3, @17.0, @22.0, @24.8, @24.1, @20.1, @14.1, @8.6, @2.5])
    ];
    if(!btn.selected){
        aaChartModelSeriesArray = @[
            AASeriesElement.new
                .dataSet(@[@7.0, @6.9, @9.5, @14.5, @18.2, @21.5, @25.2, @26.5, @23.3, @18.3, @13.9, @9.6])
        ];
    }
    btn.selected = !btn.selected;
    [self.sleepView aa_onlyRefreshTheChartDataWithChartModelSeries:aaChartModelSeriesArray];
}


@end

 

标签:曲线图,self,new,changeBtn,sleepView,frame,view
From: https://www.cnblogs.com/somethingWithiOS/p/17524002.html

相关文章