This is a GREAT package. I'm planningto use it to plot statistical data from one of our machines (sampled every few minutes) and display it in a simple servlet. Right now, I'm trying to get the servlet code to plot basic stuff before I pull the data from a DB. I am having one problem...
It seems that the Plot of each point in a TimeSeriesChart that has data of type Minute is not exactly lined up with the grid, but seems to be aligned 0.5 units to the right. In my example, I was plotting a timeseries with values every 5 seconds and the grid lines on the plot were at 5 second intervals. The plot's datapoints seem to be at 5.5, 10.5, 15.5, etc. rather than at 5, 10, 15, etc. and therefore do not line up with the grid. Worse, if I call the setMinimumDate and setMaximumDate methods on the HorizontalDateAxis class, I get a 0.5 unit horizontal gap before the data begins and I lose the last datapoint as its outside the chart's plot.
Any clues? BTW- THANKS for the postings on the Minute and Second Timezone problems (I was having an AWEFUL time trying to get past that one). I used the simple solution of setting myself to UTC....
-------------------------------------------------
Here is my dataset definitiion (within the CreateTimeSeriesMinuteCollection method):
BasicTimeSeries t1 = new BasicTimeSeries("Stats Values", Second.class);
try {
t1.add(new Second(5, new Day(2, SerialDate.JANUARY, 2001)), new Double(5));
t1.add(new Second(10, new Day(2, SerialDate.JANUARY, 2001)), new Double(10));
t1.add(new Second(15, new Day(2, SerialDate.JANUARY, 2001)), new Double(5));
t1.add(new Second(20, new Day(2, SerialDate.JANUARY, 2001)), new Double(20));
t1.add(new Second(25, new Day(2, SerialDate.JANUARY, 2001)), new Double(5));
t1.add(new Second(30, new Day(2, SerialDate.JANUARY, 2001)), new Double(30));
t1.add(new Second(35, new Day(2, SerialDate.JANUARY, 2001)), new Double(5));
t1.add(new Second(40, new Day(2, SerialDate.JANUARY, 2001)), new Double(40));
t1.add(new Second(45, new Day(2, SerialDate.JANUARY, 2001)), new Double(5));
t1.add(new Second(50, new Day(2, SerialDate.JANUARY, 2001)), new Double(50));
t1.add(new Second(55, new Day(2, SerialDate.JANUARY, 2001)), new Double(5));
t1.add(new Second(60, new Day(2, SerialDate.JANUARY, 2001)), new Double(60));
Here is my chart code:
JFreeChart chart = null;
Plot myPlot;
Axis myVerticalAxis;
VerticalNumberAxis vnAxis;
HorizontalDateAxis hzAxis;
PlotFit pf;
XYDataset xyData = null;
HorizontalDateAxis timeAxis = null;
NumberAxis valueAxis = null;
MovingAveragePlotFitAlgorithm mavg = null;
xyData = createTimeSeriesMinuteCollection(); // gets the data above
mavg = new MovingAveragePlotFitAlgorithm();
mavg.setPeriod(5);
pf = new PlotFit(xyData, mavg);
xyData = pf.getFit();
chart = ChartFactory.createTimeSeriesChart("Moving Average", "Stats From mm-mm", "Value", xyData, true);
chart.setBackgroundPaint(new GradientPaint(0, 0, getColor( initGradColor ), 1000, 0, getColor( finalGradColor )));
myPlot = chart.getPlot();
myVerticalAxis = myPlot.getAxis(Axis.VERTICAL);
myVerticalAxis.setLabel("Some Useless Stats");
vnAxis = (VerticalNumberAxis)chart.getPlot().getAxis(Axis.VERTICAL);
vnAxis.setAutoRangeIncludesZero(false);
hzAxis = (HorizontalDateAxis)chart.getPlot().getAxis(Axis.HORIZONTAL);
hzAxis.setVerticalTickLabels(true);
hzAxis.setMinimumDate(createDateTime(2001, 0, 2, 0, 0));
hzAxis.setMaximumDate(createDateTime(2001, 0, 2, 1, 0));
chart.setDataset(xyData);
return chart;
Timeseries Plot Not Lined Up With Grid
Re: Timeseries Plot Not Lined Up With Grid
I have a feeling that the HorizontalDateAxis is putting the tick labels at the *start* of each time unit, whereas the TimePeriod classes return the middle millisecond for their x-values. I'll have to spend some time looking at it though (hopefully on Monday).
If you are in a hurry to fix it, the method that is most important for the tick unit placement is the DateAxis.previousStandardDate(...) method...
Regards,
DG.
If you are in a hurry to fix it, the method that is most important for the tick unit placement is the DateAxis.previousStandardDate(...) method...
Regards,
DG.
Re: Timeseries Plot Not Lined Up With Grid
I thought this may be where the problem is, but I also noticed that the background grid is lined up with the tick labels and therefore the plot seems to be off. My guess is that if there is a problem in the DateAxis methods, there is also a similar problem in the background grid methods (wherever they are generated). I'll spend some time playing with it today (Monday) also and let you know if I find a solution. If you find anything, please let me know.
Thanks.
- Nick
Thanks.
- Nick
Re: Timeseries Plot Not Lined Up With Grid
At the moment the grid is controlled by the axis object(s), so it is the same problem.
I'm thinking of putting the grid settings in the plot class, because that's where most people would expect to find them...but of course then the plot object would have to ask the axis object(s) to provide a list of tick values so that it could draw the grid lines. It was to avoid passing all that information around that I originally wrote the grid line drawing as part of the axis class...but now I think that was a (minor) mistake.
Regards,
DG.
I'm thinking of putting the grid settings in the plot class, because that's where most people would expect to find them...but of course then the plot object would have to ask the axis object(s) to provide a list of tick values so that it could draw the grid lines. It was to avoid passing all that information around that I originally wrote the grid line drawing as part of the axis class...but now I think that was a (minor) mistake.
Regards,
DG.
Re: Timeseries Plot Not Lined Up With Grid
I FINALLY figured this out. Apparently, the Minute is being calculated by the TimeSeriesCollection.getXValue() method which returns a value using the Minute's getMiddle() method. This is why everything was 30 seconds off! I'm not sure if there is a better solution here, but for now I changed it to use the 'getStart()' method as an alternative. This may have other implications, but I don't think they will concern me right now.
Thanks for the pointers.
- Nick
Thanks for the pointers.
- Nick