2013-07-03 2 views
2

timeseries-chartJFreechart -Api를 사용하는 데 문제가 있습니다. timeseries 그래프에서 x 축에 DAYS-MONTH를 표시합니다. 그래서, 나는 SeriesException으로 인해 timeseries-data를 만들 때 날짜를 올바르게 설정할 수 없습니다.

Jfreechart timeseries graph

나는 오류가 어떻게 발생하는지보기 위해 컴파일 할 수있는 최소한의 예를 제공 할 수 있습니다.

은 내가 클래스 이달 인수

로 날짜를 취할 수 있다는 것을 알고 뭐죠 월 (날짜 날짜) -Consturctor 내가 그것을 사용하는 방법을 사용하여 함께 문제? 그리고 timeseries-data의 요일을 어떻게 설정하여 줄거리에 표시 할 수 있습니까?

(참고 :. 수입품은 포함되지 않습니다)

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 
     } 
    } 
} 
+0

+1 사이의 달을 컴파일 예제로 사용합니다. – obourgain

답변

3

는 예외입니다 : 당신은 시리즈에서 두 번 같은 지점을 추가하려고

org.jfree.data.general.SeriesException: 
You are attempting to add an observation for the time period February 3902 but 
the series already contains an observation for that time period. Duplicates 
are not permitted. Try using the addOrUpdate() method. 

. 둘 :

new Month(new Date(2002, 1, 1, 12, 45, 23)) and 
new Month(new Date(2002, 1, 2, 12, 45, 23)) 

은 같은 달을 나타냅니다. 당신이 두 값 월 1 일에 하나 월 2 일에 하나가 org.jfree.data.time.Day 사용하려면

: 그건 그렇고

timeseries.add(new Day(1, 1, 2002), 100.10000000000002D); 
    timeseries.add(new Day(2, 1, 2002), 694.10000000000002D); 

new Month(new Date(2002, 1, 1, 12, 45, 23))java.util.Date으로 2002 년 1 월 3902 월과하지 생성자를 인수로 취합니다. 1900을 빼고 0-11