Giter Site home page Giter Site logo

lewbarchart's Introduction

LewBarChart

iOS 柱状图,支持多个 Y 轴坐标

效果图

效果图

使用方法

_barChart = [[LewBarChart alloc]initWithFrame:CGRectMake(0, 145, SCREEN_WIDTH, 200)];

// 生成数据
NSMutableArray *yVals1 = [[NSMutableArray alloc] init];
NSMutableArray *yVals2 = [[NSMutableArray alloc] init];
    
double mult = 5 * 1000.f;
for (int i = 0; i < 5; i++){
   double val = (double) (arc4random_uniform(mult) + 3.0);
   [yVals1 addObject:@(val)];
   
   val = (double) (arc4random_uniform(mult) + 3.0);
   [yVals2 addObject:@(val)];
}
    
LewBarChartDataSet *set1 = [[LewBarChartDataSet alloc] initWithYValues:yVals1 label:@"报名人数"];
[set1 setBarColor:[UIColor colorWithRed:77.0 / 255.0 green:186.0 / 255.0 blue:122.0 / 255.0 alpha:1.0f]];
LewBarChartDataSet *set2 = [[LewBarChartDataSet alloc] initWithYValues:yVals2 label:@"实到人数"];
[set2 setBarColor:[UIColor colorWithRed:245.0 / 255.0 green:94.0 / 255.0 blue:78.0 / 255.0 alpha:1.0f]];
    
NSMutableArray *dataSets = [[NSMutableArray alloc] init];
[dataSets addObject:set1];
[dataSets addObject:set2];
    
LewBarChartData *data = [[LewBarChartData alloc] initWithDataSets:dataSets];
data.xLabels = @[@"项目名称1",@"项目名称2",@"项目名称3",@"项目名称4",@"项目名称5"];
data.itemSpace = 6;

// 设置柱状图
_barChart.data = data;
_barChart.displayAnimated = YES;
_barChart.chartMargin = UIEdgeInsetsMake(20, 15, 45, 15);
_barChart.showYAxis = NO;
_barChart.showNumber = YES;
_barChart.legendView.alignment = LegendAlignmentHorizontal;
    
[self.view addSubview:_barChart];
[_barChart show];
    
// 设置图例位置
CGPoint legendCenter = CGPointMake(SCREEN_WIDTH-_barChart.legendView.bounds.size.width/2, -18);
_barChart.legendView.center = legendCenter;

License | 许可

This code is distributed under the terms of the MIT license.
代码使用 MIT license 许可发布.

lewbarchart's People

Contributors

pljhonglu avatar

Watchers

James Cloos avatar  avatar

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.