我正在使用优秀的 JBChartView
在我的项目中,它运行良好。这是我当前的代码:
self.lineChart = [[JBLineChartView alloc] initWithFrame:CGRectMake(320, 400, 680, 300)];
self.lineChart.dataSource = self;
self.lineChart.delegate = self;
self.lineChart.backgroundColor = [UIColor clearColor];
JBLineChartFooterView *footerView = [[JBLineChartFooterView alloc] initWithFrame:CGRectMake(10, ceil(self.view.bounds.size.height * 0.5) - ceil(10 * 0.5), self.view.bounds.size.width - (10 * 2), 10)];
footerView.backgroundColor = [UIColor clearColor];
footerView.leftLabel.text = @"yesterday";
footerView.leftLabel.textColor = [UIColor whiteColor];
footerView.rightLabel.text = @"now";
footerView.rightLabel.textColor = [UIColor whiteColor];
footerView.sectionCount = 10;
self.lineChart.footerView = footerView;
[self.view addSubview:self.lineChart];
[self.lineChart setState:JBChartViewStateCollapsed animated:YES];
没什么特别的,真的。
JBChartView 根据 lineChartView: heightForIndex:
中传递给它的数据自动选择 Y 轴刻度。这在大多数情况下都很好。然而,我的数据是关于 CPU 使用率的,因此我想强制 Y 轴在底部始终为 0,在顶部始终为 100。
实际上,我希望底部为 0,顶部为 MAX(100, highestPoint)
(因为 CPU 使用率有时会超过 100%)- 这可能吗?
最佳答案
截至v2.2.1 , JBChartView 允许您为 y 轴提供 minimumValue 和/或 maximumValue。
注意事项:
- 如果未提供任何值,则使用图表数据源的最小值和最大值。
- 如果提供值,则它们必须 >= 0,否则将抛出断言。
- 最小/最大值限制在图表数据源的实际最小/最大值的上限和下限。
- 例如,如果提供的最大值为 20,而图表的实际最大值为 100,则将使用 100。
- 最后,要使最小/最大修改生效,必须调用 reloadData。
希望这对您有所帮助!
关于ios - 强制 JBChartView 使用 0-100 Y 轴,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22079773/