JFreeChart轴标签,以小时为单位 [英] JFreeChart axis label in Hours

查看:126
本文介绍了JFreeChart轴标签,以小时为单位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有数据,例如(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,以表示

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);

小时数限制在0到23之间,您知道如何克服吗?

The hours are limited to between 0 and 23, any idea how to overcome this?

您可以尝试其他格式,例如"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轴标签,以小时为单位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆