Example usage for org.jfree.chart ChartFactory createTimeSeriesChart

List of usage examples for org.jfree.chart ChartFactory createTimeSeriesChart

Introduction

In this page you can find the example usage for org.jfree.chart ChartFactory createTimeSeriesChart.

Prototype

public static JFreeChart createTimeSeriesChart(String title, String timeAxisLabel, String valueAxisLabel,
        XYDataset dataset, boolean legend, boolean tooltips, boolean urls) 

Source Link

Document

Creates and returns a time series chart.

Usage

From source file:compecon.dashboard.panel.AgentsPanel.java

protected ChartPanel createAgentNumberPanel(Currency currency, Class<? extends Agent> agentType) {
    TimeSeriesCollection timeSeriesCollection = new TimeSeriesCollection();

    timeSeriesCollection.addSeries(ApplicationContext.getInstance().getModelRegistry()
            .getNationalEconomyModel(currency).numberOfAgentsModels.get(agentType).getTimeSeries());

    // in case of households
    if (Household.class.isAssignableFrom(agentType)) {
        // show retired households
        timeSeriesCollection.addSeries(ApplicationContext.getInstance().getModelRegistry()
                .getNationalEconomyModel(currency).householdsModel.retiredModel.getTimeSeries());
    }//  www .jav  a2 s  . c  om

    JFreeChart chart = ChartFactory.createTimeSeriesChart("# " + agentType.getSimpleName() + " Agents", "Date",
            "# Agents", (XYDataset) timeSeriesCollection, true, true, false);
    configureChart(chart);
    return new ChartPanel(chart);
}

From source file:gui.grafica.estadisticas.PanelGrafica.java

/**
 * Crea un objeto JFreechart con el titulo pasado por parametro con 
 * leyenda en el eje X  siendo el tiempo y la leyenda de eje Y  la velocidad.
 * La grafica creada es vaca./*w  ww  . ja  v  a 2s .  c  o  m*/
 *
 * @param title. Titulo de la grafica.
 *
 * @return A chart.
 */
private JFreeChart createChart() {

    JFreeChart chart = ChartFactory.createTimeSeriesChart(title, // title
            LEYENDA_X, // x-axis label
            LEYENDA_Y, // y-axis label
            dataset, // data
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
        renderer.setDrawSeriesLineAsPath(true);
    }

    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("h:mm"));
    chartSet = chart;
    return chart;

}

From source file:org.jfree.chart.demo.TimeSeriesDemo2.java

/**
 * A demonstration application showing a quarterly time series containing a null value.
 *
 * @param title  the frame title./*from  w  w w  .  j  ava  2s  .  c  om*/
 */
public TimeSeriesDemo2(final String title) {

    super(title);

    final TimeSeries series = new TimeSeries("Quarterly Data", Quarter.class);
    series.add(new Quarter(1, 2001), 500.2);
    series.add(new Quarter(2, 2001), 694.1);
    series.add(new Quarter(3, 2001), 734.4);
    series.add(new Quarter(4, 2001), 453.2);
    series.add(new Quarter(1, 2002), 500.2);
    series.add(new Quarter(2, 2002), null);
    series.add(new Quarter(3, 2002), 734.4);
    series.add(new Quarter(4, 2002), 453.2);
    final TimeSeriesCollection dataset = new TimeSeriesCollection(series);
    final JFreeChart chart = ChartFactory.createTimeSeriesChart("Time Series Demo 2", "Time", "Value", dataset,
            true, true, false);
    chart.getXYPlot().addRangeMarker(new ValueMarker(550.0));
    final Quarter q = new Quarter(2, 2002);
    chart.getXYPlot().addDomainMarker(new ValueMarker(q.getMiddleMillisecond()));
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(chartPanel);

}

From source file:net.sourceforge.openforecast.examples.ForecastingChartDemo.java

/**
 * A demonstration application showing a quarterly time series
 * along with the forecast values.//ww  w. ja v a  2  s.  c  om
 * @param title the frame title.
 */
public ForecastingChartDemo(String title) {
    super(title);

    // Create a title...
    String chartTitle = "OpenForecast Demo";
    XYDataset dataset = createDataset();

    JFreeChart chart = ChartFactory.createTimeSeriesChart(chartTitle, "Date", "Quarterly Sales (Units sold)",
            dataset, true, // Legend
            true, // Tooltips
            false);// URLs

    XYPlot plot = chart.getXYPlot();
    XYItemRenderer renderer = plot.getRenderer();
    if (renderer instanceof StandardXYItemRenderer) {
        StandardXYItemRenderer r = (StandardXYItemRenderer) renderer;
        r.setPlotShapes(true);
        r.setDefaultShapesFilled(Boolean.TRUE);
    }

    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(chartPanel);
}

From source file:org.jfree.chart.demo.TimeSeriesDemo6.java

/**
 * Creates a chart.// ww  w. j ava  2 s.  c  om
 * 
 * @param dataset  the dataset.
 * 
 * @return a chart.
 */
private JFreeChart createChart(final XYDataset dataset) {

    final JFreeChart chart = ChartFactory.createTimeSeriesChart("Time Series Demo 6", "Date", "Value", dataset,
            true, true, false);

    final XYPlot plot = chart.getXYPlot();
    final DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));
    final ValueAxis rangeAxis = plot.getRangeAxis();
    rangeAxis.setAutoRangeMinimumSize(1.0);
    return chart;

}

From source file:org.jfree.chart.demo.MultipleDatasetDemo1.java

/**
 * Constructs a new demonstration application.
 *
 * @param title  the frame title./* w  ww  .j  a v a  2  s .com*/
 */
public MultipleDatasetDemo1(final String title) {

    super(title);
    final TimeSeriesCollection dataset1 = createRandomDataset("Series 1");
    final JFreeChart chart = ChartFactory.createTimeSeriesChart("Multiple Dataset Demo 1", "Time", "Value",
            dataset1, true, true, false);
    chart.setBackgroundPaint(Color.white);

    this.plot = chart.getXYPlot();
    this.plot.setBackgroundPaint(Color.lightGray);
    this.plot.setDomainGridlinePaint(Color.white);
    this.plot.setRangeGridlinePaint(Color.white);
    //        this.plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 4, 4, 4, 4));
    final ValueAxis axis = this.plot.getDomainAxis();
    axis.setAutoRange(true);

    final NumberAxis rangeAxis2 = new NumberAxis("Range Axis 2");
    rangeAxis2.setAutoRangeIncludesZero(false);

    final JPanel content = new JPanel(new BorderLayout());

    final ChartPanel chartPanel = new ChartPanel(chart);
    content.add(chartPanel);

    final JButton button1 = new JButton("Add Dataset");
    button1.setActionCommand("ADD_DATASET");
    button1.addActionListener(this);

    final JButton button2 = new JButton("Remove Dataset");
    button2.setActionCommand("REMOVE_DATASET");
    button2.addActionListener(this);

    final JPanel buttonPanel = new JPanel(new FlowLayout());
    buttonPanel.add(button1);
    buttonPanel.add(button2);

    content.add(buttonPanel, BorderLayout.SOUTH);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(content);

}

From source file:DualAxisDemo2.java

/**
 * A demonstration application showing how to create a time series chart with dual axes.
 *
 * @param title  the frame title./*from w  ww.j a  v  a 2s .  c o m*/
 */
public DualAxisDemo2(final String title) {

    super(title);

    // create a title...
    final String chartTitle = "Dual Axis Demo 2";
    final XYDataset dataset = createDataset1();

    final JFreeChart chart = ChartFactory.createTimeSeriesChart(chartTitle, "Date", "Price Per Unit", dataset,
            true, true, false);

    //      final StandardLegend legend = (StandardLegend) chart.getLegend();
    //    legend.setDisplaySeriesShapes(true);

    final XYPlot plot = chart.getXYPlot();
    final NumberAxis axis2 = new NumberAxis("Secondary");
    axis2.setAutoRangeIncludesZero(false);
    plot.setRangeAxis(1, axis2);
    plot.setDataset(1, createDataset2());
    plot.mapDatasetToRangeAxis(1, 1);
    final XYItemRenderer renderer = plot.getRenderer();
    renderer.setToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());
    if (renderer instanceof StandardXYItemRenderer) {
        final StandardXYItemRenderer rr = (StandardXYItemRenderer) renderer;
        //           rr.setPlotShapes(true);
        rr.setShapesFilled(true);
    }

    final StandardXYItemRenderer renderer2 = new StandardXYItemRenderer();
    renderer2.setSeriesPaint(0, Color.black);
    //        renderer2.setPlotShapes(true);
    renderer.setToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());
    plot.setRenderer(1, renderer2);

    final DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));

    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(chartPanel);

}

From source file:com.view.TimeSeriesChartView.java

public JFreeChart getVendorTimeSeriesChart(Excel theExcel, String vendor) {
    int vendorCode = Integer.parseInt(vendor);
    ArrayList<Receiving> theReceiving = theExcel.getSheetReceiving();

    //        HashMap<Month, Integer> item1Map = new HashMap<>();
    //        HashMap<Month, Integer> item2Map = new HashMap<>();
    //        HashMap<Month, Integer> item3Map = new HashMap<>();
    Set vendorItem = new HashSet();
    for (int i = 0; i < theReceiving.size(); i++) {
        vendorItem.add(theReceiving.get(i).getItem());
    }/*ww w. ja  va  2  s.  c om*/
    TimeSeries data[] = new TimeSeries[vendorItem.size()];
    HashMap<Month, Integer> itemMap[] = new HashMap[vendorItem.size()];
    for (int i = 0; i < vendorItem.size(); i++) {
        String itemName = "item" + i;
        data[i] = new TimeSeries(itemName);
        itemMap[i] = new HashMap<>();
    }
    Calendar cal = Calendar.getInstance();
    for (int i = 0; i < theReceiving.size(); i++) {
        cal.setTime(theReceiving.get(i).getDate());
        int month = cal.get(Calendar.MONTH) + 1;
        int year = cal.get(Calendar.YEAR);
        int quantity = 0;
        if (theReceiving.get(i).getVendor() == vendorCode) {
            quantity = theReceiving.get(i).getQuantity();
            Month theMonth = new Month(month, year);
            int itemNum = theReceiving.get(i).getItem() - 1;
            itemMap[itemNum].put(theMonth, updateItemMap(itemMap[itemNum], theMonth, quantity));
        }
    }
    TimeSeriesCollection my_data_series = new TimeSeriesCollection();
    for (int i = 0; i < vendorItem.size(); i++) {
        for (Map.Entry<Month, Integer> entry : itemMap[i].entrySet()) {
            data[i].add(entry.getKey(), entry.getValue());
        }
        my_data_series.addSeries(data[i]);
    }

    JFreeChart chart = ChartFactory.createTimeSeriesChart("Receiving", "Month", "Quantity", my_data_series,
            true, true, false);
    chart.setBackgroundPaint(Color.YELLOW);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainGridlinePaint(Color.GREEN);
    plot.setRangeGridlinePaint(Color.orange);
    plot.setAxisOffset(new RectangleInsets(50, 0, 20, 5));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();

    renderer.setBaseShapesVisible(true);
    renderer.setBaseShapesFilled(true);

    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("MM.yyyy"));
    return chart;
}

From source file:ws.moor.bt.gui.charts.PiecesStats.java

private JFreeChart createChart(XYDataset dataset) {
    JFreeChart chart = ChartFactory.createTimeSeriesChart("Pieces", "Time", "Pieces", dataset, true, false,
            false);//from   w  ww .  j  a  v  a 2  s. co m
    chart.setBackgroundPaint(Color.white);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("HH:mm:ss"));

    return chart;
}

From source file:edu.cuny.cat.ui.SpecialistView.java

private void setupShoutPlots() {
    final JFreeChart chart = ChartFactory.createTimeSeriesChart("", "Time", "Price", dataset, true, true,
            false);//from w  ww.  ja va  2  s.  c  om
    chart.setAntiAlias(true);
    chart.setBackgroundPaint(getContentPane().getBackground());
    xyplot = (XYPlot) chart.getPlot();
    xyplot.setNoDataMessage("NO DATA");
    xyplot.setRenderer(new XYLineAndShapeRenderer());
    final NumberAxis numberaxis1 = (NumberAxis) xyplot.getRangeAxis();
    numberaxis1.setTickMarkInsideLength(2.0F);
    numberaxis1.setTickMarkOutsideLength(0.0F);

    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setDomainZoomable(true);
    chartPanel.setRangeZoomable(true);

    chartPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(20, 5, 5, 20),
            BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder("Shouts"),
                    BorderFactory.createEmptyBorder(5, 5, 5, 5))));

    getContentPane().add(chartPanel, BorderLayout.CENTER);

    pack();
}