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:info.financialecology.finance.utilities.datastruct.VersatileChart.java

public JFreeChart drawTimeSeries(ArrayList<VersatileTimeSeries> atsArray) {
    JFreeChart chart;//w ww  . j av  a  2s . c  o m
    ArrayList<String> visibleKeys = new ArrayList<String>();

    if (params.ticks) {
        XYSeriesCollection dataSet = new XYSeriesCollection();

        for (VersatileTimeSeries ats : atsArray) {
            XYSeries xySeries = new XYSeries(ats.getKey());
            dataSet.addSeries(xySeries);

            for (int i = 0; i < ats.getItemCount(); i++)
                xySeries.add(i, ats.getValue(i));
        }

        chart = ChartFactory.createXYLineChart(params.title, params.xLabel, params.yLabel, dataSet,
                PlotOrientation.VERTICAL, params.legend, params.toolTips, false);

        if (params.autoRange) {
            Range currentRange = dataSet.getRangeBounds(true);
            Range newRange = new Range((1 - params.autoRangePadding) * currentRange.getLowerBound(),
                    (1 + params.autoRangePadding) * currentRange.getUpperBound());
            chart.getXYPlot().getRangeAxis().setRange(newRange);
        }
    } else {
        TimeSeriesCollection dataSet = new TimeSeriesCollection();

        for (VersatileTimeSeries ats : atsArray) {
            dataSet.addSeries(ats);
            visibleKeys.add((String) ats.getKey());
        }

        chart = ChartFactory.createTimeSeriesChart(params.title, params.xLabel, params.yLabel, dataSet,
                params.legend, params.toolTips, false);

        if (params.autoRange) {
            Range currentRange = dataSet.getRangeBounds(visibleKeys, dataSet.getDomainBounds(true), true);
            Range newRange = new Range((1 - params.autoRangePadding) * currentRange.getLowerBound(),
                    (1 + params.autoRangePadding) * currentRange.getUpperBound());
            chart.getXYPlot().getRangeAxis().setRange(newRange);
        }
    }

    return chart;
}

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

/**
 * Confirm that the equals method can distinguish all the required fields.
 *//*from w w w  . j  ava 2  s.com*/
@Test
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);
    assertEquals(c1, c2);
    assertEquals(c2, c1);

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

    c1.setIntervalWidth(5.0);
    assertFalse(c1.equals(c2));
    c2.setIntervalWidth(5.0);
    assertEquals(c1, c2);

    c1.setIntervalPositionFactor(0.75);
    assertFalse(c1.equals(c2));
    c2.setIntervalPositionFactor(0.75);
    assertEquals(c1, c2);

    c1.setAutoWidth(true);
    assertFalse(c1.equals(c2));
    c2.setAutoWidth(true);
    assertEquals(c1, c2);

}

From source file:celeste.Celeste.java

public void pintarTrayectoriaPlaneta(int n_plat) {
    XYSeriesCollection coleccion = new XYSeriesCollection();

    String name = planetas.get(n_plat)[0];
    double a = Double.parseDouble(planetas.get(n_plat)[1]);
    double epsilon = Double.parseDouble(planetas.get(n_plat)[2]);
    double p = Double.parseDouble(planetas.get(n_plat)[3]);
    Planeta planeta = new Planeta(a, epsilon, p);

    XYSeries serie = planeta.generarPosiciones();
    serie.setKey(name);//from   ww w .  j av a 2  s.  c  o  m
    coleccion.addSeries(serie);

    generarGrafica(coleccion, false);
}

From source file:playground.christoph.evacuation.analysis.AgentsInEvacuationAreaWriter.java

/**
 * @return a graphic showing the number of agents in the evacuated area
 *///w w  w  .  ja  v  a2s .c  o m
private JFreeChart getGraphic(String title, String legend, String modeName, int inputData[]) {

    /*
     * Write only the number of defined picture bins to the plot.
     */
    int data[];
    if (inputData.length > this.nofPictureBins) {
        data = Arrays.copyOfRange(inputData, 0, this.nofPictureBins);
    } else
        data = inputData;

    final XYSeriesCollection xyData = new XYSeriesCollection();
    final XYSeries dataSerie = new XYSeries(legend, false, true);

    for (int i = 0; i < data.length; i++) {
        double hour = i * this.binSize / 60.0 / 60.0;
        dataSerie.add(hour, data[i]);
    }

    xyData.addSeries(dataSerie);
    final JFreeChart chart = ChartFactory.createXYStepChart(title + ", " + modeName + ", it." + this.iteration,
            "time", "# agents", xyData, PlotOrientation.VERTICAL, true, // legend
            false, // tooltips
            false // urls
    );

    XYPlot plot = chart.getXYPlot();

    final CategoryAxis axis1 = new CategoryAxis("hour");
    axis1.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 7));
    plot.setDomainAxis(new NumberAxis("time"));
    return chart;
}

From source file:visualizer.datamining.dataanalysis.NeighborhoodHit.java

private XYDataset createAllSeries(ArrayList<Serie> series, int maxneigh) {
    XYSeriesCollection xyseriescollection = new XYSeriesCollection();

    for (int i = 0; i < series.size(); i++) {
        double[] values = this.neighborhoodHit(series.get(i).filename, maxneigh);
        XYSeries xyseries = this.createSerie(series.get(i).name, values);
        xyseriescollection.addSeries(xyseries);
    }/*from   w  ww  .java 2s. c om*/

    return xyseriescollection;
}

From source file:org.schreibubi.JCombinations.logic.visitors.ChartNodesVisitor.java

public void visit(Shmoo s) throws Exception {
    if (s.componentSelected(this.treePaths, OurTreeNode.MYSELF | OurTreeNode.PARENTS | OurTreeNode.CHILDS)) {
        NumberAxis xAxis = new NumberAxis(s.getTrim() + " [" + s.getXdataDefault().getUnit() + "]");
        xAxis.setAutoRangeIncludesZero(false);
        NumberAxis yAxis = new NumberAxis(
                s.getMeasure() + " [" + ((Ydata) s.getYdata().get(0)).getUnit() + "]");
        yAxis.setAutoRangeIncludesZero(false);
        XYLineAndShapeRenderer renderer = new XYLineAndShapeRendererExtended(true, true);
        renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());

        this.dutData = new ArrayList<ArrayList<Double>>();
        this.dutName = new ArrayList<String>();
        for (int i = 0; i < s.getChildCount(); i++)
            (s.getChildAt(i)).accept(this);

        XYSeriesCollection xyseries = new XYSeriesCollection();
        ArrayList<Double> x = s.getXdataDefault().getXPositions();
        for (int j = 0; j < this.dutData.size(); j++) {
            ArrayList<Double> y = this.dutData.get(j);
            XYSeries xy = new XYSeries(this.dutName.get(j));
            for (int i = 0; i < y.size(); i++)
                xy.add(x.get(i), y.get(i));
            xyseries.addSeries(xy);
        }/*from   w w w  .j  ava  2s.  com*/

        XYPlot plot = new XYPlot(xyseries, xAxis, yAxis, renderer);
        plot.setOrientation(PlotOrientation.VERTICAL);
        plot.setDomainCrosshairVisible(true);
        plot.setRangeCrosshairVisible(true);
        Marker marker = s.getMarker();
        if (marker != null)
            plot.addRangeMarker(marker, Layer.BACKGROUND);
        ExtendedJFreeChart chart = new ExtendedJFreeChart(s.getDescription(), JFreeChart.DEFAULT_TITLE_FONT,
                plot, false);
        if (marker == null)
            chart.addSubtitle(new TextTitle(s.getSubtitle()));
        else
            chart.addSubtitle(new TextTitle(
                    s.getSubtitle() + " " + s.getValueAt(3) + "/" + s.getValueAt(4) + "/" + s.getValueAt(5)));

        chart.setTreePath(s.getTreePath());
        this.charts.add(chart);
    }

}

From source file:biometricgui.MainWindow.java

private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
    XYSeries series = new XYSeries("Biometric Data");
    series.add(1, 1);/*from  www  .  jav  a 2 s. co  m*/
    series.add(1, 2);
    series.add(2, 1);
    series.add(3, 9);
    series.add(4, 10);

    // Add the series to your data set
    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(series);
    JFreeChart chart = ChartFactory.createXYLineChart("GSR Readings", "Seconds", "Value", dataset,
            PlotOrientation.VERTICAL, true, true, false);
    ChartPanel CP;
    CP = new ChartPanel(chart);

    //int a = jPanel12.getSize();
    CP.setSize(jPanel12.getSize());
    jPanel11.add(CP);
    jPanel11.revalidate();
    jPanel11.repaint();
}

From source file:br.usp.icmc.gazetteer.SemanticSearchTest.Grafico.java

private XYDataset createDataset1() {
    XYSeriesCollection xySeriesCollection = new XYSeriesCollection();
    XYSeries team1_xy_data = new XYSeries("MAP1");
    int k = 126;/*  w  ww  .  j  ava2  s. c o  m*/
    for (BigDecimal d : cm.getMapQ()) {
        team1_xy_data.add(k, d.floatValue());
        k++;
    }
    xySeriesCollection.addSeries(team1_xy_data);
    return xySeriesCollection;
}

From source file:br.usp.icmc.gazetteer.SemanticSearchTest.Grafico.java

private XYDataset createDataset2() {
    XYSeriesCollection xySeriesCollection = new XYSeriesCollection();
    XYSeries team1_xy_data = new XYSeries("MAP2");
    int k = 126;/*ww  w  .j a  v  a 2s  . c o m*/
    for (BigDecimal d : cm.getFire()) {
        team1_xy_data.add(k, d.floatValue());
        k++;
    }
    xySeriesCollection.addSeries(team1_xy_data);
    return xySeriesCollection;
}

From source file:org.drools.planner.benchmark.core.report.BenchmarkReport.java

private XYPlot createScalabilityPlot(List<XYSeries> seriesList, String yAxisLabel, NumberFormat numberFormat) {
    NumberAxis xAxis = new NumberAxis("Problem scale");
    xAxis.setNumberFormatOverride(NumberFormat.getInstance(locale));
    NumberAxis yAxis = new NumberAxis(yAxisLabel);
    yAxis.setNumberFormatOverride(numberFormat);
    XYPlot plot = new XYPlot(null, xAxis, yAxis, null);
    int seriesIndex = 0;
    for (XYSeries series : seriesList) {
        XYSeriesCollection seriesCollection = new XYSeriesCollection();
        seriesCollection.addSeries(series);
        plot.setDataset(seriesIndex, seriesCollection);
        XYItemRenderer renderer = createScalabilityPlotRenderer(numberFormat);
        plot.setRenderer(seriesIndex, renderer);
        seriesIndex++;/* w w w  .ja va  2s  .com*/
    }
    plot.setOrientation(PlotOrientation.VERTICAL);
    return plot;
}