JFreeChart: DynamicTimeSeries with period of n milliseconds

前端 未结 3 1182
栀梦
栀梦 2020-12-04 00:40

I\'m trying do define an interface in which I want to plot some values received by an external device. These values are received with a frequency that can be set through the

3条回答
  •  攒了一身酷
    2020-12-04 01:08

    This is the solution I implemented. I reported only the methods that I changed. It was a stupid error :D

    public MilliDTSC(int nSeries, int nMoments, RegularTimePeriod timeSample) {
      super(nSeries, nMoments, timeSample);
      if(timeSample instanceof MultipleOfMillisecond){
        this.pointsInTime = new MultipleOfMillisecond[nMoments];
      }else if (timeSample instanceof Millisecond) {
        this.pointsInTime = new Millisecond[nMoments];
      } 
    }
    
    public class MultipleOfMillisecond extends Millisecond {
    
      private static final long serialVersionUID = 1L;
      private int periodMs = 100;
    
      public MultipleOfMillisecond(int periodMs){
        super();
        this.periodMs = periodMs;
      }
    
      public MultipleOfMillisecond(int periodMs, int millisecond, Second second){
        super(millisecond, second);
        this.periodMs = periodMs;
      }
    
      @Override
      public RegularTimePeriod next() {
        
        RegularTimePeriod result = null;
        if(getMillisecond() + periodMs <= LAST_MILLISECOND_IN_SECOND){
            result = new MultipleOfMillisecond( periodMs, (int)(getMillisecond() + periodMs), getSecond());
        }else{
            Second next = (Second)getSecond().next();
            if(next != null){
                result = new MultipleOfMillisecond(periodMs, (int)(getMillisecond() + periodMs - LAST_MILLISECOND_IN_SECOND - 1), next);
            }
        }
        return result;
        
      }
    
      @Override
      public RegularTimePeriod previous() {
        
        RegularTimePeriod result = null;
        if(getMillisecond() - periodMs >= FIRST_MILLISECOND_IN_SECOND){
            result = new MultipleOfMillisecond(periodMs, (int)getMillisecond() - periodMs, getSecond());
        }else{
            Second previous = (Second)getSecond().previous();
            if(previous != null){
                result = new MultipleOfMillisecond(periodMs, (int)(getMillisecond() - periodMs + LAST_MILLISECOND_IN_SECOND + 1), previous);
            }
        }
        return result;
        
      } 
    }
    

    Now I have 10 samples in 5 seconds, i set the period to 500 ms

    Now I have 10 samples in 5 seconds, i set the period to 500 ms

提交回复
热议问题