2
我在創建時間序列圖使用JFreechart -Api時出現問題。 在時間序列圖中我想讓x軸顯示DAYS-MONTH。它是這樣做的,但是由於SeriesException,我創建時間序列數據時無法正確設置日期。
Jfreechart時間序列圖
我可以提供一個可以編譯以查看錯誤如何發生的最小示例。
我知道一個月的類可以採取一個日期作爲參數
請告訴我用月(日期爲準)-Consturctor我用它的方式的問題?我怎樣才能設置時間序列中的日期 - 數據,以便它們出現在劇情中?
(注:進口不包括在內)
public class MyTimeSeriesGraphMinimalExample {
public static void main(String args[]) {
TimeSeries timeseries = new TimeSeries("Series 1");
//works not
timeseries.add(new Month(new Date(2002, 1, 1, 12, 45, 23)),
100.10000000000002D);//day 1
timeseries.add(new Month(new Date(2002, 1, 2, 12, 45, 23)),
694.10000000000002D);// day 2
// works timeseries.add(new Month(3, 2002), 734.39999999999998D);
// works timeseries.add(new Month(4, 2002), 453.19999999999999D);
TimeSeries timeseries1 = new TimeSeries("Series 2");
//works not
timeseries1.addOrUpdate(new Month(new Date(2002, 1, 1, 12, 45, 23)),
234.09999999999999D);// day 1
timeseries1.addOrUpdate(new Month(new Date(2002, 1, 2, 12, 45, 23)),
623.70000000000005D);// day 2
//works timeseries1.add(new Month(3, 2002), 642.5D);
//works timeseries1.add(new Month(4, 2002), 700.39999999999998D);
TimeSeriesCollection timeseriescollection = new TimeSeriesCollection();
timeseriescollection.addSeries(timeseries);
timeseriescollection.addSeries(timeseries1);
XYDataset xydataset = timeseriescollection;
//chart-visual-property-settings
JFreeChart jfreechart = ChartFactory.createTimeSeriesChart(
"Time Series Demo 3", "Time", "Value", xydataset, true, true,
false);
XYPlot xyplot = (XYPlot) jfreechart.getPlot();
DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis();
dateaxis.setTickUnit(new DateTickUnit(DateTickUnitType.MONTH, 1,
new SimpleDateFormat("dd-MMM")));
dateaxis.setVerticalTickLabels(true);
XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyplot
.getRenderer();
xylineandshaperenderer.setBaseShapesVisible(true);
xylineandshaperenderer.setSeriesFillPaint(0, Color.red);
xylineandshaperenderer.setSeriesFillPaint(1, Color.green);
xylineandshaperenderer.setSeriesPaint(0, Color.red);
xylineandshaperenderer.setSeriesPaint(1, Color.green);
xylineandshaperenderer.setUseFillPaint(true);
xylineandshaperenderer
.setLegendItemToolTipGenerator(new StandardXYSeriesLabelGenerator(
"Tooltip {0}"));
//draw
try {
ChartUtilities.saveChartAsJPEG(new File("C:/series.jpeg"),
jfreechart, 600, 500);
} catch (Exception e) {
// TODO: handle exception
}
}
}
編譯示例的+1。 – obourgain