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) 

Source Link

Document

Creates and returns a time series chart.

Usage

From source file:DataCharts.LineGraph.java

public static JFreeChart createChart(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createTimeSeriesChart("Customers by Month", "Months", "Customers", dataset);

    String fontName = "SansSerif";
    chart.getTitle().setFont(new Font(fontName, Font.BOLD, 18));
    chart.addSubtitle(new TextTitle(" ", new Font(fontName, Font.PLAIN, 14)));

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setDomainPannable(false);/*  w w w .  ja  v  a2  s .  com*/
    plot.setRangePannable(false);
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    plot.getDomainAxis().setLowerMargin(0.0);
    plot.getDomainAxis().setLabelFont(new Font(fontName, Font.BOLD, 14));
    plot.getDomainAxis().setTickLabelFont(new Font(fontName, Font.PLAIN, 12));

    plot.getRangeAxis().setLabelFont(new Font(fontName, Font.BOLD, 14));
    plot.getRangeAxis().setTickLabelFont(new Font(fontName, Font.PLAIN, 12));

    chart.getLegend().setItemFont(new Font(fontName, Font.PLAIN, 14));
    chart.getLegend().setFrame(BlockBorder.NONE);

    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(true);
        renderer.setDrawSeriesLineAsPath(false);
        // set the default stroke for all series
        renderer.setAutoPopulateSeriesStroke(false);

    }
    return chart;

}

From source file:de.stefanwndelmann.zy1270logger.Test.TestJFreeChart.java

private void initJFreeChart() {
    voltageSeries = new TimeSeries("Voltage");
    ampSeries = new TimeSeries("Amps");
    dataset = new TimeSeriesCollection(voltageSeries);
    dataset.addSeries(ampSeries);//from   w  ww .jav a2  s.  c  o m
    chart = ChartFactory.createTimeSeriesChart("Test Chart", "Time (seconds)", "U/I", dataset);
    DateAxis axis = (DateAxis) chart.getXYPlot().getDomainAxis();
    //        axis.setTickUnit(new DateTickUnit(DateTickUnitType.MILLISECOND, 1));
    axis.setTickMarkPosition(DateTickMarkPosition.START);
    axis.setDateFormatOverride(new SimpleDateFormat("HH:mm:ss.SSS"));
    chart.setAntiAlias(true);
    chart.setTextAntiAlias(true);
    this.add(new ChartPanel(chart), BorderLayout.CENTER);
}

From source file:UserInterface.PatientRole.VitalSignsChartJPanel.java

/**
 * Creates new form VitalSignsChartJPanel
 *///from  w w  w.  ja  va 2  s  .  com
public VitalSignsChartJPanel(JPanel userProcessContainer, UserAccount userAccount,
        PatientOrganization patientOrganization, Enterprise enterprise, EcoSystem ecoSyste) {
    initComponents();
    this.userProcessContainer = userProcessContainer;
    this.ecoSystem = ecoSystem;
    this.userAccount = userAccount;
    this.patientOrganization = (PatientOrganization) patientOrganization;
    this.enterprise = enterprise;
    this.patient = userAccount.getPatient();

    XYDataset data = createXYDataset();
    JFreeChart chart = ChartFactory.createTimeSeriesChart(patient.getPatientName(), "Time", "Data", data);

    ChartPanel chartPanel = new ChartPanel(chart);
    this.add(chartPanel, BorderLayout.CENTER);
    this.validate();
}

From source file:org.jfree.graphics2d.demo.SVGTimeSeriesChartDemo1.java

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

    JFreeChart chart = ChartFactory.createTimeSeriesChart("International Coffee Organisation : Coffee Prices",
            null, "US cents/lb", dataset);

    String fontName = "Palatino";
    chart.getTitle().setFont(new Font(fontName, Font.BOLD, 18));
    chart.addSubtitle(new TextTitle("Source: http://www.ico.org/historical/2010-19/PDF/HIST-PRICES.pdf",
            new Font(fontName, Font.PLAIN, 14)));

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setDomainPannable(true);
    plot.setRangePannable(false);
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    plot.getDomainAxis().setLowerMargin(0.0);
    plot.getDomainAxis().setLabelFont(new Font(fontName, Font.BOLD, 14));
    plot.getDomainAxis().setTickLabelFont(new Font(fontName, Font.PLAIN, 12));
    plot.getRangeAxis().setLabelFont(new Font(fontName, Font.BOLD, 14));
    plot.getRangeAxis().setTickLabelFont(new Font(fontName, Font.PLAIN, 12));
    plot.setRangeGridlinePaint(Color.GRAY);
    plot.setDomainGridlinePaint(Color.GRAY);
    chart.getLegend().setItemFont(new Font(fontName, Font.PLAIN, 14));
    chart.getLegend().setFrame(BlockBorder.NONE);
    chart.getLegend().setHorizontalAlignment(HorizontalAlignment.CENTER);
    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(false);
        renderer.setDrawSeriesLineAsPath(true);
        // set the default stroke for all series
        renderer.setAutoPopulateSeriesStroke(false);
        renderer.setDefaultStroke(new BasicStroke(3.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL), false);
        renderer.setSeriesPaint(0, Color.RED);
        renderer.setSeriesPaint(1, new Color(24, 123, 58));
        renderer.setSeriesPaint(2, new Color(149, 201, 136));
        renderer.setSeriesPaint(3, new Color(1, 62, 29));
        renderer.setSeriesPaint(4, new Color(81, 176, 86));
        renderer.setSeriesPaint(5, new Color(0, 55, 122));
        renderer.setSeriesPaint(6, new Color(0, 92, 165));
    }

    return chart;

}

From source file:org.jfree.graphics2d.demo.SVGChartWithAnnotationsDemo1.java

/**
 * Creates a sample chart.//from w  ww.  j a  v  a 2 s . com
 *
 * @param dataset  a dataset for the chart.
 *
 * @return A sample chart.
 */
private static JFreeChart createChart(XYDataset dataset) {
    JFreeChart chart = ChartFactory.createTimeSeriesChart("XYDrawableAnnotationDemo1", null, "$ million",
            dataset);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setDomainPannable(true);
    plot.setRangePannable(true);
    DateAxis xAxis = (DateAxis) plot.getDomainAxis();
    xAxis.setLowerMargin(0.2);
    xAxis.setUpperMargin(0.2);
    xAxis.setStandardTickUnits(createStandardDateTickUnits());

    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setLowerMargin(0.2);
    yAxis.setUpperMargin(0.2);

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setBaseShapesVisible(true);
    renderer.setBaseLinesVisible(true);
    renderer.setSeriesShape(0, new Ellipse2D.Double(-5.0, -5.0, 10.0, 10.0));
    renderer.setSeriesShape(1, new Ellipse2D.Double(-5.0, -5.0, 10.0, 10.0));
    renderer.setSeriesStroke(0, new BasicStroke(3.0f));
    renderer.setSeriesStroke(1, new BasicStroke(3.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 5.0f,
            new float[] { 10.0f, 5.0f }, 0.0f));
    renderer.setSeriesFillPaint(0, Color.white);
    renderer.setSeriesFillPaint(1, Color.white);
    renderer.setUseFillPaint(true);

    renderer.setDefaultToolTipGenerator(new StandardXYToolTipGenerator());
    renderer.setDefaultEntityRadius(6);

    renderer.addAnnotation(new XYDrawableAnnotation(new Month(4, 2005).getFirstMillisecond(), 600, 180, 100,
            3.0, createPieChart()));
    renderer.addAnnotation(new XYDrawableAnnotation(new Month(9, 2007).getFirstMillisecond(), 1250, 120, 100,
            2.0, createBarChart()));
    plot.setRenderer(renderer);
    return chart;
}

From source file:org.softinica.maven.jmeter.report.analyser.ValueByTimestampAnalyzer.java

@Override
protected JFreeChart createChart(PageDefinition definition, Input input) {
    Map<String, Map<Long, Double>> allSeries = new HashMap<String, Map<Long, Double>>();
    for (Sample sample : input.getSamples()) {
        Map<Long, Double> duration = allSeries.get(sample.getLabel());
        if (duration == null) {
            duration = new HashMap<Long, Double>();
            allSeries.put(sample.getLabel(), duration);
        }/*from   w ww .j  a  va2s .  co m*/
        duration.put(sample.getTimestamp(), sample.getValue());
    }
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    for (String label : allSeries.keySet()) {
        Map<Long, Double> duration = allSeries.get(label);
        TimeSeries series = new TimeSeries(label);
        for (Long key : duration.keySet()) {
            series.addOrUpdate(new Millisecond(new Date(key)), duration.get(key));
        }
        dataset.addSeries(series);
    }

    return ChartFactory.createTimeSeriesChart(definition.getTitle(), "Time", "Value", dataset);
}

From source file:org.softinica.maven.jmeter.report.analyser.ResponseSizeAnalyzer.java

@Override
protected JFreeChart createChart(PageDefinition definition, Input input) {
    Map<String, Map<Long, Long>> allSeries = new HashMap<String, Map<Long, Long>>();
    for (Sample sample : input.getSamples()) {
        Map<Long, Long> duration = allSeries.get(sample.getLabel());
        if (duration == null) {
            duration = new HashMap<Long, Long>();
            allSeries.put(sample.getLabel(), duration);
        }/*www .jav  a2 s .co  m*/
        duration.put((sample.getTimestamp() + (long) sample.getValue()), (long) sample.getByteCount());
    }
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    for (String label : allSeries.keySet()) {
        Map<Long, Long> duration = allSeries.get(label);
        TimeSeries series = new TimeSeries(label);
        for (Long key : duration.keySet()) {
            series.addOrUpdate(new Millisecond(new Date(key)), duration.get(key));
        }
        dataset.addSeries(series);
    }

    return ChartFactory.createTimeSeriesChart(definition.getTitle(), "Time", "Size(bytes)", dataset);
}

From source file:org.softinica.maven.jmeter.report.analyser.RequestDurationAnalyzer.java

@Override
protected JFreeChart createChart(PageDefinition definition, Input input) {
    Map<String, Map<Long, Long>> allSeries = new HashMap<String, Map<Long, Long>>();
    for (Sample sample : input.getSamples()) {
        Map<Long, Long> duration = allSeries.get(sample.getLabel());
        if (duration == null) {
            duration = new HashMap<Long, Long>();
            allSeries.put(sample.getLabel(), duration);
        }//from   w  w w  .j ava  2  s .c om
        duration.put((sample.getTimestamp() + (long) sample.getValue()), (long) sample.getValue());
    }
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    for (String label : allSeries.keySet()) {
        Map<Long, Long> duration = allSeries.get(label);
        TimeSeries series = new TimeSeries(label);
        for (Long key : duration.keySet()) {
            series.addOrUpdate(new Millisecond(new Date(key)), duration.get(key));
        }
        dataset.addSeries(series);
    }

    return ChartFactory.createTimeSeriesChart(definition.getTitle(), "Time", "Duration", dataset);
}

From source file:de.stefanwndelmann.zy1270logger.ZY1270LoggerMain.java

private void initJFreeChart() {
    voltageSeries = new TimeSeries("Voltage");
    ampSeries = new TimeSeries("Amps");
    wattSeries = new TimeSeries("Watt");
    dataset = new TimeSeriesCollection(voltageSeries);
    dataset.addSeries(ampSeries);// w  w  w .j  av a  2s  .c o  m
    dataset.addSeries(wattSeries);
    chart = ChartFactory.createTimeSeriesChart("Live Data", "Time", "U/I/P", dataset);
    DateAxis axis = (DateAxis) chart.getXYPlot().getDomainAxis();
    axis.setTickMarkPosition(DateTickMarkPosition.START);
    axis.setDateFormatOverride(new SimpleDateFormat("HH:mm:ss.SSS"));
    chart.setAntiAlias(true);
    chart.setTextAntiAlias(true);
    chartPanel = new ChartPanel(chart);
    jFreeChartPanel.add(chartPanel, BorderLayout.CENTER);
}

From source file:org.softinica.maven.jmeter.report.analyser.ThroughputAnalyzer.java

@Override
protected JFreeChart createChart(PageDefinition definition, Input input) {
    Map<String, Multiset<Long>> allSeries = new HashMap<String, Multiset<Long>>();
    for (Sample sample : input.getSamples()) {
        Multiset<Long> rps = allSeries.get(sample.getLabel());
        if (rps == null) {
            rps = TreeMultiset.create();
            allSeries.put(sample.getLabel(), rps);
        }//from w  w w  . java2s . c o m
        rps.add(((sample.getTimestamp() + (long) sample.getValue()) / 1000) * 1000);
    }
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    for (String label : allSeries.keySet()) {
        Multiset<Long> rps = allSeries.get(label);
        TimeSeries series = new TimeSeries(label);
        for (Long key : rps) {
            series.addOrUpdate(new Second(new Date(key)), rps.count(key));
        }
        dataset.addSeries(series);
    }

    return ChartFactory.createTimeSeriesChart(definition.getTitle(), "Time", "Requests/second", dataset);
}