Looks like the HorizontalDateAxis class can only handle Calendar.DATE as its smallest unit of date to be put as ticks. Am I missing something or do I have to work with some extended class to use Calendar.SECOND as the smallest tick unit. And if so, how?
Please let me know.
I appreciate it.
No Time handling using HorizontalDateAxis
RE: No Time handling using HorizontalDateAxis
There's a bug in the date axis classes that prevents the ticks being displayed correctly. The date axis was designed to handle any tick size from milliseconds to decades but, obviously, not tested with anything except days.
You can download two source files (DateAxis.java and HorizontalDateAxis.java) that should fix the problem - the download is via anonymous FTP from ftp://jrefinery.com/pub/jfreechart. These are replacements for the existing source files with those names.
I have to confess that this bug was reported and fixed a few weeks ago, but I didn't get around to updating the 0.5 download - sorry. The 0.5 download was produced manually, so it is a pain to update it.
I have since transferred development of JFreeChart to Linux and I have written scripts to package up the 0.6 download (to be released later this month), so that updating it with bug fixes should be easier.
Regards,
DG.
You can download two source files (DateAxis.java and HorizontalDateAxis.java) that should fix the problem - the download is via anonymous FTP from ftp://jrefinery.com/pub/jfreechart. These are replacements for the existing source files with those names.
I have to confess that this bug was reported and fixed a few weeks ago, but I didn't get around to updating the 0.5 download - sorry. The 0.5 download was produced manually, so it is a pain to update it.
I have since transferred development of JFreeChart to Linux and I have written scripts to package up the 0.6 download (to be released later this month), so that updating it with bug fixes should be easier.
Regards,
DG.
RE: No Time handling using HorizontalDateAxis
I really appreciate the prompt reply. I'm at work and can't get on to any ftp server. Can you please e-mail me the 2 java files as attachments. Thanks again.
RE: No Time handling using HorizontalDateAxis
Never mind. I got it. Thanks for the help.
RE: No Time handling using HorizontalDateAxis
I tried using the new DateAxis.java and HorizontalDateAxis.java from the ftp server and compiled them into classes and replaced them into jrefinery.jar. Bu my graphs are still not showing up. Here's some code I'm using but it's not working.
QueryXYDataSource is an exact replica of DefaultXYDataSource.
/** part of a method*/
XYDataSource xyData = createQueryXYDataSource(dataVector);
JFreeChart graph = JFreeChart.createTimeSeriesChart(xyData);
StandardTitle title = (StandardTitle)graph.getTitle();
title.setTitle("Performance");
graph.setChartBackgroundPaint(new GradientPaint(0, 0, Color.white,0, 1000, Color.blue));
JFreeChartPanel graphPanel = new JFreeChartPanel(graph);
graphPanel.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createEmptyBorder(4, 4, 4, 4),
BorderFactory.createLineBorder(Color.darkGray, 1)));
Plot myPlot = graph.getPlot();
Axis myVerticalAxis = myPlot.getAxis(Plot.VERTICAL_AXIS);
myVerticalAxis.setLabel("Yield");
JFrame graphFrame = new JFrame();
graphFrame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
System.exit(0);
}
});
JPanel contentPane = (JPanel)graphFrame.getContentPane();
contentPane.add(graphPanel);
contentPane.setLayout(new BorderLayout());
graphFrame.pack();
graphFrame.show();
/**
* creates a graph from the DataVector given
*/
private XYDataSource createQueryXYDataSource(DataVector dataVector)
{ Object[][][] data = new Object[1][dataVector.size()][2];
System.out.println("data length = " + data.length);
System.out.println("data[0] length = " + data[0].length);
System.out.println("data[0][0] length = " + data[0][0].length);
for (int i = 0; i<dataVector.size(); i++)
{ RecordData recordData = (RecordData)dataVector.get(i);
data[0][0] = recordData.DateAndTimeStamp;
//DateAndTimeStamp is a Calendar with set values up to SECOND
if (recordData.FailureType == 0)
{ data[0][1] = new Integer(0);
}
else
{ data[0][1] = new Integer(1);
}
}
return new QueryXYDataSource(new String[] { "Overall yield" }, data);
}//end createQueryXYDataSource()
QueryXYDataSource is an exact replica of DefaultXYDataSource.
/** part of a method*/
XYDataSource xyData = createQueryXYDataSource(dataVector);
JFreeChart graph = JFreeChart.createTimeSeriesChart(xyData);
StandardTitle title = (StandardTitle)graph.getTitle();
title.setTitle("Performance");
graph.setChartBackgroundPaint(new GradientPaint(0, 0, Color.white,0, 1000, Color.blue));
JFreeChartPanel graphPanel = new JFreeChartPanel(graph);
graphPanel.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createEmptyBorder(4, 4, 4, 4),
BorderFactory.createLineBorder(Color.darkGray, 1)));
Plot myPlot = graph.getPlot();
Axis myVerticalAxis = myPlot.getAxis(Plot.VERTICAL_AXIS);
myVerticalAxis.setLabel("Yield");
JFrame graphFrame = new JFrame();
graphFrame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
System.exit(0);
}
});
JPanel contentPane = (JPanel)graphFrame.getContentPane();
contentPane.add(graphPanel);
contentPane.setLayout(new BorderLayout());
graphFrame.pack();
graphFrame.show();
/**
* creates a graph from the DataVector given
*/
private XYDataSource createQueryXYDataSource(DataVector dataVector)
{ Object[][][] data = new Object[1][dataVector.size()][2];
System.out.println("data length = " + data.length);
System.out.println("data[0] length = " + data[0].length);
System.out.println("data[0][0] length = " + data[0][0].length);
for (int i = 0; i<dataVector.size(); i++)
{ RecordData recordData = (RecordData)dataVector.get(i);
data[0][0] = recordData.DateAndTimeStamp;
//DateAndTimeStamp is a Calendar with set values up to SECOND
if (recordData.FailureType == 0)
{ data[0][1] = new Integer(0);
}
else
{ data[0][1] = new Integer(1);
}
}
return new QueryXYDataSource(new String[] { "Overall yield" }, data);
}//end createQueryXYDataSource()
RE: No Time handling using HorizontalDateAxis
I can't spot anything obvious that's wrong in your code. Possibly the line that reads:
data[0][0] = recordData.DateAndTimeStamp;
...could be causing trouble. It needs to be *either* a java.util.Date *or* a Long that is equal to the number of milliseconds since 1 January 1970 (that is, a Long object equivalent to the long value returned by java.util.Date.getTime()). Ultimately, the XYDataSource needs to supply a Long to the XYPlot, but the DefaultXYDataSource automatically converts the Date objects to Long objects as required.
Does that help?
DG.
data[0][0] = recordData.DateAndTimeStamp;
...could be causing trouble. It needs to be *either* a java.util.Date *or* a Long that is equal to the number of milliseconds since 1 January 1970 (that is, a Long object equivalent to the long value returned by java.util.Date.getTime()). Ultimately, the XYDataSource needs to supply a Long to the XYPlot, but the DefaultXYDataSource automatically converts the Date objects to Long objects as required.
Does that help?
DG.