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:old.MonitoringChart.java

private JFreeChart createChart(String title, final XYDataset dataset) {
    final JFreeChart result = ChartFactory.createTimeSeriesChart(title, "Time", "Usage in %", dataset, true,
            true, false);//  w ww  .  j a va2 s . c o  m
    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, 100.0);
    return result;
}

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

private JFreeChart createChart(XYDataset xydataset) {
    JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("Clone Test 1", "Time", "Value", xydataset, true,
            true, false);//from   w  ww.  jav a  2s  .  c om
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    ValueAxis valueaxis = xyplot.getDomainAxis();
    valueaxis.setAutoRange(true);
    valueaxis.setFixedAutoRange(60000D);
    return jfreechart;
}

From source file:org.jfree.chart.swt.demo.SWTMultipleAxisDemo1.java

/**
 * Creates the demo chart.//w w w.j a va2s  . c  o  m
 *
 * @return The chart.
 */
private static JFreeChart createChart() {

    XYDataset dataset1 = createDataset("Series 1", 100.0, new Minute(), 200);

    JFreeChart chart = ChartFactory.createTimeSeriesChart("Multiple Axis Demo 3", "Time of Day",
            "Primary Range Axis", dataset1, true, true, false);

    chart.setBackgroundPaint(Color.white);
    chart.setBorderVisible(true);
    chart.setBorderPaint(Color.BLACK);
    TextTitle subtitle = new TextTitle("Four datasets and four range axes.");
    chart.addSubtitle(subtitle);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    XYItemRenderer renderer = plot.getRenderer();
    renderer.setSeriesPaint(0, Color.black);

    // AXIS 2
    NumberAxis axis2 = new NumberAxis("Range Axis 2");
    axis2.setAutoRangeIncludesZero(false);
    axis2.setLabelPaint(Color.red);
    axis2.setTickLabelPaint(Color.red);
    plot.setRangeAxis(1, axis2);
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_LEFT);

    XYDataset dataset2 = createDataset("Series 2", 1000.0, new Minute(), 170);
    plot.setDataset(1, dataset2);
    plot.mapDatasetToRangeAxis(1, 1);
    XYItemRenderer renderer2 = new StandardXYItemRenderer();
    renderer2.setSeriesPaint(0, Color.red);
    plot.setRenderer(1, renderer2);

    // AXIS 3
    NumberAxis axis3 = new NumberAxis("Range Axis 3");
    axis3.setLabelPaint(Color.blue);
    axis3.setTickLabelPaint(Color.blue);
    //axis3.setPositiveArrowVisible(true);
    plot.setRangeAxis(2, axis3);

    XYDataset dataset3 = createDataset("Series 3", 10000.0, new Minute(), 170);
    plot.setDataset(2, dataset3);
    plot.mapDatasetToRangeAxis(2, 2);
    XYItemRenderer renderer3 = new StandardXYItemRenderer();
    renderer3.setSeriesPaint(0, Color.blue);
    plot.setRenderer(2, renderer3);

    // AXIS 4
    NumberAxis axis4 = new NumberAxis("Range Axis 4");
    axis4.setLabelPaint(Color.green);
    axis4.setTickLabelPaint(Color.green);
    plot.setRangeAxis(3, axis4);

    XYDataset dataset4 = createDataset("Series 4", 25.0, new Minute(), 200);
    plot.setDataset(3, dataset4);
    plot.mapDatasetToRangeAxis(3, 3);

    XYItemRenderer renderer4 = new StandardXYItemRenderer();
    renderer4.setSeriesPaint(0, Color.green);
    plot.setRenderer(3, renderer4);

    return chart;
}

From source file:temp1.RealTimeChart.java

public static JFreeChart createChart(String chartContent, String title, String yaxisName) {
    thread1 = new Thread();
    timeseries1 = new TimeSeries(chartContent, Millisecond.class);
    timeseries2 = new TimeSeries(chartContent, Millisecond.class);
    timeseries3 = new TimeSeries(chartContent, Millisecond.class);
    timeseries4 = new TimeSeries(chartContent, Millisecond.class);

    TimeSeriesCollection timeseriescollection = new TimeSeriesCollection(timeseries1);
    TimeSeriesCollection timeseriescollection1 = new TimeSeriesCollection(timeseries2);
    TimeSeriesCollection timeseriescollection2 = new TimeSeriesCollection(timeseries3);
    TimeSeriesCollection timeseriescollection3 = new TimeSeriesCollection(timeseries4);

    jfreechart = ChartFactory.createTimeSeriesChart("", "", "", timeseriescollection, false, false, false);

    final XYPlot xyplot = jfreechart.getXYPlot();
    xyplot.setOutlinePaint(Color.magenta);
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setRangeGridlinePaint(Color.gray);
    xyplot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    ValueAxis valueaxis = xyplot.getDomainAxis();
    valueaxis.setAutoRange(true);// www  .  j  av a2  s.c o  m
    valueaxis.setFixedAutoRange(20000D);
    //Value
    valueaxis = xyplot.getRangeAxis();
    valueaxis.setRange(800D, 3300D);
    xyplot.setDataset(0, timeseriescollection);
    xyplot.setDataset(1, timeseriescollection1);
    xyplot.setDataset(2, timeseriescollection2);
    xyplot.setDataset(3, timeseriescollection3);
    XYLineAndShapeRenderer xylineandshaperenderer0 = new XYLineAndShapeRenderer();
    XYLineAndShapeRenderer xylineandshaperenderer1 = new XYLineAndShapeRenderer();
    XYLineAndShapeRenderer xylineandshaperenderer2 = new XYLineAndShapeRenderer();
    XYLineAndShapeRenderer xylineandshaperenderer3 = new XYLineAndShapeRenderer();
    xylineandshaperenderer0.setBaseShapesVisible(false);
    xylineandshaperenderer1.setBaseShapesVisible(false);
    xylineandshaperenderer2.setBaseShapesVisible(false);
    xylineandshaperenderer3.setBaseShapesVisible(false);
    xylineandshaperenderer0.setSeriesPaint(0, Color.RED);
    xylineandshaperenderer1.setSeriesPaint(0, Color.cyan);
    xylineandshaperenderer2.setSeriesPaint(0, Color.yellow);
    xylineandshaperenderer3.setSeriesPaint(0, Color.blue);
    xyplot.setRenderer(0, xylineandshaperenderer0);
    xyplot.setRenderer(1, xylineandshaperenderer1);
    xyplot.setRenderer(2, xylineandshaperenderer2);
    xyplot.setRenderer(3, xylineandshaperenderer3);
    //xylineandshaperenderer.setSeriesStroke(0, new BasicStroke(0.5F, 1, 1, 5F, new float[] { 5F, 10F }, 0.0F));
    return jfreechart;
}

From source file:cn.edu.thss.iise.bpmdemo.charts.SWTMultipleAxisDemo1.java

/**
 * Creates the demo chart./*w w w  . j a v  a2  s. c o m*/
 *
 * @return The chart.
 */
private static JFreeChart createChart() {

    XYDataset dataset1 = createDataset("Series 1", 100.0, new Day(), 200);

    JFreeChart chart = ChartFactory.createTimeSeriesChart("Multiple Axis Demo 3", "Time of Day",
            "Primary Range Axis", dataset1, true, true, false);

    chart.setBackgroundPaint(Color.white);
    chart.setBorderVisible(true);
    chart.setBorderPaint(Color.BLACK);
    TextTitle subtitle = new TextTitle("Four datasets and four range axes.");
    chart.addSubtitle(subtitle);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    XYItemRenderer renderer = plot.getRenderer();
    renderer.setSeriesPaint(0, Color.black);

    // AXIS 2
    NumberAxis axis2 = new NumberAxis("Range Axis 2");
    axis2.setAutoRangeIncludesZero(false);
    axis2.setLabelPaint(Color.red);
    axis2.setTickLabelPaint(Color.red);
    plot.setRangeAxis(1, axis2);
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_LEFT);

    XYDataset dataset2 = createDataset("Series 2", 1000.0, new Day(), 170);
    plot.setDataset(1, dataset2);
    plot.mapDatasetToRangeAxis(1, 1);
    XYItemRenderer renderer2 = new StandardXYItemRenderer();
    renderer2.setSeriesPaint(0, Color.red);
    plot.setRenderer(1, renderer2);

    // AXIS 3
    NumberAxis axis3 = new NumberAxis("Range Axis 3");
    axis3.setLabelPaint(Color.blue);
    axis3.setTickLabelPaint(Color.blue);
    // axis3.setPositiveArrowVisible(true);
    plot.setRangeAxis(2, axis3);

    XYDataset dataset3 = createDataset("Series 3", 10000.0, new Day(), 170);
    plot.setDataset(2, dataset3);
    plot.mapDatasetToRangeAxis(2, 2);
    XYItemRenderer renderer3 = new StandardXYItemRenderer();
    renderer3.setSeriesPaint(0, Color.blue);
    plot.setRenderer(2, renderer3);

    // AXIS 4
    NumberAxis axis4 = new NumberAxis("Range Axis 4");
    axis4.setLabelPaint(Color.green);
    axis4.setTickLabelPaint(Color.green);
    plot.setRangeAxis(3, axis4);

    XYDataset dataset4 = createDataset("Series 4", 25.0, new Day(), 200);
    plot.setDataset(3, dataset4);
    plot.mapDatasetToRangeAxis(3, 3);

    XYItemRenderer renderer4 = new StandardXYItemRenderer();
    renderer4.setSeriesPaint(0, Color.green);
    plot.setRenderer(3, renderer4);

    return chart;
}

From source file:de.atomfrede.tools.evalutation.tools.plot.TimePlot.java

@Override
protected JFreeChart createChart(XYDatasetWrapper... datasetWrappers) {
    XYDatasetWrapper mainDataset = datasetWrappers[0];

    JFreeChart chart = ChartFactory.createTimeSeriesChart(mainDataset.getSeriesName(), "Time",
            mainDataset.getSeriesName(), mainDataset.getDataset(), true, true, false);

    XYPlot plot = (XYPlot) chart.getPlot();
    // all adjustments for first/main dataset
    plot.getRangeAxis(0).setLowerBound(mainDataset.getMinimum());
    plot.getRangeAxis(0).setUpperBound(mainDataset.getMaximum());
    // some additional "design" stuff for the plot
    plot.getRenderer(0).setSeriesPaint(0, mainDataset.getSeriesColor());
    plot.getRenderer(0).setSeriesStroke(0, new BasicStroke(mainDataset.getStroke()));

    for (int i = 1; i < datasetWrappers.length; i++) {
        XYDatasetWrapper wrapper = datasetWrappers[i];
        plot.setDataset(i, wrapper.getDataset());
        chart.setTitle(chart.getTitle().getText() + "/" + wrapper.getSeriesName());

        NumberAxis axis = new NumberAxis(wrapper.getSeriesName());
        plot.setRangeAxis(i, axis);/*from  ww w.j  a v a2  s.  co m*/
        plot.setRangeAxisLocation(i, AxisLocation.BOTTOM_OR_RIGHT);

        plot.getRangeAxis(i).setLowerBound(wrapper.getMinimum() - 15.0);
        plot.getRangeAxis(i).setUpperBound(wrapper.getMaximum() + 15.0);
        // map the second dataset to the second axis
        plot.mapDatasetToRangeAxis(i, i);

        XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
        renderer.setBaseShapesVisible(false);
        renderer.setSeriesStroke(0, new BasicStroke(wrapper.getStroke()));
        plot.setRenderer(i, renderer);
        plot.getRenderer(i).setSeriesPaint(0, wrapper.getSeriesColor());
    }
    // change the background and gridline colors
    plot.setBackgroundPaint(Color.white);
    plot.setDomainMinorGridlinePaint(Color.LIGHT_GRAY);
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);

    // format the date axis
    DateAxis axis = (DateAxis) plot.getDomainAxis();

    axis.setDateFormatOverride(new SimpleDateFormat("dd.MM HH:mm"));
    axis.setTickUnit(new DateTickUnit(DateTickUnitType.HOUR, 1));
    axis.setVerticalTickLabels(true);
    return chart;
}

From source file:net.sf.statcvs.output.xml.chart.TimeLineChart.java

/**
 * @param filename//from  w ww . j  a v  a 2 s.co  m
 * @param title
 */
public TimeLineChart(String filename, String title) {
    super(filename, title);

    Paint[] colors = new Paint[1];
    colors[0] = Color.blue;

    tsc = new TimeSeriesCollection();
    //collection.addSeries(createTimeSeries(timeline));

    //String range = timeline.getRangeLabel();
    String domain = I18n.tr("Date");

    setChart(ChartFactory.createTimeSeriesChart(Settings.getProjectName(), I18n.tr("Date"), rangeLabel,
            (XYDataset) tsc, true, true, false));

    //getChart().getPlot().setSeriesPaint(colors);

    XYPlot plot = getChart().getXYPlot();
    ValueAxis axis = plot.getDomainAxis();
    axis.setVerticalTickLabels(true);
    plot.setRenderer(new XYStepRenderer());
}

From source file:de.berlios.statcvs.xml.chart.AbstractTimeSeriesChart.java

/**
 * @param filename// w  w w  .  j a v  a  2 s.  c  om
 * @param title
 */
public AbstractTimeSeriesChart(ReportSettings settings, String filename, String title, String rangeLabel) {
    super(settings, filename, title);

    tsc = new TimeSeriesCollection();

    setChart(ChartFactory.createTimeSeriesChart(settings.getProjectName(), I18n.tr("Date"), rangeLabel, tsc,
            true, true, false));

    //Paint[] colors = new Paint[1];
    //colors[0] = Color.blue;
    //getChart().getPlot().setSeriesPaint(colors);

    // setup axis
    XYPlot plot = getChart().getXYPlot();
    ValueAxis axis = plot.getDomainAxis();
    axis.setVerticalTickLabels(true);
    plot.setRenderer(new XYStepRenderer());

    // the 4th color is yellow which has almost no contrast to the white 
    // background color, therefore we use a different color
    plot.getRenderer().setSeriesPaint(0, Color.red);
    plot.getRenderer().setSeriesPaint(1, Color.blue);
    plot.getRenderer().setSeriesPaint(2, Color.green);
    plot.getRenderer().setSeriesPaint(3, Color.magenta);
    plot.getRenderer().setSeriesPaint(4, Color.orange);
    plot.getRenderer().setSeriesPaint(5, Color.cyan);
    plot.getRenderer().setSeriesPaint(6, Color.pink);
}

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

/**
 * Creates a sample chart./*from   w  w w. j a v  a  2 s  .c o  m*/
 * 
 * @param dataset  the dataset.
 * 
 * @return A sample chart.
 */
private JFreeChart createChart(final XYDataset dataset) {
    final JFreeChart result = ChartFactory.createTimeSeriesChart("Client Packets", "Time", "Value", 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, 200.0);
    return result;
}

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

protected ChartPanel createCreditUtilizationRatePanel() {
    TimeSeriesCollection timeSeriesCollection = new TimeSeriesCollection();

    for (Currency currency : Currency.values())
        timeSeriesCollection.addSeries(ApplicationContext.getInstance().getModelRegistry()
                .getNationalEconomyModel(currency).creditUtilizationRateModel.getTimeSeries());

    JFreeChart chart = ChartFactory.createTimeSeriesChart("Credit Utilization Rate", "Date",
            "Credit Utilization Rate", timeSeriesCollection, true, true, false);
    configureChart(chart);/*from   ww  w .j  ava 2 s  .  c  o m*/
    return new ChartPanel(chart);
}