Giter VIP home page Giter VIP logo

llbarchart's Introduction

LLBarChart

Demo效果如下:

LLBarChart.gif

创建试图方法如下:

    NSArray *xLabels = @[@"Python", @"iOS", @"Java", @"C", @"C++", @"Android"];
    NSArray *yLabels = @[@20, @40, @60, @80, @100];
    NSArray *dataArray = @[@0, @30, @38, @100, @90, @50];
    
    _barChart = [[LLBarChart alloc] initWithFrame:CGRectMake(30, 100, 300, 300) offset:CGSizeMake(10, 7)];
    _barChart.xLabels = xLabels;
    _barChart.yLabels = yLabels;
    _barChart.dataArray = dataArray;
    _barChart.ySuffix = @"人";
    _barChart.barWidth = 30;
    _barChart.barBlank = 30;
    _barChart.delegate = self;
    _barChart.needAnimation = YES;
    [self.view addSubview:_barChart];

调用开始动画的方法一共有三种,任意一种都可以,最后一种除支持设置动画时间外,还支持动画完成回调:

/**
 * @brief 开始动画
 * @param duration 动画时间
 * @param completion 动画完成回调
 */
- (void)startAnimate;

- (void)startAnimateWithDuration:(NSTimeInterval)duration;

- (void)startAnimateWithDuration:(NSTimeInterval)duration completion:(void (^ __nullable)())completion;

点击bar的回调方法如下:

// 需要先设置delegate
- (void)barChartDidSelected:(LLBarChart *)barChart bar:(LLBar *)bar {
NSLog(@"点击柱形图回调");
}

详细API接口如下:

NS_ASSUME_NONNULL_BEGIN

@class LLBarChart;
@class LLBar;

@protocol LLBarChartDelegate <NSObject>

// 点击回调
- (void)barChartDidSelected:(LLBarChart *)barChart bar:(LLBar *)bar;

@end

@interface LLBarChart : UIView

/**
 * @brief init Method
 * @param offset offset.width y轴的偏移量
                 offset.height x轴的偏移量
 */
- (instancetype)initWithFrame:(CGRect)frame offset:(CGSize)offset;

// LLBarChartDelegate
@property (nonatomic, weak) id <LLBarChartDelegate>delegate;
// 渐变背景
@property (nonatomic, strong, readonly) CAGradientLayer *gradientLayer;
// x轴显示坐标内容(任意内容)
@property (nonatomic, strong) NSArray <NSString *>*xLabels;
// x轴显示坐标内容(具体值)
@property (nonatomic, strong) NSArray <NSNumber *>*yLabels;
// 数据源
@property (nonatomic, strong) NSArray <NSNumber *>*dataArray;
// y轴坐标后缀
@property (nonatomic, copy) NSString *ySuffix;
// bar宽度
@property (nonatomic, assign) CGFloat barWidth;
// bar之间的空隙
@property (nonatomic, assign) CGFloat barBlank;
// 是否需要动画显示(default is NO)
@property (nonatomic, assign) BOOL needAnimation;

/**
 * @brief 开始动画
 * @param duration 动画时间
 * @param completion 动画完成回调
 */
- (void)startAnimate;

- (void)startAnimateWithDuration:(NSTimeInterval)duration;

- (void)startAnimateWithDuration:(NSTimeInterval)duration completion:(void (^ __nullable)())completion;

@end

NS_ASSUME_NONNULL_END

llbarchart's People

Contributors

pipedog avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

wymann

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.