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

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

Introduction

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

Prototype

public XYSeriesCollection() 

Source Link

Document

Constructs an empty dataset.

Usage

From source file:ui.Graph.java

/**
 * Creates a chart./*from w  ww .  ja v a  2s .  c om*/
 *
 * @param dataset
 *            the data for the chart.
 *
 * @return a chart.
 */
private JFreeChart createChart(ArrayList<Setpoint> setpoints, ArrayList<Setpoint> traj) {
    trajectory = traj;

    XYSeries posSeries = new XYSeries("Position");
    XYSeries trajSeries = new XYSeries("Trajectory");
    XYSeries velSeries = new XYSeries("Velocity");
    for (int i = 0; i < setpoints.size(); i++) {

        Setpoint p = setpoints.get(i);
        posSeries.add(p.time, p.position);
        velSeries.add(p.time, p.velocity);
    }

    for (int i = 0; i < trajectory.size(); i++) {

        Setpoint p = trajectory.get(i);
        trajSeries.add(p.time, p.position);

    }

    XYSeriesCollection posDataset = new XYSeriesCollection();
    XYSeriesCollection trajDataset = new XYSeriesCollection();
    XYSeriesCollection velDataset = new XYSeriesCollection();

    posDataset.addSeries(posSeries);
    velDataset.addSeries(velSeries);
    trajDataset.addSeries(trajSeries);
    // create the chart...
    final JFreeChart chart = ChartFactory.createScatterPlot("System output", // chart title
            "X", // x axis label
            "Y", // y axis label
            posDataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white);

    // final StandardLegend legend = (StandardLegend) chart.getLegend();
    // legend.setDisplaySeriesShapes(true);
    // get a reference to the plot for further customisation...
    final XYPlot plot = chart.getXYPlot();

    plot.setDataset(0, posDataset);
    plot.setDataset(1, trajDataset);
    plot.setDataset(2, velDataset);
    plot.setBackgroundPaint(Color.white);
    // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);

    XYLineAndShapeRenderer posRenderer = new XYLineAndShapeRenderer();
    // renderer.setSeriesShape(0, new Ellipse2D.Float(1.0f, 1.0f, 1.0f,
    // 1.0f));
    posRenderer.setSeriesPaint(0, Color.BLUE);
    posRenderer.setSeriesLinesVisible(0, true);
    posRenderer.setSeriesShapesVisible(0, false);
    XYStepRenderer trajRenderer = new XYStepRenderer();
    trajRenderer.setSeriesPaint(1, Color.RED);
    trajRenderer.setSeriesStroke(1, new BasicStroke(10));
    trajRenderer.setSeriesLinesVisible(1, true);
    trajRenderer.setSeriesShapesVisible(1, false);

    XYLineAndShapeRenderer velRenderer = new XYLineAndShapeRenderer();
    velRenderer.setSeriesPaint(0, Color.MAGENTA);
    velRenderer.setSeriesLinesVisible(0, true);
    velRenderer.setSeriesShapesVisible(0, false);
    // renderer.setSeriesStroke(1, new BasicStroke(0.01f));
    plot.setRenderer(0, posRenderer);
    plot.setRenderer(1, trajRenderer);
    plot.setRenderer(2, velRenderer);

    for (Setpoint s : trajectory) {
        Marker marker = new ValueMarker(s.time);
        marker.setPaint(Color.DARK_GRAY);
        marker.setLabel(Float.toString((float) s.position));
        marker.setLabelAnchor(RectangleAnchor.TOP_LEFT);
        marker.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
        plot.addDomainMarker(marker);
    }

    XYTextAnnotation p = new XYTextAnnotation("kP = " + gains.kP, plot.getDomainAxis().getUpperBound() * 0.125,
            plot.getRangeAxis().getUpperBound() * .75);
    p.setFont(new Font("Dialog", Font.PLAIN, 12));
    plot.addAnnotation(p);
    XYTextAnnotation i = new XYTextAnnotation("kI = " + gains.kI, plot.getDomainAxis().getUpperBound() * 0.125,
            plot.getRangeAxis().getUpperBound() * .7);
    i.setFont(new Font("Dialog", Font.PLAIN, 12));
    plot.addAnnotation(i);
    XYTextAnnotation d = new XYTextAnnotation("kD = " + gains.kD, plot.getDomainAxis().getUpperBound() * 0.125,
            plot.getRangeAxis().getUpperBound() * .65);
    d.setFont(new Font("Dialog", Font.PLAIN, 12));
    plot.addAnnotation(d);

    // change the auto tick unit selection to integer units only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setAutoRange(true);
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}

From source file:org.gwaspi.reports.PlinkReportLoaderCombined.java

public static CombinedRangeXYPlot loadAssocUnadjLogPvsPos(File plinkReport, Set<String> redMarkers)
        throws IOException {

    NumberAxis sharedAxis = new NumberAxis("-log?(P)");
    sharedAxis.setTickMarkInsideLength(3.0f);
    CombinedRangeXYPlot combinedPlot = new CombinedRangeXYPlot(sharedAxis);
    combinedPlot.setGap(0);/*from   ww w  .  ja va  2 s.c o m*/

    XYSeries series1 = null;
    XYSeries series2 = null;
    FileReader inputFileReader = null;
    BufferedReader inputBufferReader = null;
    try {
        inputFileReader = new FileReader(plinkReport);
        inputBufferReader = new BufferedReader(inputFileReader);

        // Getting data from file and subdividing to series all points by chromosome
        String l;
        String tempChr = "";
        // read but ignore the header
        /*String header = */inputBufferReader.readLine();
        int count = 0;
        while ((l = inputBufferReader.readLine()) != null) {
            if (count % 10000 == 0) {
                log.info("loadAssocUnadjLogPvsPos -> reader count: {}", count);
            }
            count++;

            l = l.trim().replaceAll("\\s+", ",");
            String[] cVals = l.split(",");
            String markerId = cVals[1];
            int position = Integer.parseInt(cVals[2]);
            String s_pVal = cVals[8];

            if (!s_pVal.equals("NA")) {
                double pValue = Double.parseDouble(s_pVal); // P value

                if (cVals[0].toString().equals(tempChr)) {
                    if (redMarkers.contains(markerId)) { // Insert in alternate color series
                        series2.add(position, pValue);
                    } else {
                        series1.add(position, pValue);
                    }

                    //                  series1.add(position, logPValue);
                } else {
                    if (!tempChr.isEmpty()) { // Not the first time round!
                        XYSeriesCollection tempChrData = new XYSeriesCollection();
                        tempChrData.addSeries(series1);
                        tempChrData.addSeries(series2);
                        appendToCombinedRangePlot(combinedPlot, tempChr, tempChrData, false);
                    }

                    tempChr = cVals[0];
                    series1 = new XYSeries("Imputed");
                    series2 = new XYSeries("Observed"); // Alternate color series
                    if (redMarkers.contains(markerId)) { // Insert inlternate color series
                        series2.add(position, pValue);
                    } else {
                        series1.add(position, pValue);
                    }

                    //                  series1 = new XYSeries(cVals[0]);
                    //                  series1.add(position, logPValue);
                }
            }
        }
        // Append last chromosome to combined plot
        XYSeriesCollection tempChrData = new XYSeriesCollection();
        tempChrData.addSeries(series1);
        tempChrData.addSeries(series2);
        appendToCombinedRangePlot(combinedPlot, tempChr, tempChrData, true);
    } finally {
        try {
            if (inputBufferReader != null) {
                inputBufferReader.close();
            } else if (inputFileReader != null) {
                inputFileReader.close();
            }
        } catch (Exception ex) {
            log.warn(null, ex);
        }
    }

    return combinedPlot;
}

From source file:com.googlecode.logVisualizer.chart.StatDevelopmentLineChart.java

@Override
protected XYDataset createDataset() {
    final XYSeriesCollection datasets = new XYSeriesCollection();
    final XYSeries muscleDataset = new XYSeries("Muscle", false);
    final XYSeries mystDataset = new XYSeries("Mysticality", false);
    final XYSeries moxieDataset = new XYSeries("Moxie", false);

    Statgain stats = Statgain.NO_STATS;//from w w  w. j  ava  2s  .  c  o m
    if (getLogData().isDetailedLog())
        for (final SingleTurn si : getLogData().getTurnsSpent())
            stats = addStatValues(muscleDataset, mystDataset, moxieDataset, stats, si);
    else
        for (final TurnInterval ti : getLogData().getTurnIntervalsSpent())
            stats = addStatValues(muscleDataset, mystDataset, moxieDataset, stats, ti);

    // If the log actually held any statgain data, add it to the collection.
    if (!stats.isAllStatsZero()) {
        datasets.addSeries(muscleDataset);
        datasets.addSeries(mystDataset);
        datasets.addSeries(moxieDataset);
    }

    return datasets;
}

From source file:org.samjoey.graphing.GraphUtility.java

public static HashMap<String, ChartPanel> getGraphs(LinkedList<Game> games) {
    HashMap<String, XYSeriesCollection> datasets = new HashMap<>();
    for (int j = 0; j < games.size(); j++) {
        Game game = games.get(j);//  w  ww  .j  a  va  2  s . c  o  m
        if (game == null) {
            continue;
        }
        for (String key : game.getVarData().keySet()) {
            if (datasets.containsKey(key)) {
                try {
                    datasets.get(key).addSeries(createSeries(game.getVar(key), "" + game.getId()));
                } catch (Exception e) {
                }
            } else {
                datasets.put(key, new XYSeriesCollection());
                datasets.get(key).addSeries(createSeries(game.getVar(key), "" + game.getId()));
            }
        }
    }
    HashMap<String, ChartPanel> chartPanels = new HashMap<>();
    for (String key : datasets.keySet()) {
        JFreeChart chart = ChartFactory.createXYLineChart(key, // chart title
                "X", // x axis label
                "Y", // y axis label
                datasets.get(key), // data
                PlotOrientation.VERTICAL, false, // include legend
                true, // tooltips
                false // urls
        );
        XYPlot plot = chart.getXYPlot();
        XYItemRenderer rend = plot.getRenderer();
        for (int i = 0; i < games.size(); i++) {
            Game g = games.get(i);
            if (g.getWinner() == 1) {
                rend.setSeriesPaint(i, Color.RED);
            }
            if (g.getWinner() == 2) {
                rend.setSeriesPaint(i, Color.BLACK);
            }
            if (g.getWinner() == 0) {
                rend.setSeriesPaint(i, Color.PINK);
            }
        }
        ChartPanel chartPanel = new ChartPanel(chart);
        chartPanels.put(key, chartPanel);
    }
    return chartPanels;
}

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

/**
 * Creates a sample dataset./*from  www.  j a  v a 2s  .  c  o  m*/
 * 
 * @return A sample dataset.
 */
private XYDataset createDataset() {
    final XYSeriesCollection data = new XYSeriesCollection();
    final XYSeries series1 = createRandomData("Series 1", 75.0, 10.0);
    final XYSeries series2 = createRandomData("Series 2", 50.0, 5.0);
    final XYSeries series3 = createRandomData("Series 3", 25.0, 1.0);
    data.addSeries(series1);
    data.addSeries(series2);
    data.addSeries(series3);
    return data;
}

From source file:cs.register.geraGrafico.java

private XYSeriesCollection datasocore(List<partida> list1) {
    XYSeriesCollection data = new XYSeriesCollection();
    XYSeries ser = new XYSeries("kda");
    for (partida p : list1) {
        ser.add(list1.indexOf(p) + 1, p.getScore());
    }//w w  w . j  a  va  2s .c om
    data.addSeries(ser);

    return data;
}

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 {// w ww  . j av a  2 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:org.matsim.contrib.parking.parkingchoice.PC2.analysis.ParkingGroupOccupancies.java

@Override
public void reset(int iteration) {
    parkingGroupOccupency = new IntegerValueHashMap<String>();
    parkingGroupOccupancySeries = new HashMap<String, XYSeries>();
    xySeriesCollection = new XYSeriesCollection();
}

From source file:support.SystemMonitorGui.java

private XYPlot createChartFrame(XYSeries series) {
    XYSeriesCollection dataSet = new XYSeriesCollection();
    dataSet.addSeries(series);//from  w w  w.  j  a v a 2  s .c  o m
    JFreeChart chart = ChartFactory.createXYLineChart("Memory Allocation Rate", "Time (ms)",
            "Allocation Rate (MB/s)", dataSet, PlotOrientation.VERTICAL, true, true, false);
    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainGridlinePaint(Color.DARK_GRAY);
    plot.setRangeGridlinePaint(Color.DARK_GRAY);
    plot.getRenderer().setSeriesPaint(0, Color.BLUE);

    JFrame frame = new JFrame();
    frame.setBackground(Color.WHITE);
    frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
    frame.setTitle("Hazelcast Jet Source Builder Sample");
    frame.setBounds(WINDOW_X, WINDOW_Y, WINDOW_WIDTH, WINDOW_HEIGHT);
    frame.setLayout(new BorderLayout());
    frame.add(new ChartPanel(chart));
    frame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent windowEvent) {
            hzMap.removeEntryListener(entryListenerId);
        }
    });
    frame.setVisible(true);
    return plot;
}

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);//  w  ww .  ja v a 2 s. co  m
        }
        data.addSeries(series);
    }
    return data;
}