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:Util.PacketGenerator.java

public static void GenerateGraph() {
    try {/*from w w w  .  j  ava2s  . c  o m*/
        for (int j = 6; j <= 6; j++) {
            File real = new File("D:\\Mestrado\\SketchMatrix\\trunk\\Simulations\\Analise\\Scenario1\\Topology"
                    + j + "\\Real.csv");
            for (int k = 1; k <= 4; k++) {
                File simu = new File(
                        "D:\\Mestrado\\SketchMatrix\\trunk\\Simulations\\Analise\\Scenario1\\Topology" + j
                                + "\\SimulacaoInstancia" + k + ".csv");

                FileInputStream simuFIS = new FileInputStream(simu);
                DataInputStream simuDIS = new DataInputStream(simuFIS);
                BufferedReader simuBR = new BufferedReader(new InputStreamReader(simuDIS));

                FileInputStream realFIS = new FileInputStream(real);
                DataInputStream realDIS = new DataInputStream(realFIS);
                BufferedReader realBR = new BufferedReader(new InputStreamReader(realDIS));

                String lineSimu = simuBR.readLine();
                String lineReal = realBR.readLine();

                XYSeries matrix = new XYSeries("Matriz", false, true);
                while (lineSimu != null && lineReal != null) {

                    lineSimu = lineSimu.replaceAll(",", ".");
                    String[] simuMatriz = lineSimu.split(";");
                    String[] realMatriz = lineReal.split(";");

                    for (int i = 0; i < simuMatriz.length; i++) {
                        try {
                            Integer valorReal = Integer.parseInt(realMatriz[i]);
                            Float valorSimu = Float.parseFloat(simuMatriz[i]);
                            matrix.add(valorReal.doubleValue() / 1000.0, valorSimu.doubleValue() / 1000.0);
                        } catch (NumberFormatException ex) {

                        }
                    }
                    lineSimu = simuBR.readLine();
                    lineReal = realBR.readLine();
                }

                simuFIS.close();
                simuDIS.close();
                simuBR.close();

                realFIS.close();
                realDIS.close();
                realBR.close();

                double maxPlot = Double.max(matrix.getMaxX(), matrix.getMaxY()) * 1.1;
                XYSeries middle = new XYSeries("Referncia");
                ;
                middle.add(0, 0);
                middle.add(maxPlot, maxPlot);
                XYSeries max = new XYSeries("Superior 20%");
                max.add(0, 0);
                max.add(maxPlot, maxPlot * 1.2);
                XYSeries min = new XYSeries("Inferior 20%");
                min.add(0, 0);
                min.add(maxPlot, maxPlot * 0.8);

                XYSeriesCollection dataset = new XYSeriesCollection();
                dataset.addSeries(middle);
                dataset.addSeries(matrix);
                dataset.addSeries(max);
                dataset.addSeries(min);
                JFreeChart chart;
                if (k == 4) {
                    chart = ChartFactory.createXYLineChart("Matriz de Trfego", "Real", "CMO-MT", dataset);
                } else {
                    chart = ChartFactory.createXYLineChart("Matriz de Trfego", "CMO-MT", "Zhao", dataset);
                }
                chart.setBackgroundPaint(Color.WHITE);
                chart.getPlot().setBackgroundPaint(Color.WHITE);
                chart.getTitle().setFont(new Font("Times New Roman", Font.BOLD, 13));

                chart.getLegend().setItemFont(new Font("Times New Roman", Font.TRUETYPE_FONT, 10));

                chart.getXYPlot().getDomainAxis().setLabelFont(new Font("Times New Roman", Font.BOLD, 10));
                chart.getXYPlot().getDomainAxis()
                        .setTickLabelFont(new Font("Times New Roman", Font.TRUETYPE_FONT, 1));
                chart.getXYPlot().getRangeAxis().setLabelFont(new Font("Times New Roman", Font.BOLD, 10));
                chart.getXYPlot().getRangeAxis()
                        .setTickLabelFont(new Font("Times New Roman", Font.TRUETYPE_FONT, 1));

                XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) chart.getXYPlot().getRenderer();

                renderer.setSeriesLinesVisible(1, false);
                renderer.setSeriesShapesVisible(1, true);

                renderer.setSeriesStroke(0, new BasicStroke(2.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER,
                        10.0f, new float[] { 0.1f }, 0.0f));
                renderer.setSeriesShape(1, new Ellipse2D.Float(-1.5f, -1.5f, 3f, 3f));
                renderer.setSeriesStroke(2, new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER,
                        10.0f, new float[] { 3.0f }, 0.0f));
                renderer.setSeriesStroke(3, new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER,
                        10.0f, new float[] { 3.0f }, 0.0f));

                renderer.setSeriesPaint(0, Color.BLACK);
                renderer.setSeriesPaint(1, Color.BLACK);
                renderer.setSeriesPaint(2, Color.BLACK);
                renderer.setSeriesPaint(3, Color.BLACK);

                int width = (int) (192 * 1.5f); /* Width of the image */

                int height = (int) (144 * 1.5f); /* Height of the image */

                File XYChart = new File(
                        "D:\\Mestrado\\SketchMatrix\\trunk\\Simulations\\Analise\\Scenario1\\Topology" + j
                                + "\\SimulacaoInstancia" + k + ".jpeg");
                ChartUtilities.saveChartAsJPEG(XYChart, chart, width, height);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.jfree.chart.demo.selection.SelectionDemo2.java

public static XYDataset createDataset() {
    Random rgen = new Random();
    XYSeriesCollection dataset = new XYSeriesCollection();
    for (int s = 0; s < 3; s++) {
        XYSeries series = new XYSeries("S" + s);
        for (int i = 0; i < 100; i++) {
            double x = rgen.nextGaussian() * 200;
            double y = rgen.nextGaussian() * 200;
            series.add(x, y);/*from w w  w  . j av a 2  s.c o  m*/
        }
        dataset.addSeries(series);
    }
    return dataset;
}

From source file:org.jfree.chart.demo.selection.SelectionDemo3.java

public static XYDataset createDataset() {
    String[] names = { "JFreeChart", "Eastwood", "Orson", "JCommon" };
    Random rgen = new Random();
    XYSeriesCollection dataset = new XYSeriesCollection();
    for (int s = 0; s < 4; s++) {
        XYSeries series = new XYSeries(names[s]);
        for (int i = 0; i < 5000; i++) {
            double x = rgen.nextGaussian() * 200;
            double y = rgen.nextGaussian() * 200;
            series.add(x, y);// w w  w  . ja  va  2 s .  c  o m
        }
        dataset.addSeries(series);
    }
    return dataset;
}

From source file:audio.cords.old.RegressionDemo.java

private static XYSeriesCollection getTestData() {
    Random rg = new Random();
    XYSeriesCollection data = new XYSeriesCollection();
    for (int i = 1; i <= 3; i++) {
        XYSeries series = new XYSeries("Series " + i);
        double a = rg.nextDouble() - .5;
        int b = rg.nextInt(20) - 10;
        for (int j = 1; j <= 20; j++) {
            double x = j + (rg.nextDouble() - .5);
            double y = a * j + b + (rg.nextDouble() - .5) * 2;
            series.add(x, y);//from  w  w  w.j  av  a  2 s  .  c  om
        }
        data.addSeries(series);
    }
    return data;
}

From source file:edu.msu.cme.rdp.classifier.train.validation.distance.BoxPlotUtils.java

public static void readData(String inFile, File outdir, String xAxisLabel, String yAxisLabel)
        throws IOException {
    XYSeriesCollection dataset = new XYSeriesCollection();
    DefaultBoxAndWhiskerCategoryDataset scatterDataset = new DefaultBoxAndWhiskerCategoryDataset();

    BufferedReader reader = new BufferedReader(new FileReader(inFile));
    String line = reader.readLine();

    while ((line = reader.readLine()) != null) {
        String[] values = line.split("\\t");
        XYSeries series = new XYSeries(values[2]);
        dataset.addSeries(series);

        double average = Double.parseDouble(values[4]);
        int Q1 = Integer.parseInt(values[6]);
        ;/*from  ww  w  .j a  va 2s  .c  o m*/
        int median = Integer.parseInt(values[7]);
        int Q3 = Integer.parseInt(values[8]);
        int pct_98 = Integer.parseInt(values[9]);
        int pct_2 = Integer.parseInt(values[10]);
        int minOutlier = 0; // we don't care about the outliers
        int maxOutlier = 0; //

        BoxAndWhiskerItem item = new BoxAndWhiskerItem(average, median, Q1, Q3, pct_2, pct_98, minOutlier,
                maxOutlier, new ArrayList());
        scatterDataset.add(item, values[2], "");
    }

    String title = new File(inFile).getName();
    int index = title.indexOf(".");
    if (index != -1) {
        title = title.substring(0, index);
    }

    Font lableFont = new Font("Helvetica", Font.BOLD, 28);
    createBoxplot(scatterDataset, new PrintStream(new File(outdir, title + ".boxchart.png")), title, xAxisLabel,
            yAxisLabel, lableFont);

}

From source file:jprobix.ui.SPlotFinal.java

private static XYDataset samplexydataset2() {
    int cols = 20;
    int rows = 20;
    double[][] values = new double[cols][rows];

    XYSeriesCollection xySeriesCollection = new XYSeriesCollection();
    XYSeries series = new XYSeries("Random");

    Random rand = new Random();
    for (int i = 0; i < values.length; i++) {
        for (int j = 0; j < values.length; j++) {
            double x = Math.round(rand.nextDouble() * 500);
            double y = Math.round(rand.nextDouble() * 500);

            series.add(x, y);/*  w  w w  .  j  a  v  a  2  s.  c  o m*/
        }
    }
    xySeriesCollection.addSeries(series);
    return xySeriesCollection;

}

From source file:org.jfree.data.time.MovingAverage.java

/**
 * Creates a new {@link XYDataset} containing the moving averages of each
 * series in the <code>source</code> dataset.
 *
 * @param source  the source dataset./*from w w  w.j  av a2 s .c  om*/
 * @param suffix  the string to append to source series names to create
 *                target series names.
 * @param period  the averaging period.
 * @param skip  the length of the initial skip period.
 *
 * @return The dataset.
 */
public static XYDataset createMovingAverage(XYDataset source, String suffix, double period, double skip) {

    ParamChecks.nullNotPermitted(source, "source");
    XYSeriesCollection result = new XYSeriesCollection();
    for (int i = 0; i < source.getSeriesCount(); i++) {
        XYSeries s = createMovingAverage(source, i, source.getSeriesKey(i) + suffix, period, skip);
        result.addSeries(s);
    }
    return result;
}

From source file:eu.cassandra.training.utils.ChartUtils.java

/**
 * This function is used for the visualization of a Line Diagram.
 * //  w w w.  j  av a  2s  .  co  m
 * @param title
 *          The title of the chart.
 * @param x
 *          The unit on the X axis of the chart.
 * @param y
 *          The unit on the Y axis of the chart.
 * @param data
 *          The array of values.
 * @return a chart panel with the graphical representation.
 */
public static ChartPanel createLineDiagram(String title, String x, String y, double[] data) {

    XYSeries series1 = new XYSeries("Active Power");
    for (int i = 0; i < data.length; i++) {
        series1.add(i, data[i]);
    }

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

    PlotOrientation orientation = PlotOrientation.VERTICAL;
    boolean show = true;
    boolean toolTips = false;
    boolean urls = false;

    JFreeChart chart = ChartFactory.createXYLineChart(title, x, y, dataset, orientation, show, toolTips, urls);

    return new ChartPanel(chart);
}

From source file:stratego.neural.net.NeuralNetTest.java

private static void plotDataSet(List<NamedDataSet> ArraySetList) {

    XYSeriesCollection plotData = new XYSeriesCollection();

    for (NamedDataSet ns : ArraySetList) {
        XYSeries series = new XYSeries(ns.getName());
        double[] data = ns.getArray();
        for (int i = 0; i < data.length; i++) {
            series.add((double) i, data[i]);
        }//from  w w  w .j av a  2s . c om

        plotData.addSeries(series);
    }

    String title = "Overfitting Data";
    String xAxisLabel = "Epochs";
    String yAxisLabel = "Accuracy";
    PlotOrientation orientation = PlotOrientation.VERTICAL;
    boolean legend = true; // might wanna set this to true at some point, but research the library
    boolean tooltips = false;
    boolean urls = false;
    JFreeChart chart = ChartFactory.createScatterPlot(title, xAxisLabel, yAxisLabel, plotData, orientation,
            legend, tooltips, urls);

    JPanel panel = new ChartPanel(chart);

    JFrame f = new JFrame();
    f.add(panel);
    f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    f.pack();
    f.setTitle("Overfitting data");

    f.setVisible(true);
}

From source file:eu.cassandra.training.utils.ChartUtils.java

public static ChartPanel createLineDiagram(String title, String x, String y, double[] data, double[] data2) {

    XYSeries series1 = new XYSeries("Active Power");
    for (int i = 0; i < data.length; i++) {
        series1.add(i, data[i]);/*from   ww  w  .  j  a  va  2  s  .  c om*/
    }

    XYSeries series2 = new XYSeries("Reactive Power");
    for (int i = 0; i < data2.length; i++) {
        series2.add(i, data2[i]);
    }

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

    PlotOrientation orientation = PlotOrientation.VERTICAL;
    boolean show = true;
    boolean toolTips = false;
    boolean urls = false;

    JFreeChart chart = ChartFactory.createXYLineChart(title, x, y, dataset, orientation, show, toolTips, urls);

    return new ChartPanel(chart);
}