项目简介
一行代码图表库,应用于iOS。
截屏
安装FSLineChart
添加FSLineChart项目的组件到你的项目目录,开题报告,或者直接添加下面内容到你的Podfile:
pod "FSLineChart"
如何使用
FSLineChart是一个UIView的子类,论文,所以它可以作为一个平常的视图而被添加。块结构能够让你格式化数值,然后以你想要的方式展示在图表上。下面是一个简单的例子:
NSArray* months = @[@"January", @"February", @"March", @"April", @"May", @"June", @"July"];
FSLineChart* lineChart = [[FSLineChart alloc] initWithFrame:frame];
lineChart.labelForIndex = ^(NSUInteger item) {
return months[item];};
lineChart.labelForValue = ^(CGFloat value) {
return [NSString stringWithFormat:@'%.02f €', powf(10,value)];};
[lineChart setChartData:chartData];
你也可以设置几个参数。一些参数(包括color 和fillColor )必须在调用setChartData 方法之前设置。所有的属性可以这样设置:
// Index label properties
@property (copy) FSLabelForIndexGetter labelForIndex;
@property (nonatomic, strong) UIFont* indexLabelFont;
@property (nonatomic) UIColor* indexLabelTextColor;
@property (nonatomic) UIColor* indexLabelBackgroundColor;
// Value label properties
@property (copy) FSLabelForValueGetter labelForValue;
@property (nonatomic, strong) UIFont* valueLabelFont;
@property (nonatomic) UIColor* valueLabelTextColor;
@property (nonatomic) UIColor* valueLabelBackgroundColor;
@property (nonatomic) ValueLabelPositionType valueLabelPosition;
// Number of visible step in the chart
@property (nonatomic) int gridStep;
@property (nonatomic) int verticalGridStep;
@property (nonatomic) int horizontalGridStep;
// Margin of the chart
@property (nonatomic) CGFloat margin;
@property (nonatomic) CGFloat axisWidth;
@property (nonatomic) CGFloat axisHeight;
// Decoration parameters, let you pick the color of the line as well as the color of the axis
@property (nonatomic, strong) UIColor* axisColor;
@property (nonatomic) CGFloat axisLineWidth;
// Chart parameters
@property (nonatomic, strong) UIColor* color;
@property (nonatomic, strong) UIColor* fillColor;
@property (nonatomic) CGFloat lineWidth;
// Data points
@property (nonatomic) BOOL displayDataPoint;
@property (nonatomic, strong) UIColor* dataPointColor;
@property (nonatomic, strong) UIColor* dataPointBackgroundColor;
@property (nonatomic) CGFloat dataPointRadius;
// Grid parameters
@property (nonatomic) BOOL drawInnerGrid;
@property (nonatomic, strong) UIColor* innerGridColor;
@property (nonatomic) CGFloat innerGridLineWidth;
// Smoothing
@property (nonatomic) BOOL bezierSmoothing;
@property (nonatomic) CGFloat bezierSmoothingTension;
// Animations
@property (nonatomic) CGFloat animationDuration;
github地址:https://github.com/ArthurGuibert/FSLineChart