gpt4 book ai didi

ios-charts - 折线图 - 在底部显示 x 轴

转载 作者:行者123 更新时间:2023-12-01 12:29:16 26 4
gpt4 key购买 nike

我到处看了看并尝试了各种方法,但无法解决这个问题。如何将 xAxis 定位在折线图的底部?

在viewDidLoad中:

[self initChartProperties];
[self updateChartData:5];

初始化图表属性:

- (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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com