public class Example {
public static void main(String args[]){
/*creating timeSeriesCollection*/
TimeSeriesCollection dataset = new TimeSeriesCollection();
TimeSeries timeSeries1 = new TimeSeries("Sample 1");
timeSeries1.add(new Day(8,4, 2012), 7.0);
timeSeries1.add(new Day(19,4, 2012), 5.0);
dataset.addSeries(timeSeries1);
/*Creating the chart*/
JFreeChart chart = ChartFactory.createTimeSeriesChart("Population","Date","Population",dataset,true,true,false);
/*Altering the graph */
XYPlot plot = (XYPlot) chart.getPlot();
plot.setAxisOffset(new RectangleInsets(5.0, 10.0, 10.0, 5.0));
plot.setDomainCrosshairVisible(true);
plot.setRangeCrosshairVisible(true);
XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer)plot.getRenderer();
renderer.setBaseShapesVisible(true);
renderer.setBaseShapesFilled(true);
NumberAxis numberAxis = (NumberAxis)plot.getRangeAxis();
numberAxis.setRange(new Range(0,10));
DateAxis axis = (DateAxis) plot.getDomainAxis();
axis.setDateFormatOverride(new SimpleDateFormat("dd-MM-yyyy"));
axis.setAutoTickUnitSelection(false);
axis.setVerticalTickLabels(true);
/* Displaying the chart*/
ChartFrame frame = new ChartFrame("Test", chart);
frame.pack();
frame.setVisible(true);
}
}
我已经编写了上面的代码,它工作得很好,但是在渲染图形时它显示的日期没有值。它在没有值的 y 轴上显示日期,如9/4/12
, 10/4/2012
to 。18/4/2012
如何删除没有价值的日期。为什么会这样?
任何人都可以帮助我吗?