【问题标题】:JFreeChart XYPlot time series y value that intersects xJFreeChart XYPlot 与 x 相交的时间序列 y 值
【发布时间】:2016-11-19 01:41:00
【问题描述】:

我有一个时间序列图表,其中包含每天绘制的数据,但并非所有日期都有数据。在这种情况下,我如何确定/计算给定日期的 y 值。例如,在这个图表中,如何计算 x 为 01-Mar-2016 的 y 坐标?

我查看了类似的thread,但无法将其应用于上述要求。

【问题讨论】:

标签: jfreechart timeserieschart


【解决方案1】:

上面提到的线程实际上是我对 TimeSeries 进行一些调整所需要的。代码如下:

private static double interpolate(TimeSeries s, long x)
{
  List<?> items = s.getItems();
  for (int i=0; i<items.size()-1; i++)
  {
    TimeSeriesDataItem i0 = (TimeSeriesDataItem) items.get(i);
    TimeSeriesDataItem i1 = (TimeSeriesDataItem) items.get(i+1);
    long x0 = i0.getPeriod().getFirstMillisecond();
    double y0 = i0.getValue().doubleValue();
    long x1 = i1.getPeriod().getFirstMillisecond();
    double y1 = i1.getValue().doubleValue();

    if (x >= x0 && x <= x1)
    {
      double d = x - x0;
      double a = d / (x1-x0);
      double y = y0 + a * (y1 - y0);
      return y;
    }
 }

 // Should never happen
 return 0;

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-02
    • 2016-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多