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

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

Introduction

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

Prototype

public void removeSeries(XYSeries series) 

Source Link

Document

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

Usage

From source file:org.jfree.data.xy.XYSeriesTest.java

@Test
public void testSetKey() {
    XYSeries s1 = new XYSeries("S");
    s1.setKey("S1");
    assertEquals("S1", s1.getKey());

    XYSeriesCollection c = new XYSeriesCollection();
    c.addSeries(s1);//from  w w w  . j av  a2 s .com
    XYSeries s2 = new XYSeries("S2");
    c.addSeries(s2);

    // now we should be allowed to change s1's key to anything but "S2"
    s1.setKey("OK");
    assertEquals("OK", s1.getKey());

    try {
        s1.setKey("S2");
        fail("Expect an exception here.");
    } catch (IllegalArgumentException e) {
        // OK
    }

    // after s1 is removed from the collection, we should be able to set
    // the key to anything we want...
    c.removeSeries(s1);
    s1.setKey("S2");

    // check that removing by index also works
    s1.setKey("S1");
    c.addSeries(s1);
    c.removeSeries(1);
    s1.setKey("S2");
}

From source file:jamel.gui.charts.TwoSeriesScatterChart.java

/**
 * Sets the time range.//from  w w w. j  av a 2  s.com
 * 
 * @param lower  the lower date limit.
 * @param upper  the upper date limit.
 */
public void setTimeRange(Date lower, Date upper) {
    XYSeriesCollection dataset = (XYSeriesCollection) ((XYPlot) this.getPlot()).getDataset(); // nouvelle collection de sries
    if (((this.begin == null) | (this.end == null))
            || ((!this.begin.equals(lower)) | (!this.end.equals(upper)))) {
        this.begin = lower;
        this.end = upper;
        int minIndex = 0; // dfinit l'index des donnes correspondant  la date de dbut
        try {
            minIndex = this.xTimeSeries.getIndex(RegularTimePeriod
                    .createInstance(this.xTimeSeries.getTimePeriodClass(), lower, TimeZone.getDefault()));
        } catch (IllegalArgumentException i) {
        }
        if (minIndex < 0)
            minIndex = 0; // rectifie ventuellement le rsultat
        int maxIndex = this.xTimeSeries.getItemCount() - 1;
        try {
            maxIndex = this.xTimeSeries.getIndex(RegularTimePeriod
                    .createInstance(this.xTimeSeries.getTimePeriodClass(), upper, TimeZone.getDefault()));
        } catch (IllegalArgumentException i) {
        } // dfinit l'index des donnes correspondant  la date de fin
        if (maxIndex < 0)
            maxIndex = this.xTimeSeries.getItemCount() - 1; // rectifie ventuellement le rsultat
        XYSeries newSeries = new XYSeries("XY Data", false); // cre une nouvelle srie
        for (int index = minIndex; index <= maxIndex - 1; index++) {
            RegularTimePeriod currentPeriod = this.xTimeSeries.getTimePeriod(index); // rcupre la priode courante
            if (this.yTimeSeries.getValue(currentPeriod) != null)
                newSeries.add(this.xTimeSeries.getValue(currentPeriod),
                        this.yTimeSeries.getValue(currentPeriod));
        }
        try {
            dataset.removeSeries(0);
        } // efface la srie actuelle
        catch (IllegalArgumentException i) {
        } // au cas o il n'y aurait pas de sries  enlever (la premire fois)
        dataset.addSeries(newSeries);
    }

}

From source file:mineria.UI.java

public UI() {
    this.setLayout(new GridBagLayout());

    Label lblnodatos = new Label("NoDatos: ");
    Label label = new Label("BD: ");
    JTextField filename = new JTextField("/Users/eduardomartinez/Documents/mineria/representacion.txt");
    JTextField nodatos = new JTextField();
    nodatos.setText("500");

    JTextField funcion = new JTextField("6");
    JTextField individuos = new JTextField("200");
    JTextField enteros = new JTextField("1");
    JTextField decimales = new JTextField("40");
    JTextField variables = new JTextField("6");
    JTextField Pc = new JTextField("0.9");
    JTextField Pm = new JTextField("0.01");
    JTextField generaciones = new JTextField("100");
    JTextField minimiza = new JTextField("0");

    Label lblfuncion = new Label("funcion: ");
    Label lblindividuos = new Label("individuos: ");
    Label lblenteros = new Label("enteros: ");
    Label lbldecimales = new Label("decimales: ");
    Label lblvariables = new Label("variables: ");
    Label lblpc = new Label("Pc: ");
    Label lblpm = new Label("Pm: ");
    Label lblgeneraciones = new Label("generaciones: ");
    Label lblminimiza = new Label("[0 Min/1 Max] : ");

    /*/*from w  w  w.j av  a 2s .co m*/
    FN=funcion;
    N =individuos;
    E =bits_enteros;
    D =bits_decimales;
    V =variables;
    Pc=porcentaje_cruza;
    Pm=porcentaje_muta;
    G =generaciones;
    MM=minimiza;
    */

    JButton openBtn = new JButton("Open BD");
    JButton ejecutarEGA = new JButton("Ejecutar EGA");
    JTextField resultado = new JTextField();
    Label fitness = new Label("fitness: ");

    XYSeriesCollection datosSerie = new XYSeriesCollection();

    AGF agf = new AGF(2);
    EGA ega = new EGA();

    JFreeChart chart = ChartFactory.createScatterPlot("Scatter Plot", // chart title
            "X", // x axis label
            "Y", // y axis label
            datosSerie, // data  ***-----PROBLEM------***
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );

    // create and display a frame...
    ChartPanel panelChart = new ChartPanel(chart);

    //leer BD
    openBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            //datosSerie.removeAllSeries();
            if (filename.getText().length() > 0) {
                agf.LeerDatos(filename.getText(), Integer.parseInt(nodatos.getText()));

                createDataset(datosSerie, agf.data, "Datos");
                chart.fireChartChanged();
            } else {
                JFileChooser openFile = new JFileChooser();
                int rVal = openFile.showOpenDialog(null);
                if (rVal == JFileChooser.APPROVE_OPTION) {
                    filename.setText(openFile.getSelectedFile().getAbsolutePath());
                    agf.LeerDatos(filename.getText(), Integer.parseInt(nodatos.getText()));
                    //createDataset(datosSerie, agf.data, "Datos");
                    //chart.fireChartChanged();
                }
                if (rVal == JFileChooser.CANCEL_OPTION) {
                    filename.setText("");
                    //dir.setText("");
                }
            }
        }
    });

    ejecutarEGA.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            //datosSerie.removeAllSeries();
            if (datosSerie.getSeriesCount() > 1)
                datosSerie.removeSeries(1);

            int fn = Integer.parseInt(funcion.getText());
            int n = Integer.parseInt(individuos.getText());
            int e = Integer.parseInt(enteros.getText());
            int d = Integer.parseInt(decimales.getText());
            int v = Integer.parseInt(variables.getText());
            double pc = Double.parseDouble(Pc.getText());
            double pm = Double.parseDouble(Pm.getText());
            int g = Integer.parseInt(generaciones.getText());
            int mm = Integer.parseInt(minimiza.getText());

            ega.setParams(fn, n, e, d, v, pc, pm, g, mm);

            Resultado res = ega.ejecutarAlgoritmoGenetico(agf);

            resultado.setText(String.valueOf(res.getFitnessSemental()));

            res.creaArchivo();
            createDataset(datosSerie, res.getFenotipoSemental(), "Centros");

            Shape cross = ShapeUtilities.createDiagonalCross(5, 1);
            XYPlot xyPlot = (XYPlot) chart.getPlot();
            xyPlot.setDomainCrosshairVisible(true);
            xyPlot.setRangeCrosshairVisible(true);
            XYItemRenderer renderer = xyPlot.getRenderer();
            renderer.setSeriesShape(1, cross);
            renderer.setSeriesPaint(1, Color.blue);

            chart.fireChartChanged();

        }
    });
    //ejecutar AG

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridx = 2;
    gbc.gridy = 0;
    gbc.weighty = 1;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    this.add(lblnodatos, gbc);

    gbc.gridx = 3;
    gbc.gridy = 0;
    gbc.weighty = 1;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    this.add(nodatos, gbc);

    gbc.gridx = 2;
    gbc.gridy = 1;
    gbc.weighty = 1;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    this.add(filename, gbc);

    gbc.gridx = 3;
    gbc.gridy = 1;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    this.add(openBtn, gbc);

    gbc.gridx = 2;
    gbc.gridy = 2;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    this.add(fitness, gbc);

    gbc.gridx = 3;
    gbc.gridy = 2;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    this.add(resultado, gbc);

    gbc.gridx = 2;
    gbc.gridy = 3;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    this.add(ejecutarEGA, gbc);

    //-----------------PARAMETROS
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.weighty = 1;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    this.add(lblfuncion, gbc);

    gbc.gridx = 1;
    gbc.gridy = 0;
    gbc.weighty = 1;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    this.add(funcion, gbc);

    gbc.gridx = 0;
    gbc.gridy = 1;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    this.add(lblindividuos, gbc);

    gbc.gridx = 1;
    gbc.gridy = 1;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    this.add(individuos, gbc);

    gbc.gridx = 0;
    gbc.gridy = 2;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    this.add(lblenteros, gbc);

    gbc.gridx = 1;
    gbc.gridy = 2;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    this.add(enteros, gbc);

    gbc.gridx = 0;
    gbc.gridy = 3;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    this.add(lbldecimales, gbc);

    gbc.gridx = 1;
    gbc.gridy = 3;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    this.add(decimales, gbc);

    gbc.gridx = 0;
    gbc.gridy = 4;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    this.add(lblvariables, gbc);

    gbc.gridx = 1;
    gbc.gridy = 4;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    this.add(variables, gbc);

    gbc.gridx = 0;
    gbc.gridy = 5;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    this.add(lblpc, gbc);

    gbc.gridx = 1;
    gbc.gridy = 5;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    this.add(Pc, gbc);

    gbc.gridx = 0;
    gbc.gridy = 6;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    this.add(lblpm, gbc);

    gbc.gridx = 1;
    gbc.gridy = 6;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    this.add(Pm, gbc);

    gbc.gridx = 0;
    gbc.gridy = 7;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    this.add(lblgeneraciones, gbc);

    gbc.gridx = 1;
    gbc.gridy = 7;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    this.add(generaciones, gbc);

    gbc.gridx = 0;
    gbc.gridy = 8;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    this.add(lblminimiza, gbc);

    gbc.gridx = 1;
    gbc.gridy = 8;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    this.add(minimiza, gbc);

    gbc.fill = GridBagConstraints.BOTH;
    gbc.gridx = 0;
    gbc.gridy = 9;
    gbc.gridheight = 2;
    gbc.gridwidth = 4;
    this.add(panelChart, gbc);

    this.setTitle("File Chooser");

    this.pack();
}