PNBarChart

#import "BarChartVC.h"
#import "PNChart.h"

@interface BarChartVC () {
    
    PNBarChart *_barChart;
    IBOutlet UIView *_bgView;
    
}

@end

@implementation BarChartVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
        // _bgView为xib上拖得View
        _barChart = [[PNBarChart alloc] initWithFrame:_bgView.bounds];
        _barChart.backgroundColor = [[UIColor lightGrayColor] colorWithAlphaComponent:0.2];
        
//        _barChart.yLabels = @[@"0", @"300", @"600", @"900", @"1200", @"1500"];
        //_barChart.yMaxValue = 1456;
        
        //_barChart.strokeColor = [UIColor blackColor];// 所有柱形颜色
        _barChart.strokeColors = @[[UIColor whiteColor], [UIColor blackColor], [UIColor blueColor], [UIColor orangeColor], [UIColor lightGrayColor]];// 每个柱形的颜色 必须每个设置才有效
        _barChart.barBackgroundColor = [UIColor yellowColor];// 柱形背景颜色
        
        _barChart.isShowNumbers = YES;// 是否显示柱子中的数字
        _barChart.labelTextColor = [UIColor blueColor];// 所有label文本颜色
        
//        _barChart.yChartLabelWidth = 20;// Y轴label宽度
//        _barChart.yLabelPrefix = @"p";// Y轴前缀
//        _barChart.yLabelSuffix = @"s";// Y轴后缀
        
        _barChart.showChartBorder = YES;// 是否显示图表边框
        _barChart.chartBorderColor = [UIColor redColor];// 图表边框颜色
        _barChart.labelFont = [UIFont systemFontOfSize:10];// X、Y轴label文本大小
        
        //_barChart.chartMarginLeft = 25;// 图表距离左边距离 默认25
        //_barChart.chartMarginBottom = 50;// 图表距离底部距离 默认25
        //_barChart.chartMarginTop = 25;// 默认25
        //_barChart.barRadius = 2;// 柱形圆角半径
        _barChart.barWidth = 30;// 柱形宽度
        _barChart.labelMarginTop = 25;// X轴label距离图表的上外边距 设置了这个 就不需要设置chartMarginBottom=50 来正确的显示X轴label的位置

        _barChart.yLabelSum = 10;// Y轴有多少个等级label
        
        //_barChart.rotateForXAxisText = YES;// X轴label是否顺时针旋转45度 设置了这个属性 就需要重新改变 labelMarginTop、chartMarginBottom的值
        
        // X轴和值的设置放最后  前面的一些设置才生效
        _barChart.xLabels = @[@"普通", @"翡翠", @"白金", @"钻石", @"金钻"];
        _barChart.yValues = @[@1456, @799, @233, @23, @2];
        
        [_barChart strokeChart];
        [_bgView addSubview:_barChart];
        
    });
    
}

@end

效果如下图

111.png
 _barChart.xLabelSkip = 2;// 以xLabelSkip为基数 X轴第xLabelSkip的倍数个显示X轴label 效果图如下
11111.png
_barChart.isGradientShow = NO;// 柱形颜色是否渐变 效果图如下
111.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容