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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 179,967评论 25 708
  • 第1章 jQuery实现Ajax应用 1-1 使用load()方法异步请求数据 使用load()方法通过Ajax请...
    mo默22阅读 1,933评论 1 9
  • 4-5 第四课:三维修改器建模 含义:以三维模型位基础,在此基础上施加一个或几个修改器命令,使其变形生成新的三维模...
    zhoucanhui阅读 2,359评论 0 5
  • 腊肉是湖北、四川、湖南等很多地区的特产,已有几千年的历史 ,也是我家乡的特产之一。 每到冬季,家家...
    浅浅的简书阅读 395评论 0 0
  • 大年初一收到高中同学信息说要来找我,约在第二天下午见面,当时有点吃惊,高中毕业后我们还没见过面,只知道她在上海,平...
    越来悦幸福阅读 277评论 0 0

友情链接更多精彩内容