ios - 强制 JBChartView 使用 0-100 Y 轴

标签 ios jbchartview

我正在使用优秀的 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 和/或 ma​​ximumValue

注意事项:

  • 如果未提供任何值,则使用图表数据源的最小值和最大值。
  • 如果提供值,则它们必须 >= 0,否则将抛出断言。
  • 最小/最大值限制在图表数据源的实际最小/最大值的上限和下限。
  • 例如,如果提供的最大值为 20,而图表的实际最大值为 100,则将使用 100。
  • 最后,要使最小/最大修改生效,必须调用 reloadData。

希望这对您有所帮助!

关于ios - 强制 JBChartView 使用 0-100 Y 轴,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22079773/

相关文章:

ios - 在 iOS 上创建具有任意 X 轴样本位置的折线图

ios - NSMutableArray 不在图表上显示数据

ios - 使用 JBChartView 库的分组条形图

ios - Swift 2.0 beta 词典扩展

ios - 通过比较字符串值快速对数组进行排序

iOS GHUnit 和核心数据

ios - UICollectionView 中的 IBOutlets 为 nil - Swift

ios - 如何截断 UITableView Cell TextLabel 中的文本,使其不隐藏 DetailTextLabel?