我到处寻找并尝试了各种方法,但无法解决这个问题。
如何将 xAxis 定位在折线图的底部?
在 viewDidLoad 中:
[self initChartProperties];
[self updateChartData:5];
initChart 属性:
- (void)initChartProperties2 {
_chartView.delegate = self;
_chartView.descriptionText = @"";
_chartView.noDataTextDescription = @"You need to provide data for the chart.";
_chartView.dragEnabled = YES;
_chartView.pinchZoomEnabled = YES;
_chartView.legend.enabled = NO;
[_chartView setScaleEnabled:YES];
_chartView.leftAxis.customAxisMax = 21;
_chartView.leftAxis.customAxisMin = 0;
_chartView.leftAxis.drawZeroLineEnabled = NO;
_chartView.leftAxis.enabled = YES;
_chartView.xAxis.axisLineWidth = 2.0f;
_chartView.xAxis.drawAxisLineEnabled = YES;
_chartView.rightAxis.enabled = NO;
[_chartView.viewPortHandler setMaximumScaleY: 2.f];
[_chartView.viewPortHandler setMaximumScaleX: 2.f];
}
更新图表数据:
- (void)updateChartData:(int)count {
NSMutableArray *xVals = [[NSMutableArray alloc] init];
NSMutableArray *yVals = [[NSMutableArray alloc] init];
for (int i = 0; i < count; i++) {
[xVals addObject:[@(i) stringValue]];
}
for (int i = 0; i < count; i++) {
[yVals addObject:[[ChartDataEntry alloc] initWithValue:i xIndex:i]];
}
LineChartDataSet *set1 = [[LineChartDataSet alloc] initWithYVals:yVals label:@""];
set1.lineWidth = 1.0;
set1.circleRadius = 0.0;
set1.drawCircleHoleEnabled = NO;
set1.valueFont = [UIFont fontWithName:@"HelveticaNeue-Light" size:9.0f];
NSMutableArray *dataSets = [[NSMutableArray alloc] init];
[dataSets addObject:set1];
LineChartData *data = [[LineChartData alloc] initWithXVals:xVals dataSets:dataSets];
_chartView.data = data;
}
结果:
line graph
我只想将 xAxis 值呈现在图形的底部,而不是顶部。
对不起,这个看似简单的问题。
感谢任何帮助。
最佳答案
没关系 - 终于想通了
_chartView.xAxis.labelPosition = XAxisLabelPositionBottom;
关于ios-charts - 折线图 - 在底部显示 x 轴,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35911926/