jFreeChart时间序列图表,x轴上有时间间隔

时间:2013-07-04 08:58:51

标签: plot jfreechart intervals timeserieschart

是否有可能 x轴标记为时间序列中的非周期时间间隔 - 使用绘制的-Chart JFreeChart的

我编写了一个可编辑的最小例子。在这个例子里面是注释,指出了我想要的间隔。

我已经尝试过的是扩展 RegularTimePeriod - 类。由于一些错误,我放弃了这种方法,而是想询问是否有更简单的方法。

这是最小的例子(注意:它没有导入):

public class MyTimeSeriesGraphMinimalExample {
    public static void main(String args[]) {
        TimeSeries timeseries = new TimeSeries("Series 1");

    //these two should form one interval
    timeseries.add(new Day(1,1,2013),10);//1
    timeseries.add(new Day(5,1,2013),10);//2

    //these two should form one interval
    timeseries.add(new Day(11,1,2013),9);//1
    timeseries.add(new Day(14,1,2013),9);//2
    TimeSeries timeseries1 = new TimeSeries("Series 2");

    //these two should form one interval
    timeseries1.add(new Day(1, 1,2013), 5);//1
    timeseries1.add(new Day(5, 1,2013), 5);//2

    //these two should form one interval
    timeseries1.add(new Day(11, 1,2013), 8);//1
    timeseries1.add(new Day(14, 1,2013), 8);//2

    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.DAY, 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:/minimalExampleChart.jpeg"),
                jfreechart, 600, 500);
    } catch (Exception e) {
        // TODO: handle exception
    }
        }
}

0 个答案:

没有答案