PNLineChart

#import "LineChartVC.h"
#import "PNChart.h"

@interface LineChartVC () {
    
    
    IBOutlet UIView *_bgView;
    PNLineChart *_lineChart;
    
}

@end

@implementation LineChartVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
        _lineChart = [[PNLineChart alloc] initWithFrame:_bgView.bounds];
        _lineChart.backgroundColor = [[UIColor lightGrayColor] colorWithAlphaComponent:0.2];
        
        _lineChart.yFixedValueMax = 1500;
        _lineChart.yFixedValueMin = 0;
        //_lineChart.yLabelNum = 2;// 设置Y轴有几个等级数值 默认自动计算
        //_lineChart.yLabelHeight = 10;
        _lineChart.yLabelFont = [UIFont systemFontOfSize:20];
        _lineChart.yLabelColor = [UIColor blueColor];// Y轴label颜色
        _lineChart.xLabelColor = [UIColor greenColor];// X轴label颜色
        //_lineChart.chartCavanHeight = 10;// 整个图表的高度 默认自动计算
        //_lineChart.chartCavanWidth = 10;// 整个图表的宽度 默认自动计算
        _lineChart.xUnit = @"会员";// X轴单位
        _lineChart.yUnit = @"人";// Y轴单位
        
        //_lineChart.showLabel = NO;// 是否显示X轴label 设置为NO会有问题
        _lineChart.showGenYLabels = YES;// 是否显示Y轴label
        
        _lineChart.displayAnimated = YES;// 是否有显示动画 default YES
        
        _lineChart.showYGridLines = YES;// 是否显示Y轴网格线
        _lineChart.yGridLinesColor = [UIColor redColor];// Y轴网格颜色
        
        //_lineChart.showSmoothLines = YES;// 是否显示弧线
        
        _lineChart.thousandsSeparator = YES;// 千位分隔符 1,200
        
        _lineChart.showCoordinateAxis = YES;// 是否显示坐标轴
        _lineChart.axisWidth = 1;// 坐标轴宽度
        //_lineChart.axisColor = [UIColor blackColor];// 坐标轴颜色
        
        // 最好放到所有设置之后 否则有些设置可能无效
        [_lineChart setXLabels:@[@"普通", @"翡翠", @"白金", @"钻石", @"金钻"]];
        
        NSArray *dataArray1 = @[@1456, @443, @233, @56, @11];
        PNLineChartData *data1 = [PNLineChartData new];
        data1.itemCount = dataArray1.count;
        data1.color = [UIColor greenColor];
        data1.inflexionPointColor = [UIColor redColor];// 拐点颜色
        data1.inflexionPointStyle = PNLineChartPointStyleCircle;// 拐点样式
        data1.getData = ^(NSUInteger index) {
            CGFloat yValue = [dataArray1[index] floatValue];
            return [PNLineChartDataItem dataItemWithY:yValue];
        };
        _lineChart.chartData = @[data1];
        [_lineChart strokeChart];
        [_bgView addSubview:_lineChart];
        
    });
    
}

@end

效果图如下

PNLineChart_第1张图片
2222.png

你可能感兴趣的:(PNLineChart)