title: JFreeChart: DynamicTimeSeries with period of n milliseconds
body: <p>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 interface. Of course the period of the plot should change according to the period defined by the user.
  So I started to define the followint Chart:</p>
  
  <pre><code>int periodMs = 200;
  MilliDTSC dataset = new MilliDTSC(1,100, new MultipleOfMillisecond(periodMs));
  dataset.setTimeBase(new MultipleOfMillisecond(periodMs))
  dataset.addSeries(zeroSeries()),0,"Zero data") // zeroSeries returs a series with values set to 0
  JFreeChart chart = createChart(dataset) // create the chart and set ranges and legends
  ChartPanel panel = new ChartPanel(panel);
  </code></pre>
  
  <p><code>MilliDTSC</code> is the following class, as suggested <a href="https://stackoverflow.com/questions/6850326/jfreechart-dynamictimeseriescollection-with-a-period-of-n-milliseconds/6850925#6850925">here</a>:</p>
  
  <pre><code>public class MilliDTSC extends DynamicTimeSeriesCollection{
    public MilliDTSC(int nSeries, int nMoments, RegularTimePeriod timeSample){
      super(nSeries, nMoments, timeSample);
      if(timeSample instanceof Millisecond)
        this.pointsInTime = new Millisecond[nMoments]
      else if (timeSample instanceof MultipleOfMillisecond)
        this.pointsInTime = new MultipleOfMillisecond[nMoments]
    }
  }
  </code></pre>
  
  <p><code>MultipleOfMillisecond</code> is the following class:</p>
  
  <pre><code>public class MultipleOfMilliseconds extends Millisecond{
    MulitpleOfMilliseconds(int periodMs){
      this.periodMs = periodMs
    }
  
    public RegularTimePeriod previous(){
      RegularTimePeriod result = null;
      if(getMillisecond() - periodMs &gt;= FIRST_MILLISECOND_IN_SECOND)
        result = new Millisecond((int)getMillisecond - periodMs, getSecond());
      else{
        Second previous = (Second)getSecond().previous();
        if(previous!=null)
          result = new Millisecond((int)(getMillisecond() - periodMS + LAST_MILLISECOND_IN_SECOND + 1), previous);
      }
      return result;
    }
    // similar for next()
  }
  </code></pre>
  
  <p>I add sample to the series in the following way:</p>
  
  <pre><code>dataset.advanceTime();
  dataset.appendData(newData);
  </code></pre>
  
  <p>What I expected is that once I fixed the period to 200 ms the chart reports on the X label more or less 5 time values: </p>
  
  <pre><code>00:00:00.000 00:00:05.000 00:00:10.000 00:00:15.000 00:00:20.000
  </code></pre>
  
  <p>And I expected 25 samples in each "space".</p>
  
  <p>What happen instead is that I have 25 samples for each "space" but the chart reports the following values on the X label:</p>
  
  <pre><code>00:00:00.000 00:00:00.025 00:00:00.050 00:00:00.075 00:00:00.100
  </code></pre>
  
  <p>It seems that the period is 1ms but I'm adding samples very 200 ms.</p>
  
  <p>How can I solve the problem?
  If I was not clear pleas tell me.
  Thanks!!</p>