2016-11-19 11 views
0

私はデータを毎日プロットしていますが、すべての日にデータがあるわけではありません。このシナリオでは、どのようにして特定の日付のy値を決定/計算できますか。たとえば、この図では、xは2016年3月1日のy座標をどのように計算できますか?JFreeChart XYPlot時系列yの値x

chart

私は似たthreadを見ていたが、私は上記の要件にそれを適用できませんでした。

+0

あなたは[_interpolation_](http://stackoverflow.com/search?q=user%3A230513+%5Bjfreechart%5D+interpolation)を試してみましたか? – trashgod

答えて

0

上記のスレッドは、実際に私が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; 

}