【问题标题】:How to add date in the form of DD/MM/YYYY hh:mm:ss to the X-axis of a TimeSeries graph using jfreechart?如何使用 jfreechart 以 DD/MM/YYYY hh:mm:ss 的形式将日期添加到 TimeSeries 图的 X 轴?
【发布时间】:2014-07-10 04:51:57
【问题描述】:

我正在尝试制作一个图表,显示最小和最大 CPU 使用率以及特定应用程序在 30 天内出现峰值的时间。日期很容易在 X 轴上获得,但是,当我放大时,默认情况下,与数据点对应的所有工具提示都被赋予其对应日期的上午 12 点的时间戳。如何将此默认时间更改为所需的时间戳?

这是一个截图供您参考:

有没有办法以 DD/MM/YYYY HH:mm:SS 格式将日期和时间添加到 X 轴?

提前感谢您的帮助!

克里提

【问题讨论】:

  • 交叉发布here

标签: datetime tooltip time-series jfreechart


【解决方案1】:

正如here 所述,StandardXYToolTipGenerator 使用DateFormat.getInstance() 表示日期,这类似于我的Locale 中的MM-dd-yyyy HH:mm:ss。确保您添加的值具有所需的分辨率,如 here 使用 new Second() 所示。

【讨论】:

    【解决方案2】:

    您可以通过在绘图轴上调用setDateFormatOverride() 来覆盖格式。

    在您的情况下,它看起来像这样。

    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("DD/MM/YYYY HH:mm:SS"));
    

    查看SimpleDateFormat 了解更多时间格式。

    【讨论】:

      猜你喜欢
      • 2013-11-01
      • 1970-01-01
      • 2015-11-03
      • 2020-03-07
      • 2018-06-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-01
      相关资源
      最近更新 更多