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:sim.app.sugarscape.util.ResultsGrapher.java

JFreeChart createChart1(XYSeries[] series) {
    JFreeChart chart3 = ChartFactory.createXYLineChart("Results", x_axis_fieldname, y_axis_fieldname, null, //new XYSeriesCollection(series[2]),
            PlotOrientation.VERTICAL, true, true, false);
    //System.out.println("Series count = " +series[0].getItemCount());
    XYPlot plot = chart3.getXYPlot();// w w w  .  j a v a2  s  . c o  m

    ValueAxis yAxis = plot.getRangeAxis();
    //xAxis.setFixedDimension(100);
    //yAxis.setFixedDimension(1.0);
    //yAxis.setRange(0,1);
    ValueAxis xAxis = plot.getDomainAxis();
    //xAxis.setFixedDimension(50);

    StandardXYItemRenderer renderer = (StandardXYItemRenderer) plot.getRenderer();
    renderer.setSeriesPaint(0, Color.black);
    renderer.setStroke(new BasicStroke(2f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));

    renderer.setItemLabelFont(new Font("Serif", Font.PLAIN, 20));
    renderer.setItemLabelsVisible(true);

    renderer.setSeriesItemLabelsVisible(1, true);
    renderer.setBaseShapesVisible(true);
    //XYLabelGenerator generator = new StandardXYLabelGenerator();

    //"{2}", new DecimalFormat("0.00") );
    //renderer.setLabelGenerator(generator);
    //NumberAxis axis2 = new NumberAxis("Average Agent Vision");
    //renderer.setItemLabelsVisible(true);
    //axis2.setAutoRangeIncludesZero(false);
    //axis2.setRange(0,12);
    //plot.setRangeAxis(1, axis2);
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);
    //XYSeriesCollection vision = new XYSeriesCollection(lorenz_agent_vision);
    //plot.setDataset(1, vision);
    //String first_letter = x_param_fieldname.substring(0,1)+"=";
    XYSeriesCollection xys = new XYSeriesCollection();
    for (int a = 0; a < series.length; a++) {
        xys.addSeries(series[a]);
        //xys.
        //xys.getSeriesName(4);
        System.out.println(xys.getSeries(a).getDescription());
    }
    plot.setDataset(0, xys);
    return chart3;

}

From source file:charts.Chart.java

public static void Histogram(Vector data, int maxvalue, String net) {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    int i = 0;/* w  w w  . j  a v a  2s .  c o  m*/
    int[] degree = new int[maxvalue];//guarda o grau de cada no
    int value = 0;

    for (i = 0; i < data.size(); i++) {
        value = (Integer) data.get(i);
        degree[value]++;//determina o grau de cada no == quantas vezes ele apareceu na lista.
    }

    int max = Maximum(degree);//pega o grau maximo para gerar o histograma
    int[] vethistogram = new int[max + 1];
    for (i = 0; i < degree.length; i++) {
        vethistogram[degree[i]]++;//para cada ocorrencia do grau, soma um na sua posicao do histograma.
    }

    //codigo para gerar os dados para o grafico MultipleLineChart
    XYDataset[] xydatasets = new XYDataset[1];
    XYSeries serie = new XYSeries("sample");

    XYSeries series2 = new XYSeries("Max Value");

    float maxvaluef = maxvalue;
    for (i = 0; i < max + 1; i++) {
        float nnos = vethistogram[i];
        if (i != 0 && nnos != 0 && net.equalsIgnoreCase("BA")) {
            serie.add(Math.log(i), Math.log(nnos / maxvaluef));
            series2.add(Math.log(i), Math.log(nnos / maxvaluef));
        } else if (net.equalsIgnoreCase("ER")) {
            serie.add(i, nnos / maxvaluef);
            series2.add(i, nnos / maxvaluef);
        }
        //serie.add(i, (nnos/maxvaluef));
        dataset.addValue((Number) vethistogram[i], 0, i);
        //datasets[i].addValue(Md[ lineindex[i] ][c], String.valueOf(c));
    }
    XYSeriesCollection series = new XYSeriesCollection();
    series.addSeries(series2);
    ScatterPlot(series, "Validation Graph - Node Degree Distribution", "log(k)", "log(P(k))");

    xydatasets[0] = new XYSeriesCollection(serie);
    Chart.MultipleLineChart(xydatasets, "Line Chart", "degree", "number of nodes", true, 0, 0);

    Chart.BarChart(dataset, "Histogram of node degree", "samples", "values", true);
}

From source file:org.ect.reo.simulation.simulator.Statistic.java

/**
 * @return the chart for this statistic//from  w  ww  .j ava  2 s . c  o m
 */
public JFreeChart getChart() {
    if (chart == null) {
        if (useChart) {
            // Add the series to your data set
            XYSeriesCollection dataset = new XYSeriesCollection();
            for (int i = 0; i < numOfBatches; i++) {
                dataset.addSeries(batchPoints[i]);
            }

            // Generate the graph
            chart = ChartFactory.createXYLineChart(
                    (type == USAGE_PCT) ? "Utilization for " + description
                            : "Average duration for " + description, // Title
                    "Time", // x-axis Label
                    (type == USAGE_PCT) ? "Ratio of time used" : "Duration", // y-axis Label
                    dataset, // Dataset
                    PlotOrientation.VERTICAL, // Plot Orientation
                    false, // Show Legend
                    true, // Use tooltips
                    false // Configure chart to generate URLs?
            );
        }
    }
    return chart;
}

From source file:mineria.UI.java

private void createDataset(XYSeriesCollection result, double[][] data, String nombreSerie) {

    XYSeries series = new XYSeries(nombreSerie);
    for (int i = 0; i < data.length; i++) {
        double x = data[i][0];
        double y = data[i][1];
        series.add(x, y);/*from   www.j a va2 s .  c  o  m*/
    }
    result.addSeries(series);

    //return result;
}

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

/**
 * Some basic checks for the addSeries() method.
 */// w ww  . j a  v a2s . c om
public void testAddSeries() {
    XYSeriesCollection c = new XYSeriesCollection();
    XYSeries s1 = new XYSeries("s1");
    c.addSeries(s1);

    // the dataset should prevent the addition of a series with the
    // same name as an existing series in the dataset
    XYSeries s2 = new XYSeries("s1");
    boolean pass = false;
    try {
        c.addSeries(s2);
    } catch (RuntimeException e) {
        pass = true;
    }
    assertTrue(pass);
    assertEquals(1, c.getSeriesCount());
}

From source file:web.diva.server.unused.ProfilePlotGenerator.java

/**
 *
 * @return dataset./* ww  w .  ja va2  s  .c  o  m*/
 */
private XYDataset createDataset(Number[][] pointsData) {

    final XYSeriesCollection dataset = new XYSeriesCollection();

    for (int x = 0; x < pointsData.length; x++) {
        XYSeries series = new XYSeries(x);
        Number[] data = pointsData[x];
        for (int y = 0; y < data.length; y++) {
            series.add(y, data[y]);
        }

        dataset.addSeries(series);

    }
    return dataset;

}

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

/**
 * Some basic checks for the getSeries() method.
 *//* www.j  a v a2  s  .c  om*/
public void testGetSeries() {
    XYSeriesCollection c = new XYSeriesCollection();
    XYSeries s1 = new XYSeries("s1");
    c.addSeries(s1);
    assertEquals("s1", c.getSeries(0).getKey());

    boolean pass = false;
    try {
        c.getSeries(-1);
    } catch (IllegalArgumentException e) {
        pass = true;
    }
    assertTrue(pass);

    pass = false;
    try {
        c.getSeries(1);
    } catch (IllegalArgumentException e) {
        pass = true;
    }
    assertTrue(pass);
}

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

/**
 * Some checks for the getSeries(Comparable) method.
 *///w w w  .j a  v  a 2 s  .c o  m
public void testGetSeriesByKey() {
    XYSeriesCollection c = new XYSeriesCollection();
    XYSeries s1 = new XYSeries("s1");
    c.addSeries(s1);
    assertEquals("s1", c.getSeries("s1").getKey());

    boolean pass = false;
    try {
        c.getSeries("s2");
    } catch (UnknownKeyException e) {
        pass = true;
    }
    assertTrue(pass);

    pass = false;
    try {
        c.getSeries(null);
    } catch (IllegalArgumentException e) {
        pass = true;
    }
    assertTrue(pass);
}

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

public JFreeChart createRPChart() {

    Query query;/*from  w ww  . j  av a2  s.c  o m*/
    Map.Entry me;
    MacroAvgRecallPrecision recall = new MacroAvgRecallPrecision(20);
    ArrayList retrievedServices = new ArrayList();
    ArrayList relevantServices = new ArrayList();
    for (Iterator iter = TestCollection.getInstance()
            .getMatchmakerAnswerset(GUIState.getInstance().getSorting()).entrySet().iterator(); iter
                    .hasNext();) {
        me = (Map.Entry) (iter.next());
        query = (Query) me.getKey();
        retrievedServices = getURIasStringFromServiceSet((SortedSet) me.getValue());
        relevantServices = getURIasStringFromURISet(TestCollection.getInstance().getAnswerset(query.getURI()));
        //          owlsmx.io.ErrorLog.instanceOf().report(query.toString() + ":");
        //          owlsmx.io.ErrorLog.instanceOf().report("  " + retrievedServices.toString());
        //          owlsmx.io.ErrorLog.instanceOf().report("  " + relevantServices.toString());
        if (relevantServices.size() <= 0)
            GUIState.displayWarning(this, "Error when computing recall/precision graph",
                    "Relevance set is empty. Maybe forgotten to define?");
        recall.processRecallPrecision(retrievedServices, relevantServices);
    }

    XYSeriesCollection data = new XYSeriesCollection();
    data.addSeries(createRPSeries(recall, (retrievedServices.size() <= 0)));

    JFreeChart chart = ChartFactory.createXYLineChart("Recall/Precision", "Recall", "Precision", data,
            org.jfree.chart.plot.PlotOrientation.VERTICAL, true, true, false);
    chart.removeLegend();
    XYPlot plot = chart.getXYPlot();
    XYItemRenderer renderer = (XYItemRenderer) plot.getRenderer();
    renderer.setSeriesPaint(0, Color.red);
    return chart;
}

From source file:flexflux.analyses.result.ParetoAnalysisResult.java

public void plot() {

    XYSeriesCollection dataset = new XYSeriesCollection();

    int i = 1;/* www.  ja v  a  2  s .  c o m*/
    for (Objective obj : oneDResults.keySet()) {

        XYSeries series = new XYSeries(obj.getName());

        for (double val : oneDResults.get(obj)) {

            series.add(i, val);
        }

        dataset.addSeries(series);
        i++;
    }

    // create the chart...

    final JFreeChart chart = ChartFactory.createXYLineChart("", // chart title
            "Objectives", // x axis label
            "Values", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );

    ChartPanel chartPanel = new ChartPanel(chart);

    XYPlot plot = chart.getXYPlot();

    plot.setBackgroundPaint(Color.WHITE);
    plot.setRangeGridlinePaint(Color.GRAY);
    plot.setDomainGridlinePaint(Color.GRAY);

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setLinesVisible(false);
    renderer.setShapesVisible(true);
    plot.setRenderer(renderer);

    // change the auto tick unit selection to integer units only...
    NumberAxis rangeAxis = (NumberAxis) plot.getDomainAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    JFrame frame = new JFrame("Pareto analysis one dimension results");
    frame.add(chartPanel);

    frame.pack();

    RefineryUtilities.centerFrameOnScreen(frame);
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    frame.setVisible(true);

    for (PP2DResult r : twoDResults.keySet()) {

        r.plot();

    }

    for (PP3DResult r : threeDResults.keySet()) {

        r.plot();

    }

}