Example usage for org.jfree.chart ChartFactory createXYLineChart

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

Introduction

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

Prototype

public static JFreeChart createXYLineChart(String title, String xAxisLabel, String yAxisLabel,
        XYDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) 

Source Link

Document

Creates a line chart (based on an XYDataset ) with default settings.

Usage

From source file:it.sidgrid.sextante.tools.MultiProfileVectorAlgorithm.java

@Override
public boolean processAlgorithm() throws GeoAlgorithmExecutionException {

    int i;/*from   w  w  w.jav  a  2 s. c om*/

    serie = new XYSeries(Sextante.getText("Profile"));
    dataset.addSeries(serie);

    final IVectorLayer lines = m_Parameters.getParameterValueAsVectorLayer(ROUTE);

    if (lines.getShapesCount() == 0) {
        throw new GeoAlgorithmExecutionException(Sextante.getText("Zero_lines_in_layer"));
    }

    final ArrayList<?> layers = m_Parameters.getParameterValueAsArrayList(LAYERS);
    m_DEM = m_Parameters.getParameterValueAsVectorLayer(DEM);

    // Recupero l'indice dei campi TOP e BOTTOM
    field_TOP_idx = m_DEM.getFieldIndexByName("TOP");
    //      System.out.println("TOP "+field_TOP_idx);
    field_BOTTOM_idx = m_DEM.getFieldIndexByName("BOTTOM");
    //      System.out.println("BOTTOM "+field_BOTTOM_idx);
    // TODO: Segnalare all'utente il motivo della chiusura
    if (field_TOP_idx < 0 || field_BOTTOM_idx < 0)
        return false;

    XYSeries multiserie;

    // Recupero i layer passati all'algoritmo
    m_Layer = new IVectorLayer[layers.size()];
    for (i = 0; i < layers.size(); i++) {
        m_Layer[i] = (IVectorLayer) layers.get(i);
    }

    for (i = 0; i < layers.size(); i++) {
        multiserie = new XYSeries(m_Layer[i].getName());
        dataset.addSeries(multiserie);
    }

    // Aggiungo una serie per il TOP del DEM, gli altri saranno i BOTTOM.
    top_dem = new XYSeries("TOP_DEM");
    dataset.addSeries(top_dem);

    // Un iteratore per recuperare solo la prima linea?
    final IFeatureIterator iterator = lines.iterator();
    final Geometry line = iterator.next().getGeometry().getGeometryN(0);
    precedenti = new double[line.getCoordinates().length];
    // Pre-processing
    long start = System.currentTimeMillis();
    pre_processLine(line);
    long mid = System.currentTimeMillis();
    System.out.println("Pre_process time was " + (mid - start) + " ms.");

    // Eseguo l'algoritmo
    // long start = System.currentTimeMillis();
    processLine(line);
    long end = System.currentTimeMillis();
    System.out.println("Process time was " + (end - mid) + " ms.");
    System.out.println("Total time was " + (end - start) + " ms.");
    iterator.close();

    // Passo i risultati al grafico
    final JFreeChart chart = ChartFactory.createXYLineChart(null, null, null, dataset, PlotOrientation.VERTICAL,
            false, true, true);

    // Imposto il renderer
    XYSplineRenderer my_renderer = new XYSplineRenderer();
    //   my_renderer.setBaseShapesVisible(false);
    my_renderer.setBaseToolTipGenerator(chart.getXYPlot().getRenderer().getBaseToolTipGenerator());
    chart.getXYPlot().setRenderer(my_renderer);

    // Display del grafico in un panel
    final ChartPanel jPanelChart = new ChartPanel(chart);
    jPanelChart.setPreferredSize(new java.awt.Dimension(500, 300));
    jPanelChart.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.gray, 1));

    addOutputChart(GRAPH, Sextante.getText("Profile"), jPanelChart);

    return !m_Task.isCanceled();
}

From source file:utilities.GraphViewer.java

private ChartPanel graphe() {

    JFreeChart graph = ChartFactory.createXYLineChart("Sensors Energy", "Time", "Energy", dataset,
            PlotOrientation.VERTICAL, true, true, false);

    ChartPanel cPanel = new ChartPanel(graph);
    cPanel.setBackground(Color.blue);
    cPanel.setPreferredSize(new Dimension(800, 600));

    XYPlot plot = graph.getXYPlot();/*  w w  w. ja  v  a  2 s . c om*/
    plot.setBackgroundPaint(Color.WHITE);
    plot.setOutlinePaint(Color.BLACK);
    plot.setRangeGridlinePaint(Color.BLACK);

    return cPanel;
}

From source file:com.artnaseef.jmeter.report.ResultCodesPerSecondReport.java

protected void createChart() {
    // create the chart...
    this.chart = ChartFactory.createXYLineChart("Result Codes per " + this.yAxisLabel, // chart title
            this.yAxisLabel, // x axis label
            "Hits", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );/*from ww w .j  a v a2  s  .  c  om*/
}

From source file:edu.ucla.stat.SOCR.chart.demo.QQData2DataDemo.java

/**
 * Creates a chart./*from  w  ww .  ja  v a 2 s.  c  o  m*/
 *
 * @param dataset  the data for the chart.
 *
 * @return a chart.
 */
protected JFreeChart createChart(XYDataset dataset) {

    // create the chart...
    JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, //"Data vs Data Q-Q plot",      // chart title
            domainLabel, // x axis label
            rangeLabel, // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, !legendPanelOn, // include legend
            true, // tooltips
            false // urls
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    // renderer.setShapesVisible(true);
    renderer.setBaseShapesFilled(true);
    //  renderer.setLinesVisible(false);
    renderer.setSeriesLinesVisible(1, true);
    renderer.setSeriesShapesVisible(1, false);
    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesShapesVisible(0, true);

    //renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator());

    // change the auto tick unit selection to integer units only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setAutoRangeIncludesZero(false);
    rangeAxis.setUpperMargin(0.02);
    rangeAxis.setLowerMargin(0.02);

    // rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setAutoRangeIncludesZero(false);
    domainAxis.setUpperMargin(0.02);
    domainAxis.setLowerMargin(0.02);

    // domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // OPTIONAL CUSTOMISATION COMPLETED.
    setQQSummary(dataset);
    return chart;

}

From source file:org.jboss.console.manager.interfaces.impl.GraphMBeanAttributeAction.java

public void doAction(TreeContext tc, AppletBrowser applet) {
    try {//from w w  w .  j a v  a2  s. c om
        if (frame == null) {
            //tc.getRemoteMBeanInvoker ().invoke(targetObjectName, actionName, params, signature);
            dataset = new MBeanXYDataset();
            JFreeChart chart = ChartFactory.createXYLineChart("JMX Attribute: " + attr, "count", attr, dataset,
                    PlotOrientation.VERTICAL, true, true, false);
            UpdateThread update = new UpdateThread(dataset, tc);

            Thread thread = new Thread(update);
            thread.start();
            frame = new ChartFrame("JMX Attribute: " + attr, chart);
            frame.getChartPanel().setPreferredSize(new java.awt.Dimension(500, 270));
            frame.pack();
        } else {
            dataset.clear();
        }
        frame.show();
        frame.requestFocus();
    } catch (Exception displayed) {
        displayed.printStackTrace();
    }
}

From source file:presentationGui.GraphFrame.java

/**
 * Creates a chart./*from w w  w.j  a  va  2  s.co m*/
 *
 * @param dataset the data for the chart.
 *
 * @return a chart.
 */
private JFreeChart createChart(final XYDataset dataset) {

    // create the chart...
    final JFreeChart chart = ChartFactory.createXYLineChart("Comportamento Asintotico del throughput", // chart title
            "numero job", // x axis label
            "throughput", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white);

    //        final StandardLegend legend = (StandardLegend) chart.getLegend();
    //      legend.setDisplaySeriesShapes(true);
    // get a reference to the plot for further customisation...
    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.white);
    //    plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesShapesVisible(1, false);
    plot.setRenderer(renderer);

    // change the auto tick unit selection to integer units only...
    /*final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits());*/
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}

From source file:patientview.HistoryJFrame.java

public void genGraph(int code) {
    //ArrayList<LiveData> data = thisPatient.getLiveDatahistory(timerCSeconds); //Displays live data up untill the current moment
    ArrayList<LiveData> data = thisPatient.getAllLiveData();

    //create and populate graph
    XYSeries rr = new XYSeries("Respiratory rate (breaths/min)");
    XYSeries os = new XYSeries("Oxygen saturation (%)");
    XYSeries t = new XYSeries("Temperature (C)");
    XYSeries sbp = new XYSeries("Systolic blood pressure (mmHg)");
    XYSeries hr = new XYSeries("Heart rate (beats/min)");

    for (int i = 0; i < data.size(); i++) {
        rr.add(i * 5, data.get(i).rr);//from  www.  j a v  a2s.  com
        os.add(i * 5, data.get(i).os);
        t.add(i * 5, data.get(i).t);
        sbp.add(i * 5, data.get(i).sbp);
        hr.add(i * 5, data.get(i).hr);
    }

    XYDataset xyDataset1 = new XYSeriesCollection(rr);
    XYDataset xyDataset2 = new XYSeriesCollection(os);
    XYDataset xyDataset3 = new XYSeriesCollection(t);
    XYDataset xyDataset4 = new XYSeriesCollection(sbp);
    XYDataset xyDataset5 = new XYSeriesCollection(hr);

    JFreeChart chart = ChartFactory.createXYLineChart(thisPatient.getFullName(), "Time (s)", "", null,
            PlotOrientation.VERTICAL, true, true, false);

    this.plot = chart.getXYPlot();

    this.plot.setRenderer(0, new StandardXYItemRenderer());
    this.plot.setRenderer(1, new StandardXYItemRenderer());
    this.plot.setRenderer(2, new StandardXYItemRenderer());
    this.plot.setRenderer(3, new StandardXYItemRenderer());
    this.plot.setRenderer(4, new StandardXYItemRenderer());

    boolean markers = false;
    if ((code & 32) == 32) {
        markers = true;
    }
    //respiratory rate
    if ((code & 1) == 1) {
        this.plot.setDataset(0, xyDataset1);
        if (markers) {
            IntervalMarker zone = new IntervalMarker(9, 20);
            zone.setPaint(new Color(255, 0, 0, 64));
            plot.addRangeMarker(zone);
        }
        this.plot.getRendererForDataset(plot.getDataset(0)).setSeriesPaint(0, Color.red);
    }
    //oxygen saturation
    if ((code & 2) == 2) {
        this.plot.setDataset(1, xyDataset2);
        if (markers) {
            IntervalMarker zone = new IntervalMarker(93, 100);
            zone.setPaint(new Color(0, 255, 0, 64));
            plot.addRangeMarker(zone);
        }
        this.plot.getRendererForDataset(plot.getDataset(1)).setSeriesPaint(0, Color.green);
    }
    //temperature
    if ((code & 4) == 4) {
        this.plot.setDataset(2, xyDataset3);
        if (markers) {
            IntervalMarker zone = new IntervalMarker(36, 37.9);
            zone.setPaint(new Color(0, 0, 255, 64));
            plot.addRangeMarker(zone);
        }
        this.plot.getRendererForDataset(plot.getDataset(2)).setSeriesPaint(0, Color.blue);
    }
    //systolic blood pressure
    if ((code & 8) == 8) {
        this.plot.setDataset(3, xyDataset4);
        if (markers) {
            IntervalMarker zone = new IntervalMarker(100, 199);
            zone.setPaint(new Color(255, 255, 0, 64));
            plot.addRangeMarker(zone);
        }
        this.plot.getRendererForDataset(plot.getDataset(3)).setSeriesPaint(0, Color.yellow);
    }
    //heart rate
    if ((code & 16) == 16) {
        this.plot.setDataset(4, xyDataset5);
        if (markers) {
            IntervalMarker zone = new IntervalMarker(50, 99);
            zone.setPaint(new Color(255, 0, 255, 64));
            plot.addRangeMarker(zone);
        }
        this.plot.getRendererForDataset(plot.getDataset(4)).setSeriesPaint(0, Color.magenta);
    }

    graphPanel.removeAll();
    cp = new ChartPanel(chart);
    cp.setMouseWheelEnabled(true);
    cp.setPreferredSize(new Dimension(640, 480));
    graphPanel.setLayout(new java.awt.BorderLayout());
    graphPanel.add(cp, java.awt.BorderLayout.CENTER);
    graphPanel.validate();

}

From source file:de.dfki.owlsmx.gui.ResultVisualization.java

private JFreeChart createMemoryChart() {
    XYSeriesCollection data = new XYSeriesCollection();
    Map memory = MemoryContainer.getInstance().getStoredValues();
    //       System.err.println("Memory consumption: " + memory);
    data.addSeries(createSeriesFromDataMap(memory));
    JFreeChart chart = ChartFactory.createXYLineChart("Memoryconsumption", "Services", "Memory (KByte)", data,
            org.jfree.chart.plot.PlotOrientation.VERTICAL, true, true, false);
    XYPlot plot = chart.getXYPlot();/*from w w  w .  ja  v a 2 s  .c  om*/
    XYItemRenderer renderer = (XYItemRenderer) plot.getRenderer();
    renderer.setSeriesPaint(0, Color.red);
    chart.removeLegend();
    return chart;
}

From source file:edu.fullerton.viewerplugin.XYPlotter.java

private ChartPanel getPanel(double[][] data) throws WebUtilException {
    ChartPanel ret = null;/*from  w w  w. j  a  va2 s.c  o m*/
    try {
        XYSeries xys;
        XYSeriesCollection mtds = new XYSeriesCollection();
        String mylegend = legend == null || legend.isEmpty() ? "series 1" : legend;

        xys = new XYSeries(legend);

        int len = data.length;
        double minx = Double.MAX_VALUE;
        double maxx = Double.MIN_VALUE;
        double miny = Double.MAX_VALUE;
        double maxy = Double.MIN_VALUE;
        boolean gotZeroX = false;
        boolean gotZeroY = false;

        for (int i = 0; i < len; i++) {
            double x = data[i][0];
            double y = data[i][1];
            if (x == 0) {
                gotZeroX = true;
            } else {
                minx = Math.min(minx, x);
                maxx = Math.max(maxx, x);
            }
            if (y == 0) {
                gotZeroY = true;
            } else {
                miny = Math.min(miny, y);
                maxy = Math.max(maxy, y);
            }
        }
        // this kludge lets us plot a 0 on a log axis
        double fakeZeroX = 0.;
        double fakeZeroY = 0.;
        if (gotZeroX) {
            if (logXaxis) {
                fakeZeroX = minx / 10;
            } else {
                minx = Math.min(0, minx);
                maxx = Math.max(0, maxx);
            }
        }
        if (gotZeroY) {
            if (logYaxis) {
                fakeZeroY = miny / 10;
            } else {
                miny = Math.min(0, miny);
                maxy = Math.max(0, maxy);
            }
        }
        for (int i = 0; i < len; i++) {
            double x = data[i][0];
            double y = data[i][1];
            x = x == 0 ? fakeZeroX : x;
            y = y == 0 ? fakeZeroY : y;
            xys.add(x, y);
        }
        mtds.addSeries(xys);

        DefaultXYDataset ds = new DefaultXYDataset();

        int exp;
        if (maxy == 0. && miny == 0.) {
            miny = -1.;
            exp = 0;
            logYaxis = false;
        } else {

            maxy = maxy > miny ? maxy : miny * 10;
            exp = PluginSupport.scaleRange(mtds, miny, maxy);
            if (!logYaxis && exp > 0) {
                yLabel += " x 1e-" + Integer.toString(exp);
            }
        }
        JFreeChart chart = ChartFactory.createXYLineChart(title, xLabel, yLabel, ds, PlotOrientation.VERTICAL,
                true, false, false);
        org.jfree.chart.plot.XYPlot plot = (org.jfree.chart.plot.XYPlot) chart.getPlot();
        if (logYaxis) {
            LogAxis rangeAxis = new LogAxis(yLabel);
            double smallest = miny * Math.pow(10, exp);
            rangeAxis.setSmallestValue(smallest);
            rangeAxis.setMinorTickCount(9);

            LogAxisNumberFormat lanf = new LogAxisNumberFormat();
            lanf.setExp(exp);
            rangeAxis.setNumberFormatOverride(lanf);
            rangeAxis.setRange(smallest, maxy * Math.pow(10, exp));
            plot.setRangeAxis(rangeAxis);
        }
        if (logXaxis) {
            LogAxis domainAxis = new LogAxis(xLabel);
            domainAxis.setMinorTickCount(9);
            domainAxis.setSmallestValue(minx);
            domainAxis.setNumberFormatOverride(new LogAxisNumberFormat());
            plot.setDomainAxis(domainAxis);
        }
        ValueAxis domainAxis = plot.getDomainAxis();
        if (fmin != null && fmin > 0) {
            domainAxis.setLowerBound(fmin);
        }
        if (fmax != null && fmax > 0) {
            domainAxis.setUpperBound(fmax);
        }
        plot.setDomainAxis(domainAxis);
        plot.setDataset(0, mtds);

        // Set the line thickness
        XYLineAndShapeRenderer r = (XYLineAndShapeRenderer) plot.getRenderer();
        BasicStroke str = new BasicStroke(lineThickness);
        int n = plot.getSeriesCount();
        for (int i = 0; i < n; i++) {
            r.setSeriesStroke(i, str);
        }

        if (legend == null || legend.isEmpty()) {
            chart.removeLegend();
        }
        ret = new ChartPanel(chart);
    } catch (Exception ex) {
        throw new WebUtilException("Creating spectrum plot" + ex.getLocalizedMessage());
    }
    return ret;

}

From source file:org.drugis.addis.gui.ConvergencePlotsDialog.java

private JFreeChart createRhatChart(final XYDataset dataset) {
    final JFreeChart RhatChart = ChartFactory.createXYLineChart("Iterative PSRF Plot", "Iteration No.",
            "R-Hat(p)", dataset, PlotOrientation.VERTICAL, false, true, false);

    RhatChart.setBackgroundPaint(Color.white);
    final XYPlot RhatPlot = RhatChart.getXYPlot();
    RhatPlot.setDomainGridlinePaint(Color.white);
    RhatPlot.setRangeGridlinePaint(Color.white);

    final NumberAxis rangeAxis = (NumberAxis) RhatPlot.getRangeAxis();
    rangeAxis.setAutoRange(true);/*from   w w  w.  ja  v  a2s . com*/
    rangeAxis.setAutoRangeIncludesZero(false);

    return RhatChart;
}