0

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 根据传入的数据自动选择 Y 轴刻度lineChartView: heightForIndex:。这在大多数情况下都很好。但是,我的数据是关于 CPU 使用率的,因此我想强制 Y 轴在底部始终为 0,在顶部始终为 100。

实际上,我希望它在底部和MAX(100, highestPoint)顶部都为 0(因为 CPU 使用率有时可能超过 100%) - 这可能吗?

4

2 回答 2

4

v2.2.1开始,JBChartView 允许您为 y 轴提供minimumValue和/或maximumValue

笔记:

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

希望这可以帮助!

于 2014-04-03T00:10:17.760 回答
0

事实证明,我需要做的就是修改JBLineChartView.m 的第 240 行

self.cachedMaxHeight = maxHeight;

说:

self.cachedMaxHeight = MAX(100,maxHeight);
于 2014-02-27T21:07:47.253 回答