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:logica_controladores.controlador_estadistica.java

public static void grafica_orden(JPanel panel_grafica_orden, Inventario inventario, JLabel lbLinea) {
    XYSeries serie = null;//  w  ww.  java  2 s  . c  o  m
    XYSeries serie_2 = null;

    JFreeChart linea;

    serie = new XYSeries("graficas relacion gastos-orden");
    Gasto gasto_minimo = valor_minimo(inventario);
    Gasto gasto_max = valor_maximo(inventario);
    for (int i = 0; i < inventario.getGastos().size(); i = i + inventario.getReorden_max()) {
        serie.add(inventario.getGastos().get(i).getOrden_inicial(), inventario.getGastos().get(i).getGastos());
    }
    serie_2 = new XYSeries("graficas relacion gastos-reorden");

    for (int i = 0; i < inventario.getGastos().size(); i = i + inventario.getOrden_max()) {
        serie_2.add(inventario.getGastos().get(i).getReorden(), inventario.getGastos().get(i).getGastos());
    }
    final XYSeriesCollection datos = new XYSeriesCollection();
    datos.addSeries(serie);
    datos.addSeries(serie_2);

    linea = ChartFactory.createXYLineChart(
            "grafica representativa de ordenes por corrida, gasto_minimo(orden: "
                    + gasto_minimo.getOrden_inicial() + "reorden: " + gasto_minimo.getReorden() + ")= "
                    + gasto_minimo.getGastos(),
            "rango", "gastos", datos, PlotOrientation.VERTICAL, true, true, true);
    final XYPlot plot = (XYPlot) linea.getPlot();
    final NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    configurarDomainAxis(domainAxis, inventario);
    configurarRangeAxis(rangeAxis, gasto_minimo.getGastos(), gasto_max.getGastos());
    BufferedImage graficoLinea = linea.createBufferedImage(600, 280);
    lbLinea.setSize(panel_grafica_orden.getSize());
    lbLinea.setIcon(new ImageIcon(graficoLinea));
    panel_grafica_orden.updateUI();
}

From source file:evaluation.simulator.gui.results.LineJFreeChartCreator.java

private static XYDataset createDataset() {

    final XYSeries series1 = new XYSeries("AVG");
    series1.add(1.0, 1.0);/*from  w  w  w. ja  v  a  2s.c om*/
    series1.add(2.0, 4.0);
    series1.add(3.0, 3.0);
    series1.add(4.0, 5.0);
    series1.add(5.0, 5.0);
    series1.add(6.0, 7.0);
    series1.add(7.0, 7.0);
    series1.add(8.0, 8.0);

    final XYSeries series2 = new XYSeries("Min AVG");
    series2.add(1.0, 0.5);
    series2.add(2.0, 2.0);
    series2.add(3.0, 1.5);
    series2.add(4.0, 2.5);
    series2.add(5.0, 2.5);
    series2.add(6.0, 3.5);
    series2.add(7.0, 3.5);
    series2.add(8.0, 4.0);

    final XYSeries series3 = new XYSeries("Max AVG");
    series3.add(1.0, 2.0);
    series3.add(2.0, 8.0);
    series3.add(3.0, 6.0);
    series3.add(4.0, 10.0);
    series3.add(5.0, 10.0);
    series3.add(6.0, 14.0);
    series3.add(7.0, 14.0);
    series3.add(8.0, 16.0);

    final XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(series1);
    dataset.addSeries(series2);
    dataset.addSeries(series3);
    return dataset;

}

From source file:it.unifi.rcl.chess.traceanalysis.gui.Plotter.java

public static JPanel assemblePlot(XYSeries series[]) {
    // Add the series to your data set
    XYSeriesCollection dataset = new XYSeriesCollection();
    for (int i = 0; i < series.length; i++) {
        dataset.addSeries(series[i]);
    }/* w  ww  .j av a2  s .  com*/

    // Generate the graph
    JFreeChart chart = ChartFactory.createXYLineChart("XY Chart",
            // Title
            "x-axis",
            // x-axis Labels
            "y-axis",
            // y-axis Label
            dataset,
            // Dataset
            PlotOrientation.VERTICAL, // Plot Orientation
            false,
            // Show Legend
            true,
            // Use tooltips
            false
    // Configure chart to generate URLs?
    );

    return new ChartPanel(chart);
}

From source file:network.Draw.java

private static XYDataset createDataset(int method) {
    XYSeries tempreture = new XYSeries("Tempreture");
    String output = null;/*  w w  w  .j a  va 2  s  . c om*/
    String url = "http://localhost/server/dia.php";
    System.out.println(url);
    try {
        if (method == 0) {
            output = HTTP.getHTML(url);
            System.out.println("get");
        } else {
            output = HTTP.postHTML(url, "");
            System.out.println("post");
        }
    } catch (Exception ex) {
        Logger.getLogger(Draw.class.getName()).log(Level.SEVERE, null, ex);
    }
    System.out.println(output);

    String[] strArray = output.split("&");

    //String data[] = output.split("&");
    //      
    //         for(int i=0;i<10;i++){
    //            System.out.print(data[i]);
    //        }
    int x, y;

    for (int i = strArray.length - 10; i < strArray.length;) {
        x = Integer.parseInt(strArray[i]);
        y = Integer.parseInt(strArray[i + 1]);
        System.out.print(x + ":" + y + "\n");

        tempreture.add(x, y);
        i = i + 2;
    }
    //       
    final XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(tempreture);

    return dataset;
}

From source file:PerformanceGraph.java

/**
 * Plots the performance graph of the best fitness value so far versus the
 * number of function calls (NFC).//from   w ww.j a  v  a 2 s . c  o  m
 * 
 * @param bestFitness A linked hashmap mapping the NFC to the best fitness value
 * found so far.
 * @param fitnessFunction The name of the fitness function, used for the title and the
 * name of the file that is saved, e.g. "De Jong".
 */
public static void plot(LinkedHashMap<Integer, Double> bestFitness, String fitnessFunction) {
    /* Create an XYSeries plot */
    XYSeries series = new XYSeries("Best Fitness Value Vs. Number of Function Calls");

    /* Add the NFC and best fitness value data to the series */
    for (Integer NFC : bestFitness.keySet()) {
        /* Jfreechart crashes if double values are too large! */
        if (bestFitness.get(NFC) <= 10E12) {
            series.add(NFC.doubleValue(), bestFitness.get(NFC).doubleValue());
        }
    }

    /* Add the x,y series data to the dataset */
    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(series);

    /* Plot the data as an X,Y line chart */
    JFreeChart chart = ChartFactory.createXYLineChart("Best Fitness Value Vs. Number of Function Calls",
            "Number of Function Calls (NFC)", "Best Fitness Value", dataset, PlotOrientation.VERTICAL, false,
            true, false);

    /* Configure the chart settings such as anti-aliasing, background colour */
    chart.setAntiAlias(true);

    XYPlot plot = chart.getXYPlot();

    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.black);
    plot.setDomainGridlinePaint(Color.black);

    /* Set the domain range from 0 to NFC */
    NumberAxis domain = (NumberAxis) plot.getDomainAxis();
    domain.setRange(0.0, ControlVariables.MAX_FUNCTION_CALLS.doubleValue());

    /* Logarithmic range axis */
    plot.setRangeAxis(new LogAxis());

    /* Set the thickness and colour of the lines */
    XYItemRenderer renderer = plot.getRenderer();
    BasicStroke thickLine = new BasicStroke(3.0f);
    renderer.setSeriesStroke(0, thickLine);
    renderer.setPaint(Color.BLACK);

    /* Display the plot in a JFrame */
    ChartFrame frame = new ChartFrame(fitnessFunction + " Best Fitness Value", chart);
    frame.setVisible(true);
    frame.setSize(1000, 600);

    /* Save the plot as an image named after fitness function
    try
    {
       ChartUtilities.saveChartAsJPEG(new File("plots/" + fitnessFunction + ".jpg"), chart, 1600, 900);
    }
    catch (IOException e)
    {
       e.printStackTrace();
    }*/
}

From source file:wsattacker.plugin.intelligentdos.ui.helper.ChartHelper.java

public static JFreeChart createOverlaidChart(SuccessfulAttack sa) {

    // create subplot 1...
    final XYSeries data1 = createDatasetResponseTime(RequestType.UNTAMPERED, sa.getUntamperedMetrics());
    final XYSeries data2 = createDatasetResponseTime(RequestType.TAMPERED, sa.getTamperedMetrics());
    final XYSeries data3 = createDatasetResponseTime(RequestType.TESTPROBES, sa.getTestProbes());

    final XYSeriesCollection collection = new XYSeriesCollection();
    collection.addSeries(data1);
    collection.addSeries(data2);/*  w w w  . ja  va  2 s  . c  om*/
    collection.addSeries(data3);

    final XYItemRenderer renderer = new StandardXYItemRenderer();
    final NumberAxis rangeAxis1 = new NumberAxis("duration in ms");
    final XYPlot plot = new XYPlot(collection, new NumberAxis(""), rangeAxis1, renderer);
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    renderer.setSeriesPaint(0, Color.GREEN);
    renderer.setSeriesPaint(1, Color.RED);
    renderer.setSeriesPaint(2, Color.BLUE);

    // return a new chart containing the overlaid plot...
    return new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
}

From source file:MonteCarloWindowLogic.java

static void drawPointsOnChart(JPanel panelWhenInside, ArrayList<Point2D> convexHull, ArrayList<Point2D> hits,
        ArrayList<Point2D> miss) {
    panelWhenInside.removeAll();/*from  w  w  w .j a  v  a2  s  .co  m*/
    panelWhenInside.setLayout(new java.awt.BorderLayout());

    XYSeries seriersHits = new XYSeries("Hits");
    convertArrayListToXYSeries(seriersHits, hits);

    XYSeries seriersMiss = new XYSeries("Miss");
    convertArrayListToXYSeries(seriersMiss, miss);
    //TODO refactor this, to handling hits, miss and than convex hull

    int pairsNumber = 0;
    if (convexHull != null)
        pairsNumber = convexHull.size() - 1;
    XYSeries covnexHullDivideOnPiars[] = new XYSeries[pairsNumber];

    for (int i = 0; i < covnexHullDivideOnPiars.length; i++) {
        covnexHullDivideOnPiars[i] = new XYSeries("Convex hull pair " + i);
    }

    if (convexHull != null) {
        divideOnPairsAndConvertConvexHullIntoSeries(covnexHullDivideOnPiars, convexHull);
    }

    // Add the seriersAllPoints to your data set
    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(seriersHits);
    dataset.addSeries(seriersMiss);

    for (int i = 0; i < covnexHullDivideOnPiars.length; i++) {
        dataset.addSeries(covnexHullDivideOnPiars[i]);
    }

    // Generate the graph
    JFreeChart chart = ChartFactory.createXYLineChart(null, // Title
            null, // x-axis Label
            null, // y-axis Label
            dataset, // Dataset
            PlotOrientation.VERTICAL, // Plot Orientation
            false, // Show Legend
            false, // Use tooltips
            false // Configure chart to generate URLs?
    );

    final XYPlot plot = chart.getXYPlot();
    ChartPanel chartPanel = new ChartPanel(chart);
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesPaint(0, Color.GREEN);
    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesShape(0, ShapeUtilities.createDiamond(3));

    renderer.setSeriesPaint(1, Color.RED);
    renderer.setSeriesLinesVisible(1, false);
    renderer.setSeriesShape(1, ShapeUtilities.createDiamond(3));

    for (int i = 2; i <= covnexHullDivideOnPiars.length + 1; i++) {
        renderer.setSeriesPaint(i, Color.black);
        renderer.setSeriesLinesVisible(i, true);
        renderer.setSeriesStroke(i, new BasicStroke(1.0f));
    }

    plot.setRenderer(renderer);

    panelWhenInside.add(chartPanel, BorderLayout.CENTER);
    panelWhenInside.validate();
}

From source file:FindHullWindowLogic.java

static void drawPointsOnChart(JPanel panelWhenInside, ArrayList<Point2D> convexHull) {
    panelWhenInside.removeAll();/*  w  w w  .  jav a 2 s.  c om*/
    panelWhenInside.setLayout(new java.awt.BorderLayout());
    XYSeries seriersAllPoints = new XYSeries("All points");
    addPointsToSeries(seriersAllPoints);

    int pairsNumber = 0;
    if (convexHull != null)
        pairsNumber = convexHull.size() - 1;
    XYSeries covnexHullDivideOnPiars[] = new XYSeries[pairsNumber];

    for (int i = 0; i < covnexHullDivideOnPiars.length; i++) {
        covnexHullDivideOnPiars[i] = new XYSeries("Convex hull pair " + i);
    }

    if (convexHull != null) {
        divideOnPairsAndConvertConvexHullIntoSeries(covnexHullDivideOnPiars, convexHull);
    }

    // Add the seriersAllPoints to your data set
    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(seriersAllPoints);

    for (int i = 0; i < covnexHullDivideOnPiars.length; i++) {
        dataset.addSeries(covnexHullDivideOnPiars[i]);
    }

    // Generate the graph
    JFreeChart chart = ChartFactory.createXYLineChart(null, // Title
            null, // x-axis Label
            null, // y-axis Label
            dataset, // Dataset
            PlotOrientation.VERTICAL, // Plot Orientation
            false, // Show Legend
            false, // Use tooltips
            false // Configure chart to generate URLs?
    );

    final XYPlot plot = chart.getXYPlot();
    ChartPanel chartPanel = new ChartPanel(chart);
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesPaint(0, Color.BLACK);
    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesShape(0, ShapeUtilities.createDiamond(3));

    for (int i = 1; i <= covnexHullDivideOnPiars.length; i++) {
        renderer.setSeriesPaint(i, Color.red);
        renderer.setSeriesLinesVisible(i, true);
        renderer.setSeriesStroke(i, new BasicStroke(1.0f));
    }

    plot.setRenderer(renderer);

    panelWhenInside.add(chartPanel, BorderLayout.CENTER);
    panelWhenInside.validate();
}

From source file:playground.dgrether.analysis.scripts.Trb09Analysis.java

public static void writeMixedDeltaUtilsModeGroupChart(DgDeltaUtilsModeGroupChart deltaUtilsModeGroupChart,
        DgAvgDeltaUtilsModeQuantilesChart avgDScoreModeIncomeChartData, String mixedDeltaScoreIncomeChartFile,
        String mixedMsoDeltaScoreIncomeChartFile, String runid1, String runid2) {
    DgMixedDeltaUtilsModeGroupChart mixedDsIncomeChart = new DgMixedDeltaUtilsModeGroupChart();
    XYSeriesCollection modeChoiceDataset = deltaUtilsModeGroupChart
            .createDeltaScoreIncomeModeChoiceDataset(runid1, runid2);
    mixedDsIncomeChart.addIncomeModeChoiceDataSet(modeChoiceDataset);
    XYSeriesCollection avgScoreDataset = avgDScoreModeIncomeChartData.getDataset();
    mixedDsIncomeChart.addAvgDeltaScoreIncomeDs(avgScoreDataset);
    //      DgChartFrame frame = new DgChartFrame("test", mixedDsIncomeChart.createChart());
    DgChartWriter.writeChart(mixedDeltaScoreIncomeChartFile, mixedDsIncomeChart.createChart());

    XYSeriesCollection ds2 = new XYSeriesCollection();
    ds2.addSeries(modeChoiceDataset.getSeries(2));
    ds2.addSeries(modeChoiceDataset.getSeries(3));
    XYSeriesCollection ds3 = new XYSeriesCollection();
    ds3.addSeries(avgScoreDataset.getSeries(2));
    ds3.addSeries(avgScoreDataset.getSeries(3));
    DgMixedModeSwitcherOnlyDeltaScoreIncomeModeChoiceChart mixedSwichterOnlyDsIncomeChart = new DgMixedModeSwitcherOnlyDeltaScoreIncomeModeChoiceChart();
    mixedSwichterOnlyDsIncomeChart.addIncomeModeChoiceDataSet(ds2);
    mixedSwichterOnlyDsIncomeChart.addAvgDeltaScoreIncomeDs(ds3);
    //      DgChartFrame frame = new DgChartFrame("test", mixedSwichterOnlyDsIncomeChart.createChart());
    DgChartWriter.writeChart(mixedMsoDeltaScoreIncomeChartFile, mixedSwichterOnlyDsIncomeChart.createChart());
}

From source file:max.hubbard.Factoring.Graphing.java

private static XYDataset createDataset(LinkedList<LinkedHashMap<Float, Integer>> list, String orig) {

    final XYSeries series1 = new XYSeries(orig);

    for (double i = -10; i < 11; i++) {
        float v = 0;
        for (LinkedHashMap<Float, Integer> map : list) {
            for (Float f : map.keySet()) {
                if (map.get(f) != 0) {
                    v = v + f * (float) Math.pow(i, map.get(f));
                } else {
                    v = v + f;/*  w  ww.  j  a  va  2  s  . co  m*/
                }
            }
        }
        series1.add(i, v);
    }

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

    return dataset;

}