切换 JFreeChart 轴范围的上限
我有一个图表,显示已完成的任务数量与时间的关系。在 Y 轴上,始终包含 0,并且有一个固定值,该值将是最大任务数。随着时间的推移,级数线攀升至最大值。这一切我都能做到。
我想要做的是允许用户在 Y 轴从 0 到 MAX 和 0 到自动范围值之间切换。这样,当它们距离最大值还很远时,它们就可以只放大数据,而不会使图表的上半部分为空。
JFreeChart chart = ChartFactory.createTimeSeriesChart("", "", "Progress", dataset, false, true, false);
XYPlot plot = chart.getXYPlot();
plot.getRangeAxis().setRange(new Range(0, TOTAL), false, true);
该行允许我显示整个值范围,但我无法设法将范围恢复为自动值,该值将上限设置为略高于系列中的最大值(如果您不这样做,它将呈现的方式)根本不设置范围)。
I have a chart that graphs number of tasks completed versus time. On the Y-axis, 0 is always included and there is a fixed value that will be the maximum number of tasks. As time progresses, the line of the series climbs up to the maximum value. I can do all this.
What I want to be able to do is allow the user to switch between the Y-axis going from 0 to MAX and 0 to the auto range value. This way they can be zoomed in on just the data and not have the upper half of the graph empty when they are still far from the maximum value.
JFreeChart chart = ChartFactory.createTimeSeriesChart("", "", "Progress", dataset, false, true, false);
XYPlot plot = chart.getXYPlot();
plot.getRangeAxis().setRange(new Range(0, TOTAL), false, true);
That line allows me to show the entire value range, but I can't manage to get the range back to the auto value that sets the upper bound to just higher than the largest value in the series (The way it would render if you don't set the range at all).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
作为一种权宜之计,您可以保留默认的范围:
然后恢复它:
基于
org.jfree.chart.demo.TimeSeriesChartDemo1
。As an expedient, you can preserve the default
Range
:and later restore it:
Notional example based on
org.jfree.chart.demo.TimeSeriesChartDemo1
.