Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

为什么我设置X轴不显示 #3456

Closed
zp19900223zp opened this issue May 16, 2018 · 4 comments
Closed

为什么我设置X轴不显示 #3456

zp19900223zp opened this issue May 16, 2018 · 4 comments

Comments

@zp19900223zp
Copy link

NSArray *xVals = @[@"2017-12",@"2018-12",@"2018-12",@"2018-12",@"2018-12",@"2018-12",@"2018-12",@"2018-12",@"2018-12",@"2018-12",@"2018-12",@"2018-12"];
ChartXAxis *xAxis = _chartView.xAxis;
xAxis.labelPosition = XAxisLabelPositionBottom;
xAxis.labelFont = [UIFont systemFontOfSize:10];
xAxis.labelCount = xVals.count;
xAxis.valueFormatter = [[ChartIndexAxisValueFormatter alloc] initWithValues:xVals];
xAxis.gridLineDashLengths = @[@5.0, @5.0];

@zp19900223zp
Copy link
Author

使用CocoaPods安装的Charts

@liuxuan30
Copy link
Member

ask on stack overflow.

@zp19900223zp
Copy link
Author

能具体说明一下吗?

@SoftBoys
Copy link

设置X轴数据格式

xAxis.valueFormatter = [JL_DateFormatter new];

实现代理方法

@interface JL_DateFormatter : NSObject <IChartAxisValueFormatter>
@end

@implementation JL_DateFormatter
#pragma mark - IChartAxisValueFormatter
// 返回x轴显示内容
- (NSString *)stringForValue:(double)value axis:(ChartAxisBase *)axis {
    return [[NSDate dateWithTimeIntervalSince1970:value] stringWithFormat:@"MM-dd"];
}
@end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants