问题描述
我有数据,例如(1,3600),(2,4400),...(33,15000)在(1,3000)中-> 1是一个数字-> 3600是秒
I have data e.g. (1,3600), (2,4400), ... (33,15000)Where in (1,3000)-> 1 is a number-> 3600 is seconds
如果放置在图表中,则轴将显示秒"为数字.我设置了一个代码,以每隔1小时显示一次轴标签.
If put in chart, the axis would show the "second" as number.I have set a code to show axis label in 1 hour interval.
// 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 ...
So now the axis labels are: 0 ... 3600 ... 7200 ... 10.800 ...
如何使轴标签以小时显示? (0 ... 1 ... 2 ... 3 ...)
How to make the axis labels show in hours? (0 ... 1 ... 2 ... 3 ...)
推荐答案
一种方法是将数据缩放1000,以表示时代.然后,您可以将SimpleDateFormat
与合适的TimeZone
配合使用,以获得所需的效果.
One approach is to scale your data by 1000 to represent milliseconds from the epoch. Then you can use a SimpleDateFormat
with a suitable TimeZone
to get the desired effect.
DateAxis axis = new DateAxis("Hour");
SimpleDateFormat format = new SimpleDateFormat("H");
format.setTimeZone(TimeZone.getTimeZone("GMT"));
axis.setDateFormatOverride(format);
您可以尝试其他格式,例如"D:H".另外,也可以按1/3600缩放以表示小时,并使用带有整数刻度单位的NumberAxis
.
You can experiment with other formats, e.g. "D:H". Alternatively, scale by 1/3600 to represent hours and use a NumberAxis
with integer tick units.
NumberAxis axis = new NumberAxis();
axis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
这篇关于JFreeChart轴标签,以小时为单位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!