Example usage for org.jfree.data.xy XYSeriesCollection addSeries

List of usage examples for org.jfree.data.xy XYSeriesCollection addSeries

Introduction

In this page you can find the example usage for org.jfree.data.xy XYSeriesCollection addSeries.

Prototype

public void addSeries(XYSeries series) 

Source Link

Document

Adds a series to the collection and sends a DatasetChangeEvent to all registered listeners.

Usage

From source file:cmsc105_mp2.Panels.java

public void createGraph(Data d, float window, Double threshold) {
    XYSeries data = new XYSeries("data");
    double max = Double.MIN_VALUE;
    for (double num : d.plots) {
        if (max < num)
            max = num;/*from  ww w.j a va  2 s  .co m*/
    }
    max += 1;

    ArrayList<XYSeries> xy = new ArrayList();
    ArrayList<Integer> points = new ArrayList();

    for (int j = (int) (window / 2); j < d.plots.length - (window / 2); j++) {
        data.add(j, d.plots[j]);
        //System.out.println(points.size());
        if (d.plots[j] > threshold) {
            points.add(j);
        } else {
            if (points.size() >= window) {
                //System.out.println("MIN!");
                XYSeries series = new XYSeries("trend");
                for (int n : points) {
                    series.add(n, max);
                }
                xy.add(series);
            }
            points = new ArrayList();
        }
    }
    if (points.size() >= window) {
        XYSeries series = new XYSeries("trend");
        for (int n : points) {
            series.add(n, max);
        }
        xy.add(series);
    }
    XYSeriesCollection my_data_series = new XYSeriesCollection();
    my_data_series.addSeries(data);
    for (XYSeries x : xy) {
        my_data_series.addSeries(x);
    }

    XYSeries thresh = new XYSeries("threshold");
    for (int j = 0; j < d.plots.length; j++) {
        thresh.add(j, threshold);
    }
    my_data_series.addSeries(thresh);

    //System.out.println(d.name);
    JFreeChart XYLineChart = ChartFactory.createXYLineChart(d.name, "Position", "Average", my_data_series,
            PlotOrientation.VERTICAL, true, true, false);
    bImage1 = (BufferedImage) XYLineChart.createBufferedImage(690, 337);
    imageIcon = new ImageIcon(bImage1);
    jLabel1.setIcon(imageIcon);
    jLabel1.revalidate();
    jLabel1.repaint();
    jButton1.setText("Save as PNG");
    jButton1.repaint();
    jButton1.revalidate();
    jButton1.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JFileChooser chooser = new JFileChooser();
            chooser.setCurrentDirectory(new File("Documents"));
            int retrival = chooser.showSaveDialog(null);
            if (retrival == JFileChooser.APPROVE_OPTION) {
                try {
                    ImageIO.write(bImage1, "png", new File(chooser.getSelectedFile() + ".png"));
                } catch (IOException ex) {
                    System.out.println("Unable to Print!");
                }
            }
        }
    });
}

From source file:Graphing.graphXY.java

private XYDataset getDataSet() {
    XYSeriesCollection dataSet = new XYSeriesCollection();
    XYSeries series = new XYSeries(this.name);

    for (int i = 0; i < this.x.length; i++) {
        series.add(this.x[i], this.y[i]);
    }//  ww w .  j  ava  2s  . c o  m

    dataSet.addSeries(series);

    return dataSet;
}

From source file:views.analysis.ResidualPlotDisplay.java

public XYDataset createDataset() {
    XYSeriesCollection dataset = new XYSeriesCollection();
    XYSeries serie = new XYSeries("Rsidu");
    for (Point p : this.dataList) {
        double value = p.getValue();
        serie.add(p.getX(), value);/* w w w . j  a  v a 2  s  .com*/
    }
    dataset.addSeries(serie);
    return dataset;
}

From source file:net.sf.smbt.ui.btc.views.AbstractBlockchainView.java

public AbstractBlockchainView() {
    blockchainEngine = QuanticMojo.INSTANCE.createHttpPipe("blockchain", "http://blockchain.info");
    blockchainEngine.addQxEventHandler(new AbstractQxEventHandlerImpl() {
        public synchronized void handleQxEvent(net.sf.xqz.model.engine.Event event) {
            if (event.getKind().equals(EVENT_KIND.RX_DONE)) {
                Cmd cmd = event.getCmd();
                if (cmd instanceof BlockchainCmd) {
                    BlockchainCmd btcCmd = (BlockchainCmd) cmd;
                    final String jsonRcv = btcCmd.getJsonRcv();
                    //System.out.println(jsonRcv);
                    new UbiJob("refresh text") {
                        @Override
                        public IStatus runInUIThread(IProgressMonitor monitor) {
                            Object obj;
                            try {
                                obj = new ObjectMapper().readTree(jsonRcv);
                                XYSeries serie = BlockChainUiUtils.INSTANCE.createSeriesFromJson("serie",
                                        (JsonNode) obj);
                                final XYSeriesCollection dataset = new XYSeriesCollection();
                                dataset.addSeries(serie);
                                chart.getXYPlot().setDataset(dataset);
                            } catch (JsonProcessingException e) {
                                e.printStackTrace();
                            } catch (IOException e) {
                                e.printStackTrace();
                            }// w w w .j ava  2  s .  c  om
                            return Status.OK_STATUS;
                        }
                    }.schedule();
                }
            }
        };
    });
    blockchainEngine.setLocked(true);
    refreshJob = new RefreshJob();
    refreshJob.schedule();
}

From source file:raspihomeapp.ParamForm.java

public void Plotxy() {
    XYSeries series1 = new XYSeries("Punkte1");
    series1.add(5, 0);/*from  w w w.  ja  v a2 s .c o m*/
    series1.add(6, 6);
    series1.add(7, 11);
    series1.add(8, 22);
    series1.add(10, 55);

    XYSeries series2 = new XYSeries("Punkte2");
    series2.add(5, 2);
    series2.add(6, 3);
    series2.add(7, 4);

    // Hinzufuegen von series1 und series2 zu der Datenmenge dataset
    XYSeriesCollection dataset2 = new XYSeriesCollection();
    dataset2.addSeries(series1);
    dataset2.addSeries(series2);

    XYSplineRenderer dot = new XYSplineRenderer();

    NumberAxis xax = new NumberAxis("x");
    NumberAxis yax = new NumberAxis("y");
    //xax.setLabelPaint(Color.WHITE);

    DateAxis taxis = new DateAxis("t");
    taxis.setDateFormatOverride(new SimpleDateFormat("dd-MM"));

    XYPlot plot = new XYPlot(dataset2, taxis, yax, dot);

    //plot.setBackgroundPaint(Color.BLACK);
    //plot.setRangeGridlinePaint(Color.GRAY);

    JFreeChart chart2 = new JFreeChart(" Test ", plot);

    //chart2.setBackgroundPaint(Color.BLACK);

    ChartPanel chartPanel2 = new ChartPanel(chart2);

    chartPanel2.setMouseZoomable(true, false);
    jPanel4.setLayout(new BorderLayout());
    jPanel4.add(chartPanel2, BorderLayout.CENTER);
    //setContentPane(chartPanel2);

}

From source file:ihm.mainActivity.java

/**
 * This method is called from within the constructor to initialize the form.
 * WARNING: Do NOT modify this code. The content of this method is always
 * regenerated by the Form Editor./*from   w ww  .j a  v a2s.  c  om*/
 */

private XYDataset createDataset() {
    final XYSeries sheet = new XYSeries("Serie");
    if (dataList == null) {
        //dataList = new DataList();
        //dataList.addObserver(this);
        dataList.add(new Point(new Date(1970, 1, 1), 5, 7.2));
    }
    int i = 0;
    data = new Object[dataList.size()][3];
    while (i != dataList.size()) {
        Point currentPoint = dataList.getPointAt(i);
        sheet.add(currentPoint.getX(), currentPoint.getValue());
        data[i][0] = currentPoint.getDate();
        data[i][1] = currentPoint.getX();
        data[i][2] = currentPoint.getValue();
        i++;
    }
    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(sheet);
    return dataset;
}

From source file:rework.MainFrame.java

private XYDataset createDataset() {
    final XYSeries sheet = new XYSeries("Serie");
    if (datalist == null) {
        //dataList = new DataList();
        //dataList.addObserver(this);
        datalist.add(new Point(new Date(1970, 1, 1), 5, 7.2));
    }/*from   w w  w.j a  v  a  2 s. com*/
    int i = 0;
    data = new Object[datalist.size()][3];
    while (i != datalist.size()) {
        Point currentPoint = datalist.getPointAt(i);
        sheet.add(currentPoint.getX(), currentPoint.getValue());
        data[i][0] = currentPoint.getDate();
        data[i][1] = currentPoint.getX();
        data[i][2] = currentPoint.getValue();
        i++;
    }
    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(sheet);
    return dataset;
}

From source file:tw.edu.sju.ee.eea.module.iepe.file.IepeSpectrumElement.java

private JFreeChart createChart() {
    XYSeries series = new XYSeries("Ch_0");

    try {/* ww  w .  ja  v  a 2s.  c o  m*/
        ValueInputStream vi = new ValueInputStream(info.getInputStream());
        vi.skip(info.getCursor().getIndex() / 8);
        double[] value = new double[1024 * 16];
        for (int i = 0; i < value.length; i++) {
            value[i] = vi.readValue();
        }

        FastFourierTransformer fft = new FastFourierTransformer(DftNormalization.STANDARD);
        Complex[] data = ComplexUtils.convertToComplex(value);
        Complex[] transform = fft.transform(data, TransformType.FORWARD);
        int max = transform.length / 2 + 1;
        for (int i = 1; i < max; i++) {
            double f = (double) i * info.getSamplerate() / transform.length;
            series.add(f, transform[i].abs() / value.length * 2);
        }

    } catch (FileNotFoundException ex) {
        Exceptions.printStackTrace(ex);
    } catch (IOException ex) {
    }

    XYSeriesCollection collection = new XYSeriesCollection();
    collection.addSeries(series);

    BodePlot bodePlot = new BodePlot("Spectrum");
    bodePlot.addData(0, "Magnitude(dB)", collection);
    bodePlot.getXYPlot().getRangeAxis().setRange(0, 500);
    bodePlot.getXYPlot().getDomainAxis().setRange(0.5, 10000);
    return bodePlot;
}

From source file:statistics.distribution.ConstantDistribution.java

private XYDataset getDataset() {
    XYSeriesCollection dataSet = new XYSeriesCollection();
    XYSeries xySeries = new XYSeries("CDF");
    double x = 0.0;
    for (int i = 0; i < 6; i++) {
        xySeries.add(5, x);/*from   w  ww  . ja  v a 2s . c  om*/
        x += 0.2;
    }
    dataSet.addSeries(xySeries);
    return dataSet;
}

From source file:mrf.Graficar.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    // TODO add your handling code here:
    ScriptEngineManager manager = new ScriptEngineManager();
    ScriptEngine engine = manager.getEngineByName("js");
    ArrayList<Integer> Datosx = new ArrayList<Integer>();
    ArrayList<Double> Datosy = new ArrayList<Double>();
    int in = Integer.parseInt(jTextField2.getText());
    int sup = Integer.parseInt(jTextField3.getText());
    try {/*from  ww w  .ja va  2s .c  o m*/
        XYSeries series = new XYSeries("");
        int inferior = in, superior = sup;
        while (inferior <= superior) {
            Datosx.add(inferior);
            engine.put("X", inferior);
            String a = jTextField1.getText();
            Object operation = engine.eval(a);
            Datosy.add(Double.parseDouble("" + operation));
            jTextArea1.append("Parejas ordenadas " + inferior + ":" + operation + "\n");
            series.add(inferior, Double.parseDouble("" + operation));
            inferior++;
        }

        XYSeriesCollection dataset = new XYSeriesCollection();
        dataset.addSeries(series);

        JFreeChart chart = ChartFactory.createXYLineChart("Grafica del polinomio ingresado", // Ttulo
                "Eje x", // Etiqueta Coordenada X
                "Eje y", // Etiqueta Coordenada Y
                dataset, // Datos
                PlotOrientation.VERTICAL, true, // Muestra la leyenda de los productos (Producto A)              
                false, false);

        // Mostramos la grafica en pantalla
        ChartFrame frame = new ChartFrame("GRAFICA POLINOMIO", chart);
        frame.pack();
        frame.setVisible(true);

    } catch (ScriptException e) {
        e.printStackTrace();
    }

}