Example usage for org.jfree.data.xy XYSeries XYSeries

List of usage examples for org.jfree.data.xy XYSeries XYSeries

Introduction

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

Prototype

public XYSeries(Comparable key) 

Source Link

Document

Creates a new empty series.

Usage

From source file:msi.gama.hpc.gui.perspective.chart.HeadlessChart.java

private void createDataset() {
    lstvarname_flag = new ArrayList<String>();
    lsttimestep = new ArrayList<Integer>();
    lstchkbox = new ArrayList<Button>();
    readDataset();/*from  w  w  w . j  av a  2 s.c o  m*/
    ArrayList<Result> listres = sim.result;
    int n = 0;
    series = new ArrayList<XYSeries>();
    for (int i = 0; i < listres.size(); i++) {
        String varname = listres.get(i).getName();
        if (lstvarname_flag.contains(varname)) {
            int idx = lstvarname_flag.indexOf(varname);
            lsttimestep.set(idx, lsttimestep.get(idx) + 1);
            series.get(idx).add(lsttimestep.get(idx), listres.get(i).getValue());
        } else {
            lstvarname_flag.add(varname);
            Button b1 = new Button(comp.getParent(), SWT.CHECK);
            b1.setText("Show " + varname);
            b1.setSelection(true);
            b1.addSelectionListener(new SelectionListener() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    // TODO Auto-generated method stub
                    showChart();
                }

                @Override
                public void widgetDefaultSelected(SelectionEvent e) {
                    // TODO Auto-generated method stub

                }

            });
            lstchkbox.add(b1);
            lsttimestep.add(new Integer(0));
            XYSeries ss = new XYSeries(varname);
            series.add(ss);
        }
        // System.out.println(" " + listres.get(i).getName()+" " + listres.get(i).getValue());
    }

}

From source file:br.com.ant.system.util.ChartUtil.java

public void createCaminhoPercorrido(EstatisticaColetor estatisticaColetor) {

    // Create a simple XY chart

    JFrame frame = new JFrame();

    // Add the series to your data set
    XYSeriesCollection dataset = new XYSeriesCollection();

    Map<Cidade, List<Estatistica>> mapformigasEstatisticas = new HashMap<Cidade, List<Estatistica>>();
    for (Estatistica e : estatisticaColetor.getEstatisticas()) {
        if (mapformigasEstatisticas.containsKey(e.getCidadeInicial())) {
            mapformigasEstatisticas.get(e.getCidadeInicial()).add(e);
        } else {/*from   w  w w. j  a  v a2 s.c o  m*/
            List<Estatistica> lista = new ArrayList<Estatistica>();
            lista.add(e);

            mapformigasEstatisticas.put(e.getCidadeInicial(), lista);
        }
    }

    Set<Cidade> cidades = mapformigasEstatisticas.keySet();
    for (Cidade c : cidades) {
        // for (int i = 0; i < 2; i++) {
        List<Estatistica> list = (List<Estatistica>) mapformigasEstatisticas.get(c);

        XYSeries series = new XYSeries(c.getNome());
        dataset.addSeries(series);

        for (Estatistica e : list) {
            if (e.getFormigaId() == 1) {
                series.add(e.getIteracao(), e.getDistanciaPercorrida());
            }
        }
    }

    // Generate the graph
    JFreeChart chart = ChartFactory.createXYLineChart("", "Iterao", "Distancia (Km)", dataset,
            PlotOrientation.VERTICAL, true, true, false);
    frame.getContentPane().add(new ChartPanel(chart));

    frame.setPreferredSize(new Dimension(600, 600));
    frame.setMinimumSize(new Dimension(600, 600));
    frame.setMaximumSize(new Dimension(600, 600));
    frame.setVisible(true);

    try {
        ChartUtilities.saveChartAsJPEG(new File("chart.jpg"), chart, 500, 300);
    } catch (IOException e) {
        System.err.println("Problem occurred creating chart.");
    }
}

From source file:celeste.Celeste.java

public void todasPosiciones(double t) {
    XYSeriesCollection coleccion = new XYSeriesCollection();

    for (int i = 0; i < planetas.size(); i++) {
        String name = planetas.get(i)[0];
        double a = Double.parseDouble(planetas.get(i)[1]);
        double epsilon = Double.parseDouble(planetas.get(i)[2]);
        double p = Double.parseDouble(planetas.get(i)[3]);
        Planeta planeta = new Planeta(a, epsilon, p);

        XYSeries serie2 = planeta.generarPosiciones();
        serie2.setKey(name);//  w  w  w.  jav  a 2 s . co  m

        Vector pos = planeta.posicion(t);

        XYSeries serie = new XYSeries(name + " en t");
        serie.add(pos.getX1(), pos.getX2());
        coleccion.addSeries(serie2);
        coleccion.addSeries(serie);
    }
    generarGrafica(coleccion, true);
}

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

private static XYDataset createDataset(int i, double d) {
    XYSeries xyseries = new XYSeries("Series " + i);
    xyseries.add(1.0D, d);//from  w w w .  ja  v  a  2  s  .  c o m
    xyseries.add(2D, d);
    xyseries.add(3D, d);
    XYSeriesCollection xyseriescollection = new XYSeriesCollection();
    xyseriescollection.addSeries(xyseries);
    return xyseriescollection;
}

From source file:Similaridade.GraficosSimilaridade.java

public static XYDataset newDataset2OndasComDeslocada(CapturaAtual onda1, CapturaAtual onda2, int deslocamento,
        double correlacao) {
    //metodo que cria um CategoryDataset para ser usado em grafico de linhas                
    float valOnda1[] = new float[Configuracoes.PONTOSONDA];
    float valOnda2[] = new float[Configuracoes.PONTOSONDA];
    float sen1[] = new float[Configuracoes.HARMONICAS];
    float cos1[] = new float[Configuracoes.HARMONICAS];
    float sen2[] = new float[Configuracoes.HARMONICAS];
    float cos2[] = new float[Configuracoes.HARMONICAS];
    int i;//from  w ww. jav  a2 s  .co m

    float s1, s2, tempo[] = new float[Configuracoes.PONTOSONDA];
    XYSeriesCollection result = new XYSeriesCollection();

    for (i = 0; i < Configuracoes.HARMONICAS; i++) {
        sen1[i] = 0;
        cos1[i] = 0;
        sen2[i] = 0;
        cos2[i] = 0;
    }

    i = 0;
    for (HarmAtual oa : onda1.getHarmAtual()) {
        sen1[i] = oa.getSen();
        cos1[i] = oa.getCos();
        i++;
    }

    i = 0;
    for (HarmAtual oa : onda2.getHarmAtual()) {
        sen2[i] = oa.getSen();
        cos2[i] = oa.getCos();
        i++;
    }

    XYSeries series1 = new XYSeries(String.valueOf(onda1.getCodCaptura()));
    XYSeries series3 = new XYSeries("Shift " + String.valueOf(onda2.getCodCaptura()));

    tempo[0] = 0; //(float) 1 / 60;
    for (i = 0; i < Configuracoes.PONTOSONDA; i++) {
        if (TIRADOVM == 0) {
            s1 = onda1.getValorMedio() / 2;
            s2 = onda2.getValorMedio() / 2;
        } else {
            s1 = onda1.getValorMedio();
            s2 = onda2.getValorMedio();
        }

        for (int x = 0; x < Configuracoes.HARMONICAS; x++) {
            if (TIRADOVM == 0) {
                s1 += (float) (sen1[x] * Math.sin(2 * Math.PI * ((x + 1) * Configuracoes.FREQBASE) * tempo[i]))
                        + (cos1[x] * Math.cos(-2 * Math.PI * ((x + 1) * Configuracoes.FREQBASE) * tempo[i]));
                s2 += (float) (sen2[x] * Math.sin(2 * Math.PI * ((x + 1) * Configuracoes.FREQBASE) * tempo[i]))
                        + (cos2[x] * Math.cos(-2 * Math.PI * ((x + 1) * Configuracoes.FREQBASE) * tempo[i]));
            } else {
                s1 += (float) (sen1[x] * Math.sin(2 * Math.PI * ((x + 1) * Configuracoes.FREQBASE) * tempo[i]))
                        + (cos1[x] * Math.cos(2 * Math.PI * ((x + 1) * Configuracoes.FREQBASE) * tempo[i]));
                s2 += (float) (sen2[x] * Math.sin(2 * Math.PI * ((x + 1) * Configuracoes.FREQBASE) * tempo[i]))
                        + (cos2[x] * Math.cos(2 * Math.PI * ((x + 1) * Configuracoes.FREQBASE) * tempo[i]));
            }
        }
        if (TIRADOVM == 0) {
            valOnda1[i] = (int) ((s1 * (2.0)) / 256.0);
            valOnda1[i] = (valOnda1[i] - onda1.getOffset());
            valOnda2[i] = (int) ((s2 * (2.0)) / 256.0);
            valOnda2[i] = (valOnda2[i] - onda2.getOffset());

        } else {
            valOnda1[i] = (s1);
            valOnda2[i] = (s2);
        }
        valOnda1[i] = (valOnda1[i]) / onda1.getGain();
        valOnda2[i] = (valOnda2[i]) / onda2.getGain();

        series1.add(tempo[i] * 1000, valOnda1[i]);

        if (i == (Configuracoes.PONTOSONDA - 1)) {
            break;
        }
        tempo[i + 1] = (tempo[i] + (float) (1.0 / (60 * 256)));
    }

    int j = 0;
    if (correlacao < 0) {
        for (i = 0; i < Configuracoes.PONTOSONDA; i++) {
            if ((i + deslocamento) <= (Configuracoes.PONTOSONDA - 1)) {
                series3.add(tempo[i] * 1000, -1 * valOnda2[i + deslocamento]);
            } else {
                series3.add(tempo[i] * 1000, -1 * valOnda2[j++]);
            }
        }
    } else {
        for (i = 0; i < Configuracoes.PONTOSONDA; i++) {
            if ((i + deslocamento) <= (Configuracoes.PONTOSONDA - 1)) {
                series3.add(tempo[i] * 1000, valOnda2[i + deslocamento]);
            } else {
                series3.add(tempo[i] * 1000, valOnda2[j++]);
            }
        }
    }

    result.addSeries(series1);
    result.addSeries(series3);

    return result;
}

From source file:chartsPK.LineChart.java

private XYDataset createDataset() {

    XYSeriesCollection dataset = new XYSeriesCollection();
    Vector<XYSeries> series = new Vector<>();

    for (LineChartDataSeries dataSerie : dataSeries) {
        series.add(new XYSeries(dataSerie.getTitle()));
    }/*  www.j a v a 2  s  .  c  o  m*/

    for (int i = 0; i < dataSeries.size(); i++) {
        for (int j = 0; j < dataSeries.get(i).getXValues().size(); j++) {
            series.get(i).add(dataSeries.get(i).getXValues().get(j), dataSeries.get(i).getYValues().get(j));
        }
    }

    for (XYSeries serie : series) {
        dataset.addSeries(serie);
    }

    return dataset;
}

From source file:edu.wustl.cab2b.client.ui.visualization.charts.ScatterPlot.java

@Override
protected Dataset createRowWiseData() {

    List<String> selectedRowNames = chartModel.getSelectedRowNames();
    List<String> selectedColumnsNames = chartModel.getSelectedColumnsNames();

    XYSeriesCollection xySeriesCollection = new XYSeriesCollection();

    if (selectedRowNames.size() == 1) {
        String seriesName = selectedRowNames.get(0) + "";
        XYSeries xySeries = new XYSeries(seriesName);
        for (int j = 0; j < selectedColumnsNames.size(); j++) {
            Object value = null;//  www  .  j  a  v a 2  s  .  com
            if (chartModel.isWholeColumnSelected()) {
                value = chartModel.getValueAt(0, j);
            }

            xySeries.add(convertValue(selectedRowNames.get(j)), convertValue(value));
        }
        xySeriesCollection.addSeries(xySeries);
    } else {
        for (int i = 1; i < selectedRowNames.size(); i++) {
            String seriesName = selectedRowNames.get(i) + "";
            XYSeries xySeries = new XYSeries(seriesName);

            for (int j = 0; j < selectedColumnsNames.size(); j++) {
                Object xValueString = chartModel.getValueAt(0, j);
                Object yValueString = chartModel.getValueAt(i, j);
                xySeries.add(convertValue(xValueString), convertValue(yValueString));
            }
            xySeriesCollection.addSeries(xySeries);
        }
    }
    return xySeriesCollection;
}

From source file:org.jfree.data.xy.junit.XYSeriesCollectionTest.java

/**
 * Confirm that the equals method can distinguish all the required fields.
 *//*from w  ww .  ja  va 2s.  c  om*/
public void testEquals() {
    XYSeries s1 = new XYSeries("Series");
    s1.add(1.0, 1.1);
    XYSeriesCollection c1 = new XYSeriesCollection();
    c1.addSeries(s1);
    XYSeries s2 = new XYSeries("Series");
    s2.add(1.0, 1.1);
    XYSeriesCollection c2 = new XYSeriesCollection();
    c2.addSeries(s2);
    assertTrue(c1.equals(c2));
    assertTrue(c2.equals(c1));

    c1.addSeries(new XYSeries("Empty Series"));
    assertFalse(c1.equals(c2));
    c2.addSeries(new XYSeries("Empty Series"));
    assertTrue(c1.equals(c2));

    c1.setIntervalWidth(5.0);
    assertFalse(c1.equals(c2));
    c2.setIntervalWidth(5.0);
    assertTrue(c1.equals(c2));

    c1.setIntervalPositionFactor(0.75);
    assertFalse(c1.equals(c2));
    c2.setIntervalPositionFactor(0.75);
    assertTrue(c1.equals(c2));

    c1.setAutoWidth(true);
    assertFalse(c1.equals(c2));
    c2.setAutoWidth(true);
    assertTrue(c1.equals(c2));

}

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

/**
* Creates a sample dataset./*from w ww.ja va  2 s . c o m*/
*
* @return a sample dataset.
*/
protected XYDataset createDataset(boolean isDemo) {

    if (isDemo) {

        larger_row_count = 10;
        x_row_count = 10;
        y_row_count = 8;
        raw_x = new String[x_row_count];
        raw_y = new String[y_row_count];

        raw_x[0] = "95";
        raw_x[1] = "104";
        raw_x[2] = "99";
        raw_x[3] = "102";
        raw_x[4] = "95";
        raw_x[5] = "106";
        raw_x[6] = "100";
        raw_x[7] = "108";
        raw_x[8] = "104";
        raw_x[9] = "97";

        raw_y[0] = "97";
        raw_y[1] = "98";
        raw_y[2] = "92";
        raw_y[3] = "94";
        raw_y[4] = "93";
        raw_y[5] = "106";
        raw_y[6] = "94";
        raw_y[7] = "109";

        do_dd();

        XYSeries series1 = new XYSeries("QQ");

        //for (int i=0; i<row_count; i++){
        int len = normalQuantiles.length;

        for (int i = 0; i < len; i++) {
            //System.out.println("i="+i+" x="+normalQuantiles[i]+" y="+stdResiduals[i]);
            series1.add(normalQuantiles[i], stdResiduals[i]);
        }

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

        try {
            XYSeries series2 = new XYSeries("Reference Line");
            RegressionLine refLine = new RegressionLine(normalQuantiles, stdResiduals);
            double intercept = refLine.getIntercept();
            double slope = refLine.getSlope();

            min_x = Math.min(normalQuantiles[0], stdResiduals[0]);
            double min_y = slope * min_x + intercept;

            max_x = Math.max(normalQuantiles[len - 1], stdResiduals[len - 1]);
            //max_x = Math.max (normalQuantiles[row_count-1],stdResiduals[row_count-1]);
            double max_y = slope * max_x + intercept;

            series2.add(min_x, min_y);
            series2.add(max_x, max_y);

            dataset.addSeries(series2);

        } catch (DataException e) {
            System.out.println("cought dataException");
            e.printStackTrace();
        }

        return dataset;
    } else
        return super.createDataset(false);

}

From source file:org.encog.workbench.dialogs.validate.ResultValidationChart.java

public void setData(MLDataSet validationData, MLMethod method) {
    ArrayList<XYSeries> validation = new ArrayList<XYSeries>();
    ArrayList<XYSeries> computation = new ArrayList<XYSeries>();

    Vector<Vector<String>> tableData = new Vector<Vector<String>>();
    Vector<String> tableHeaders = null;

    int key = 0;/*from ww w.j  av a  2  s  .  co  m*/
    Vector<String> tableDataRow;
    for (MLDataPair dataRow : validationData) {
        MLData input = dataRow.getInput();
        MLData validIdeal = dataRow.getIdeal();
        MLData computatedIdeal = getCalculatedResult(dataRow, method);
        int inputCount = input.size();
        int idealCount = validIdeal == null ? 0 : validIdeal.size();

        tableDataRow = new Vector<String>();
        if (tableHeaders == null) {
            tableHeaders = new Vector<String>();
            for (int i = 0; i < inputCount; i++) {
                tableHeaders.add("Input " + i);
            }
            for (int i = 0; i < computatedIdeal.size(); i++) {
                tableHeaders.add("Ideal " + i);
                tableHeaders.add("Result " + i);
            }
        }

        for (int i = 0; i < inputCount; i++) {
            tableDataRow.add(new Double(input.getData(i)).toString());
        }

        for (int i = validation.size(); i < idealCount; i++) {
            validation.add(new XYSeries("Validation"));
            computation.add(new XYSeries("Computation"));
            createChart();
        }

        for (int i = 0; i < computatedIdeal.size(); i++) {
            double c = computatedIdeal.getData(i);

            if (idealCount > 0) {
                double v = validIdeal.getData(i);
                validation.get(i).add(key, v);
                tableDataRow.add(new Double(v).toString());
                computation.get(i).add(key, c);
            } else {
                tableDataRow.add("N/A");
            }

            tableDataRow.add(new Double(c).toString());

        }

        tableData.add(tableDataRow);

        key++;
    }

    drawGraphs(validation, computation);
    drawTable(tableData, tableHeaders);
}