以小时为单位的 JFreeChart 轴标签
JFreeChart axis label in Hours
我有数据,例如(1,3600), (2,4400), ... (33,15000)
哪里 (1,3000)
-> 1 是一个数字
-> 3600 是秒
如果放在图表中,轴将显示 "second" 作为数字。
我已经设置了一个代码,以 1 小时为间隔显示轴标签。
// Create an NumberAxis
NumberAxis xAxis = new NumberAxis();
xAxis.setTickUnit(new NumberTickUnit(3600));
// Assign it to the chart
xyPlot.setDomainAxis(xAxis);
所以现在轴标签是:0 ... 3600 ... 7200 ... 10.800 ...
如何让轴标签以小时为单位显示? (0 ... 1 ... 2 ... 3 ...)
一种方法是将数据缩放 1000 以表示距 epoch 的毫秒数。然后你可以使用一个 SimpleDateFormat
和一个合适的 TimeZone
来获得想要的效果。
DateAxis axis = new DateAxis("Hour");
SimpleDateFormat format = new SimpleDateFormat("H");
format.setTimeZone(TimeZone.getTimeZone("GMT"));
axis.setDateFormatOverride(format);
The hours are limited to between 0 and 23, any idea how to overcome this?
您可以尝试其他格式,例如"D:H"。或者,按 1/3600 缩放以表示小时,并使用带有整数刻度单位的 NumberAxis
。
NumberAxis axis = new NumberAxis();
axis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
我有数据,例如(1,3600), (2,4400), ... (33,15000) 哪里 (1,3000) -> 1 是一个数字 -> 3600 是秒
如果放在图表中,轴将显示 "second" 作为数字。 我已经设置了一个代码,以 1 小时为间隔显示轴标签。
// Create an NumberAxis
NumberAxis xAxis = new NumberAxis();
xAxis.setTickUnit(new NumberTickUnit(3600));
// Assign it to the chart
xyPlot.setDomainAxis(xAxis);
所以现在轴标签是:0 ... 3600 ... 7200 ... 10.800 ...
如何让轴标签以小时为单位显示? (0 ... 1 ... 2 ... 3 ...)
一种方法是将数据缩放 1000 以表示距 epoch 的毫秒数。然后你可以使用一个 SimpleDateFormat
和一个合适的 TimeZone
来获得想要的效果。
DateAxis axis = new DateAxis("Hour");
SimpleDateFormat format = new SimpleDateFormat("H");
format.setTimeZone(TimeZone.getTimeZone("GMT"));
axis.setDateFormatOverride(format);
The hours are limited to between 0 and 23, any idea how to overcome this?
您可以尝试其他格式,例如"D:H"。或者,按 1/3600 缩放以表示小时,并使用带有整数刻度单位的 NumberAxis
。
NumberAxis axis = new NumberAxis();
axis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());