2016-11-19 1 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; 

가}