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:Perfil_Deportivo.graficaEntrenamientoCargado.java

public graficaEntrenamientoCargado() {
    datos.removeAllSeries();/*from   w w  w . ja  va 2 s.c  o m*/
    //sxy.add(x[0], y[0]);
    pesos = new double[EntrenamientoCargado.pesoentreno.length];
    fecha = new String[EntrenamientoCargado.fechaentreno.length];
    pesos = EntrenamientoCargado.pesoentreno;
    fecha = EntrenamientoCargado.fechaentreno;
    ///////////////77

    Date fechaDate = null;

    int n = pesos.length;
    Calendar calendar = Calendar.getInstance();

    for (int i = 0; i < n; i++) {
        // JOptionPane.showMessageDialog(null, "fecha tio:"+fecha[i]);
        try {
            fechaDate = formato.parse(fecha[i]);
            calendar.setTime(fechaDate);
        } catch (ParseException ex) {

        }
        //  JOptionPane.showMessageDialog(null, calendar.get(Calendar.DAY_OF_MONTH)+" "+calendar.get(Calendar.MONTH)+1+" "+ calendar.get(Calendar.YEAR));
        s1.add(new Day(calendar.get(Calendar.DAY_OF_MONTH), calendar.get(Calendar.MONTH) + 1,
                calendar.get(Calendar.YEAR)), pesos[i]);
        // System.out.print(x[i]+"-"+i+" ");
    }
    datos.addSeries(s1);
    grafica = ChartFactory.createTimeSeriesChart("Progreso de cargas", "Fecha", "Peso", datos, true, true,
            false);
    /// 
    grafica.setBackgroundPaint(Color.white);

    XYPlot plot = (XYPlot) grafica.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("MMM-yyyy"));

}

From source file:grafici.FattureTimeSeriesChart.java

/**
 * Creates a chart.//from  w w w.java2s .  c  om
 * 
 * @param dataset
 *            a dataset.
 * 
 * @return A chart.
 */
private static JFreeChart createChart(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createTimeSeriesChart(titolo, // title
            "Date", // x-axis label
            "Quantit", // 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("MMM-yyyy"));

    return chart;

}

From source file:grafici.MediciTimeSeriesChart.java

/**
 * Creates a chart.//w w  w.j  a va2s .  c  o m
 * 
 * @param dataset
 *            a dataset.
 * 
 * @return A chart.
 */
private static JFreeChart createChart(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createTimeSeriesChart(titolo, // title
            "Date", // x-axis label
            "Occorrenze", // 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("MMM-yyyy"));

    return chart;

}

From source file:uk.co.petertribble.jkstat.gui.KstatSetChart.java

private void init(List<String> statistics) {
    dataset = new TimeSeriesCollection();
    tsmap = new HashMap<String, TimeSeries>();
    kMap = new HashMap<Kstat, ChartableKstat>();

    for (Kstat ks : kss.getKstats()) {
        kMap.put(ks, new ChartableKstat(jkstat, ks));

        for (String statistic : KstatUtil.numericStatistics(jkstat, ks)) {
            String s = ks.getTriplet() + ":" + statistic;
            tsmap.put(s, new TimeSeries(s));
        }/*from   www .  j  a va2  s . c o  m*/
        for (String statistic : statistics) {
            dataset.addSeries(tsmap.get(ks.getTriplet() + ":" + statistic));
        }
    }

    if (jkstat instanceof SequencedJKstat) {
        readAll(((SequencedJKstat) jkstat).newInstance());
    } else {
        setMaxAge(maxage);
        updateAccessory();
    }

    String ylabel = showdelta ? KstatResources.getString("CHART.RATE")
            : KstatResources.getString("CHART.VALUE");

    chart = ChartFactory.createTimeSeriesChart(kss.toString() == null ? "statistic" : kss.toString(),
            KstatResources.getString("CHART.TIME"), ylabel, dataset, true, true, false);

    setAxes();

    if (!(jkstat instanceof SequencedJKstat)) {
        startLoop();
    }
}

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

/**
 * Creates a sample chart.//  w  w  w . j  a va2s .c o m
 * 
 * @param dataset  the dataset.
 * 
 * @return A sample chart.
 */
private JFreeChart createChart(final XYDataset dataset) {
    return ChartFactory.createTimeSeriesChart("Test", "Day", "Value", dataset, false, false, false);
}

From source file:com.hmsinc.epicenter.webapp.chart.ChartService.java

/**
 * @param adapter//from  w  w  w. ja  v  a  2  s .  c  o  m
 * @param annotations
 * @return
 */
private static JFreeChart createChart(final AbstractChart adapter, final List<XYAnnotation> annotations) {

    final JFreeChart chart;
    if (adapter.getItems() instanceof XYDataset) {

        chart = ChartFactory.createTimeSeriesChart(adapter.getTitle(), adapter.getXLabel(), adapter.getYLabel(),
                (XYDataset) adapter.getItems(), true, false, false);
        final ValueAxis domainAxis = new DateAxis();
        domainAxis.setLabelFont(LABEL_FONT);
        domainAxis.setTickLabelFont(LABEL_FONT);
        domainAxis.setLowerMargin(0.0);
        domainAxis.setUpperMargin(0.0);

        chart.getXYPlot().setDomainAxis(domainAxis);
        chart.getXYPlot().getRangeAxis().setLabelFont(LABEL_FONT);
        chart.getXYPlot().getRangeAxis().setTickLabelFont(LABEL_FONT);
        chart.getXYPlot().getRangeAxis().setStandardTickUnits(adapter.getRangeTickUnits());

        if (adapter.isAlwaysScaleFromZero()) {
            final double upperBound = chart.getXYPlot().getRangeAxis().getRange().getUpperBound();
            final Range range = new Range(0, upperBound + (upperBound * 0.2));
            chart.getXYPlot().getRangeAxis().setRange(range);
        }

        for (Marker marker : adapter.getMarkers()) {
            chart.getXYPlot().addDomainMarker(marker);
        }

        if (annotations != null) {
            for (XYAnnotation annotation : annotations) {
                if (annotation instanceof XYPointerAnnotation) {
                    ((XYPointerAnnotation) annotation).setFont(ANNOTATION_FONT);
                }
                chart.getXYPlot().addAnnotation(annotation);
            }
        }

        // Add any bands to the chart
        if (adapter instanceof TimeSeriesChart) {
            final TimeSeriesChart tsc = (TimeSeriesChart) adapter;
            for (int i = 0; i < tsc.getBands().size(); i++) {

                final Color c = tsc.getBandColors().get(i);
                final Color fill = tsc.getBandFillColors().get(i);
                final XYDifferenceRenderer renderer = new XYDifferenceRenderer(fill, fill, false);
                renderer.setSeriesPaint(0, c);
                renderer.setSeriesPaint(1, c);
                renderer.setSeriesStroke(0, LineStyle.THICK.getStroke());
                renderer.setSeriesStroke(1, LineStyle.THICK.getStroke());

                chart.getXYPlot().setDataset(i + 1, tsc.getBands().get(i));
                chart.getXYPlot().setRenderer(i + 1, renderer);
            }
        }

    } else if (adapter.getItems() instanceof CategoryDataset) {

        chart = ChartFactory.createBarChart(adapter.getTitle(), adapter.getXLabel(), adapter.getYLabel(),
                (CategoryDataset) adapter.getItems(), PlotOrientation.VERTICAL, true, false, false);
        chart.getCategoryPlot().getDomainAxis().setLabelFont(LABEL_FONT);
        chart.getCategoryPlot().getRangeAxis().setLabelFont(LABEL_FONT);
        chart.getCategoryPlot().getDomainAxis().setTickLabelFont(LABEL_FONT);
        chart.getCategoryPlot().getRangeAxis().setTickLabelFont(LABEL_FONT);

        if (adapter.isAlwaysScaleFromZero()) {
            final double upperBound = chart.getCategoryPlot().getRangeAxis().getRange().getUpperBound();
            final Range range = new Range(0, upperBound + (upperBound * 0.1));
            chart.getCategoryPlot().getRangeAxis().setRange(range);
        }

    } else {
        throw new UnsupportedOperationException("Unsupported chart type: " + adapter.getItems().getClass());
    }

    chart.getPlot().setNoDataMessage(NO_DATA_MESSAGE);

    return chart;
}

From source file:DynamicDataDemo.java

/**
 * Creates a sample chart.//from ww w.j av  a  2  s  .c om
 * 
 * @param dataset  the dataset.
 * 
 * @return A sample chart.
 */
private JFreeChart createChart(final XYDataset dataset, String title, String xcoor, String ycoor) {
    final JFreeChart result = ChartFactory.createTimeSeriesChart(title, xcoor, ycoor, dataset, true, true,
            false);
    final XYPlot plot = result.getXYPlot();
    ValueAxis axis = plot.getDomainAxis();
    axis.setAutoRange(true);
    axis.setFixedAutoRange(60000.0); // 60 seconds
    axis = plot.getRangeAxis();
    axis.setRange(0.0, 500.0);
    return result;
}

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

/**
 * Creates a chart./*from w ww . ja  v a  2  s . c  o m*/
 * 
 * @param dataset  a dataset.
 * 
 * @return A chart.
 */
private JFreeChart createChart(final XYDataset dataset) {

    final JFreeChart chart = ChartFactory.createTimeSeriesChart("Weekly Data", "Date", "Value", dataset, true,
            true, false);

    chart.setBackgroundPaint(Color.white);

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

    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    //    plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    final XYItemRenderer renderer = plot.getRenderer();
    if (renderer instanceof StandardXYItemRenderer) {
        final StandardXYItemRenderer rr = (StandardXYItemRenderer) renderer;
        rr.setPlotShapes(true);
        rr.setShapesFilled(true);
    }

    final DateAxis axis = (DateAxis) plot.getDomainAxis();
    final TickUnits standardUnits = new TickUnits();
    standardUnits.add(new DateTickUnit(DateTickUnit.DAY, 1, new SimpleDateFormat("MMM dd ''yy")));
    standardUnits.add(new DateTickUnit(DateTickUnit.DAY, 7, new SimpleDateFormat("MMM dd ''yy")));
    standardUnits.add(new DateTickUnit(DateTickUnit.MONTH, 1, new SimpleDateFormat("MMM ''yy")));
    axis.setStandardTickUnits(standardUnits);

    return chart;

}

From source file:plugins.tutorial.chart.ChartTutorial2.java

/**
 * Creates a sample chart.// w w w.j  a v a 2  s . co m
 * 
 * @param dataset
 *        the dataset.
 * @return The chart.
 */
private static JFreeChart createChart(XYDataset xydataset) {

    JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("Projected Values - Test", "Date",
            "Index Projection", xydataset, true, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setInsets(new RectangleInsets(5D, 5D, 5D, 20D));
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setRangeGridlinePaint(Color.white);
    DeviationRenderer deviationrenderer = new DeviationRenderer(true, false);
    deviationrenderer.setSeriesStroke(0, new BasicStroke(3F, 1, 1));
    deviationrenderer.setSeriesStroke(0, new BasicStroke(3F, 1, 1));
    deviationrenderer.setSeriesStroke(1, new BasicStroke(3F, 1, 1));
    deviationrenderer.setSeriesFillPaint(0, new Color(255, 200, 200));
    deviationrenderer.setSeriesFillPaint(1, new Color(200, 200, 255));
    xyplot.setRenderer(deviationrenderer);
    NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis();
    numberaxis.setAutoRangeIncludesZero(false);
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    return jfreechart;

}

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

protected ChartPanel createUtilityPanel(Currency currency) {
    TimeSeriesCollection timeSeriesCollection = new TimeSeriesCollection();

    timeSeriesCollection.addSeries(ApplicationContext.getInstance().getModelRegistry()
            .getNationalEconomyModel(currency).stateModel.utilityModel.utilityOutputModel.getTimeSeries());

    for (GoodType inputGoodType : ApplicationContext.getInstance().getModelRegistry()
            .getNationalEconomyModel(currency).stateModel.utilityModel.utilityInputModels.keySet()) {
        timeSeriesCollection.addSeries(ApplicationContext.getInstance().getModelRegistry()
                .getNationalEconomyModel(currency).stateModel.utilityModel.utilityInputModels.get(inputGoodType)
                        .getTimeSeries());
    }/* ww w. j  av a2 s  .  c  o  m*/

    JFreeChart chart = ChartFactory.createTimeSeriesChart("State Utility", "Date", "Utility",
            (XYDataset) timeSeriesCollection, true, true, false);
    configureChart(chart);
    return new ChartPanel(chart);
}