I noticed that in a XYPlot if all the values in a
TimeSeries are same and greater than 66666666
(approximately), and the chart has only one series,
graph does not get plotted.
[code]
public class TestLineChart extends ChartPanel
{
public static SimpleDateFormat DATE_FORMAT = new
SimpleDateFormat("MM:dd:yyyy hh:mm:ss a z");
public static NumberFormat DECIMAL_FORMAT = new
DecimalFormat("0.00");
public TestLineChart(JFreeChart jfc)
{
super(jfc);
}
/**
* @param seriesName
* @param xValues
* @param yValues
*/
public synchronized void addSeries(String
seriesName, String seriesDescr, double[] xValues,
double[] yValues)
{
TimeSeries series = new TimeSeries(seriesName,
Minute.class);
series.setDescription(seriesDescr);
for (int j = 0; j < xValues.length; j++)
{
double xValue = xValues[j];
double yValue = yValues[j];
if( xValue <= 0 )
{
break;
}
// Date date = new Date();
// date.setTime((long) xValue);
Date date = new Date((long) xValue);
try
{
if( yValue >= 0 )
{
series.add(new Minute(date), yValue);
}
else
{
series.add(new Minute(date), null);
}
}
catch (Exception e)
{
}
}
((TimeSeriesCollection)
getChart().getXYPlot().getDataset()).addSeries(series);
}
/**
*
*/
private static final long serialVersionUID = 1L;
public static void main(String[] args)
{
TimeSeriesCollection timeseriescollection = new
TimeSeriesCollection();
JFreeChart jfreechart =
ChartFactory.createTimeSeriesChart(
"Test LineChart", "Time", "Value",
timeseriescollection, true, true, false);
jfreechart.setBackgroundPaint(Color.white);
XYPlot xyPlot = jfreechart.getXYPlot();
xyPlot.setOrientation(PlotOrientation.VERTICAL);
xyPlot.setBackgroundPaint(Color.white);
xyPlot.setDomainGridlinePaint(Color.lightGray);
xyPlot.setRangeGridlinePaint(Color.lightGray);
xyPlot.setAxisOffset(new RectangleInsets(5D,
5D, 5D, 5D));
xyPlot.setRangeGridlinesVisible(true);
xyPlot.setDomainGridlinesVisible(true);
DateAxis dateAxis = new DateAxis("Time");
dateAxis.setDateFormatOverride(new
SimpleDateFormat("yyyy MMM dd HH:mm"));
dateAxis.setVerticalTickLabels(true);
xyPlot.setDomainAxis(dateAxis);
XYToolTipGenerator xyTooltipGenerator = new
StandardXYToolTipGenerator("{0}: Date = {1}, Value =
{2}", DATE_FORMAT, DECIMAL_FORMAT);
TestLineChart chart = new
TestLineChart(jfreechart);
chart.setMouseZoomable(true, false);
//This series gives problem
double[] yValues1 = new double[] {100000000d,
100000000d, 100000000d, 100000000d, 100000000d};
double[] xValues1 = new double[]
{1140215400000D, 1140216000000D, 1140216600000D,
1140217200000D, 1140217800000D};
//This series is plotted properly
double[] yValues2 = new double[] {66666666d,
66666666d, 66666666d, 66666666d, 66666666d};
double[] xValues2 = new double[]
{1140215400000D, 1140216000000D, 1140216600000D,
1140217200000D, 1140217800000D};
//This series is same as "Series 1" but one
data point has value 66666666. Hence it plots properly.
double[] yValues3 = new double[] {100000000d,
66666666d, 100000000d, 100000000d, 100000000d};
double[] xValues3 = new double[]
{1140215400000D, 1140216000000D, 1140216600000D,
1140217200000D, 1140217800000D};
//chart.addSeries("Series 1", "Series 1",
xValues1, yValues1);
//chart.addSeries("Series 2", "Series 2",
xValues2, yValues2);
chart.addSeries("Series 3", "Series 3",
xValues3, yValues3);
JFrame frame = new JFrame("Test Line Chart");
frame.setSize(500, 400);
frame.getContentPane().add(BorderLayout.CENTER,
chart);
frame.setVisible(true);
}
}
[/code]
The above code is compatible with JFreeChart verion 1.0
In the above example, if only "Series 1" is added to
the chart, then the graph does not get plotted.
However, now if "Series 1" and "Series 2" are both
added to the chart, then "Series 1" graph shows up
along with "series 2" graph.
Also "Series 3" clearly shows that this issue exists
only if all the data points in the series have the same
value and are greater than 66666666 (approx.).
Anybody aware of this issue in JFreeChart? Has this
been already fixed? (unlikely as I am using JFreeChart
version 1.0.1 and the problem exists) Is there are
workaround?
Thanks in advance.
Logged In: YES
user_id=112975
Thanks for the report and especially the test case.
It looks like this bug is triggered in the case where all
the data values are the same (and large), which means the
range of values (the difference between the maximum value
and the minimum value) is zero. In this case, the
getAutoRangeMinimumSize() method is used to determine the
length of the axis (in data units), because there is no way
to determine an appropriate length from the data values
themselves. The default minimum length is 0.00000001, so
I'm guessing that this fails due to precision when the data
values are large.
A workaround is to set the minimum autorange to a value that
is appropriate for the data you are dealing with, for example:
NumberAxis numberAxis = (NumberAxis) xyPlot.getRangeAxis();
numberAxis.setAutoRangeMinimumSize(10.0);
I will try to think of a way to fix the bug more generally.
Logged In: YES
user_id=112975
OK, I applied a fix to CVS that checks that the lower and
upper axis limits are not the same AFTER the
getAutoRangeMinimumSize() is applied. This will be included
in the 1.0.3 release.
Logged In: YES
user_id=1586955
David,
Great! Thanks for the quick response and the fix. When can
we expect the 1.0.3 release?
Once again, Thank You.
Logged In: YES
user_id=112975
I'm aiming to release 1.0.3 at the end of this month.