Thanks for replying. Let me say again that this is my first attempt to use this product, so I'm probably doing several things wrong.
paradoxoff wrote:If the domain axis of your XYPlot is a NumberAxis, then you have constructed your XYPlot in this way.
I constructed a XYSeries using the add() method. That requires a number; it won't take a String. Is that the wrong Series collection to be using?
paradoxoff wrote:To replace that with a DateAxis, you can call plot.setDomainAxis(aDateAxis), using either a preconfigured DateAxis with the formatter of your choice
I don't really understand this option. I don't know what a preconfigured DateAxis is.
paradoxoff wrote:or you can call plot.setDomainAxis(new DateAxis()), then retrieve the axis using your code and format the axis according to your needs.
I tried this but got "DateAxis cannot be converted to ValueAxis[]"
Let me back up and explain what my problem is, maybe that will help. The user enters a start date and time and ending date and time. Let's say the user chooses 7:00 am to 7:00 pm. The time in the database is stored as an integer in hhMMss format. So when I create the chart the axis labels get displayed as 70,000 to 190,000. I need to change these so the labels are "7 am" to "7 pm".
I create the dataset like so:
Code: Select all
private XYDataset createDataset(Map<Integer, Double> data) {
XYSeries dataSeries = new XYSeries("Series Key");
for (Map.Entry<Integer, Double> entry : data.entrySet()) {
dataSeries.add(entry.getKey(), entry.getValue());
}
XYSeriesCollection dataset = new XYSeriesCollection();
dataset.addSeries(dataSeries);
dataset.setIntervalWidth(0.0);
return dataset;
}
..and the chart like so:
Code: Select all
private JFreeChart createAreaChart(XYDataset dataset) {
JFreeChart chart = ChartFactory.createXYAreaChart(
"DDM Speed and Efficiency",
"Time",
"Actual FPM",
dataset,
PlotOrientation.VERTICAL,
false, true, false);
XYPlot plot = (XYPlot) chart.getPlot();
plot.setForegroundAlpha(0.65f);
ValueAxis domainAxis = (DateAxis) plot.getDomainAxis(); //x axis
//plot.setDomainAxes(new DateAxis());
if (domainAxis instanceof DateAxis) {
System.out.println("entering date formatter");
DateAxis axis = (DateAxis) domainAxis;
DateFormat formatter = new SimpleDateFormat("h a");
axis.setDateFormatOverride(formatter);
axis.setTickMarkPaint(Color.black);
axis.setLowerMargin(0.0);
axis.setUpperMargin(0.0);
}
ValueAxis rangeAxis = plot.getRangeAxis(); //y axis
rangeAxis.setTickMarkPaint(Color.black);
rangeAxis.setUpperMargin(0.4);
return chart;
}
Am I going about this all wrong? How can I get the x-axis labels that I need?
Thanks for your help.