在 jfreechart 中缩小后恢复手动域轴范围
我正在使用 JFreeChart 在我的应用程序中创建时间序列图表。
我使用手动设置它的域轴范围:
...
plot.getDomainAxis().setAutoRange(false);
Calendar c1=Calendar.getInstance();
c1.set(Calendar.HOUR_OF_DAY, 10);
c1.set(Calendar.MINUTE, 0);
Calendar c2=Calendar.getInstance();
c2.set(Calendar.HOUR_OF_DAY, 18);
c2.set(Calendar.MINUTE, 0);
plot.getDomainAxis().setRange(c1.getTimeInMillis(),c2.getTimeInMillis());
...
放大图表然后缩小(在图表本身上使用鼠标)会触发两个轴上的 AutoRange
,这使得域轴范围更改为系列边界而不是我的自己的手动愤怒。
示例(查看域轴的范围):
放大缩小之前(正确):
放大后(不正确 - 是自动调整范围):
如何使其缩小到我手动设置的范围?
谢谢
I'm using JFreeChart to create a timeseries chart in my application.
I'm setting it's domain axis range manually using:
...
plot.getDomainAxis().setAutoRange(false);
Calendar c1=Calendar.getInstance();
c1.set(Calendar.HOUR_OF_DAY, 10);
c1.set(Calendar.MINUTE, 0);
Calendar c2=Calendar.getInstance();
c2.set(Calendar.HOUR_OF_DAY, 18);
c2.set(Calendar.MINUTE, 0);
plot.getDomainAxis().setRange(c1.getTimeInMillis(),c2.getTimeInMillis());
...
Zooming in to chart and then zooming out (Using mouse on chartplot itself) triggers AutoRange
on both axis that makes Domain axis range change to series borders and not my own manual rages.
Example (Look at Domain axis's range):
Before zooming in-out (Correct):
After zooming in-out (Incorrect-is Auto ranged):
How can I make it to zoom out to my manually set range?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以尝试
RestoreAutoBounds()
,如图 此处,然后是您的自定义域设置。附录:您看到的行为是在
图表面板
。当图表完成绘制且未缩放时,您可以覆盖chartProgress()
并恢复域轴。You might try
restoreAutoBounds()
, shown here, followed by your custom domain setting.Addendum: The behavior you see is defined in the mouse listener implementation of
ChartPanel
. You could overridechartProgress()
and restore your domain axis when the chart is finished drawing and not zoomed.这里有一个解决方案:
创建一个 MyNumberAxis 实例,将布尔值设置为 true 并在绘图中使用它(plot.setRangeAxis() 方法)。如果您希望表现得像默认的 NumberAxis,请将 false 作为布尔值传递。
here a solution:
Create an instance of MyNumberAxis setting the boolean to true and use it in your plot (plot.setRangeAxis() method). If you want to behave like the default NumberAxis, pass false as boolean.
Magallo 的上述解决方案效果很好。我发现如果添加另一个构造函数它会更有用:
Magallo's solution above worked great. I found it even more useful if I added another constructor:
我创建了一个具有固定范围的自定义 NumberAxis。缩小会自动缩放到这个固定范围。
I created a custom NumberAxis with a fixed range. Zooming out will auto-zoom to this fixed range.