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:org.samjoey.graphing.GraphUtility.java

/**
 *
 * @param games the games to graph/*from ww  w .j  a  v  a  2  s  .c om*/
 * @param key the variable to create the graph with
 * @param start if index, the index at which to start, else the percent in
 * the game at which to start
 * @param stop if index, the index at which to end, else the percent in the
 * game at which to end
 * @param index
 * @return
 */
public static ChartPanel getCustomGraph(Game[] games, String key, double start, double stop, boolean index) {
    XYSeriesCollection dataset = new XYSeriesCollection();
    for (Game game : games) {
        ArrayList<Double> data = game.getVar(key);
        int begin;
        int end;
        if (index) {
            begin = (int) start;
            end = (int) stop;
        } else {
            begin = (int) (data.size() / start);
            end = (int) (data.size() / stop);
        }
        XYSeries series = GraphUtility.createSeries(data.subList(begin, end), "" + game.getId());
        dataset.addSeries(series);
    }
    JFreeChart chart = ChartFactory.createXYLineChart(key, // chart title
            "X", // x axis label
            "Y", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, false, // include legend
            true, // tooltips
            false // urls
    );
    XYPlot plot = chart.getXYPlot();
    XYItemRenderer rend = plot.getRenderer();
    for (int i = 0; i < games.length; i++) {
        Game g = games[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);
    return chartPanel;
}

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

private static XYDataset createDataset() {
    XYSeries xyseries = new XYSeries("First");
    xyseries.add(1.0D, 1.0D);//from   w  ww.j  av  a2  s  .  c  o m
    xyseries.add(2D, 4D);
    xyseries.add(3D, 3D);
    xyseries.add(4D, 5D);
    xyseries.add(5D, 5D);
    xyseries.add(6D, 7D);
    xyseries.add(7D, 7D);
    xyseries.add(8D, 8D);
    XYSeries xyseries1 = new XYSeries("Second");
    xyseries1.add(1.0D, 5D);
    xyseries1.add(2D, 7D);
    xyseries1.add(3D, 6D);
    xyseries1.add(4D, 8D);
    xyseries1.add(5D, 4D);
    xyseries1.add(6D, 4D);
    xyseries1.add(7D, 2D);
    xyseries1.add(8D, 1.0D);
    XYSeries xyseries2 = new XYSeries("Third");
    xyseries2.add(3D, 4D);
    xyseries2.add(4D, 3D);
    xyseries2.add(5D, 2D);
    xyseries2.add(6D, 3D);
    xyseries2.add(7D, 6D);
    xyseries2.add(8D, 3D);
    xyseries2.add(9D, 4D);
    xyseries2.add(10D, 3D);
    XYSeriesCollection xyseriescollection = new XYSeriesCollection();
    xyseriescollection.addSeries(xyseries);
    xyseriescollection.addSeries(xyseries1);
    xyseriescollection.addSeries(xyseries2);
    return xyseriescollection;
}

From source file:utlis.HistogramPlot.java

public JFreeChart plotGrayChart(int[] histogram) {

    XYSeries xysBrightnes = new XYSeries("Brightnes");

    for (int i = 0; i < histogram.length; i++) {

        xysBrightnes.add(i, histogram[i]);
    }/*w  ww . j  a v  a  2  s . c  o  m*/

    XYSeriesCollection collection = new XYSeriesCollection();
    collection.addSeries(xysBrightnes);

    JFreeChart chart = ChartFactory.createXYLineChart("Histogram", "Color Value", "Pixel count", collection);
    try {
        ChartUtilities.saveChartAsJPEG(new File("chart.jpg"), chart, 500, 300);
    } catch (IOException ex) {
        Logger.getLogger(HistogramPlot.class.getName()).log(Level.SEVERE, null, ex);
    }
    return chart;
}

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

private static XYDataset createDataset() {
    XYSeries xyseries = new XYSeries("Series 1");
    xyseries.add(1.0D, 3D);/*from  ww  w  .  java 2 s. com*/
    xyseries.add(2D, 4D);
    xyseries.add(3D, 2D);
    xyseries.add(6D, 3D);
    XYSeries xyseries1 = new XYSeries("Series 2");
    xyseries1.add(1.0D, 7D);
    xyseries1.add(2D, 6D);
    xyseries1.add(3D, 9D);
    xyseries1.add(4D, 5D);
    xyseries1.add(6D, 4D);
    XYSeriesCollection xyseriescollection = new XYSeriesCollection();
    xyseriescollection.addSeries(xyseries);
    xyseriescollection.addSeries(xyseries1);
    return xyseriescollection;
}

From source file:jamel.gui.charts.AbstractScatterChart.java

/**
 * Returns a new plot.//from  w ww  . j  a  v a  2  s  .com
 * 
 * @param xySeries  the series.
 * @param xAxisLabel  the label of the horizontal axis.
 * @param yAxisLabel  the label of the vertical axis.
 * @return a new plot.
 */
static private Plot newPlot(XYSeries xySeries, String xAxisLabel, String yAxisLabel) {
    final XYSeriesCollection dataset = new XYSeriesCollection();
    if (xySeries != null)
        dataset.addSeries(xySeries);
    final XYPlot plot = new XYPlot(dataset, new NumberAxis(xAxisLabel), new NumberAxis(yAxisLabel),
            new XYLineAndShapeRenderer(false, true));
    plot.setOrientation(PlotOrientation.VERTICAL);
    return plot;
}

From source file:ChartPanelMaker.java

public static ChartPanel createChart(ArrayList<Voter> voters, ArrayList<Candidate> candidates,
        ArrayList<Candidate> committee, String title) {
    XYSeriesCollection dataset = new XYSeriesCollection();
    XYSeries comitteeDataset = new XYSeries("Committee");
    for (Candidate c : committee) {
        comitteeDataset.add(c.getX(), c.getY());
    }/*from  w w w .ja  v  a 2 s . c  om*/
    dataset.addSeries(comitteeDataset);

    int n = voters.size();
    int m = candidates.size();

    int skipN = n / 150;
    if (skipN < 1) {
        skipN = 1;
    }

    int skipM = m / 150;
    if (skipM < 1) {
        skipM = 1;
    }

    Collections.sort(voters, Election.VoterNameComparator);
    Collections.sort(candidates, Election.CandidateNameComparator);

    XYSeries voterDataset = new XYSeries("Voters");
    for (int i = 0; i < n; i++) {
        Voter v = voters.get(i);
        if (i % skipN == 0) {
            voterDataset.add(v.getX(), v.getY());
        }
    }
    dataset.addSeries(voterDataset);

    XYSeries candidateDataset = new XYSeries("Candidates");
    for (int i = 0; i < m; i++) {
        Candidate c = candidates.get(i);
        if (i % skipM == 0) {
            candidateDataset.add(c.getX(), c.getY());
        }
    }
    dataset.addSeries(candidateDataset);

    Shape committeeShape = ShapeUtilities.createDiamond(5);
    Shape voterShape = ShapeUtilities.createDownTriangle(3);
    Shape candidateShape = ShapeUtilities.createUpTriangle(3);

    Color committeeColor = Color.DARK_GRAY;
    Color voterColor = Color.ORANGE;
    Color candidateColor = Color.LIGHT_GRAY;

    JFreeChart chart = ChartFactory.createScatterPlot(title, "", "", dataset, PlotOrientation.VERTICAL, true,
            true, true);
    XYPlot plot = chart.getXYPlot();
    XYItemRenderer r = plot.getRenderer();
    r.setSeriesShape(0, committeeShape);
    r.setSeriesPaint(0, committeeColor);
    r.setSeriesShape(1, voterShape);
    r.setSeriesPaint(1, voterColor);
    r.setSeriesShape(2, candidateShape);
    r.setSeriesPaint(2, candidateColor);
    ChartPanel chartPanel = new ChartPanel(chart);

    return chartPanel;
}

From source file:fitness.datagrapgh.java

public datagrapgh(String table, String y) throws SQLException {
    frame = new JFrame();
    Calendar cal = Calendar.getInstance();
    DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
    cal.add(Calendar.DATE, -8);/* ww w  . jav  a2 s  .  c o m*/
    XYSeriesCollection dataset = new XYSeriesCollection();
    XYSeries series1 = new XYSeries(table);
    connec c = new connec();
    for (int i = 0; i < 7; i++) {
        cal.add(Calendar.DATE, 1);
        String s = df.format(cal.getTime());
        c.connect();
        if (table.equals("consumption")) {
            c.rs = c.st.executeQuery(
                    "SELECT calories FROM consumption WHERE uid='" + temp.getId() + "' AND date='" + s + "'");
            while (c.rs.next()) {
                //System.out.println("hello");
                String gra = c.rs.getString("calories");
                int n = Integer.parseInt(gra);
                series1.add(i, n);
            }
        } else {
            c.rs = c.st.executeQuery("SELECT calories_burned FROM workout WHERE uid='" + temp.getId()
                    + "' AND date='" + s + "'");
            while (c.rs.next()) {
                //System.out.println("hello");
                String gra = c.rs.getString("calories_burned");
                int n = Integer.parseInt(gra);
                series1.add(i, n);
            }
        }

    }
    c.disconnect();
    dataset.addSeries(series1);
    JFreeChart chart = ChartFactory.createXYLineChart("Fitness analyisis", "day", y, dataset,
            PlotOrientation.VERTICAL, true, true, false);
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new Dimension(400, 400));
    chartPanel.setBounds(100, 100, 400, 400);
    chartPanel.setVisible(true);
    frame.setSize(500, 500);
    frame.setVisible(true);
    frame.add(chartPanel);

}

From source file:net.sf.mzmine.chartbasics.gui.javafx.demo.FXChartGestureDemo.java

/**
 * Creates a dataset, consisting of two series of monthly data.
 *
 * @return the dataset./*from w w  w .  j a v  a2 s .co m*/
 */
private static XYDataset createDataset() {
    XYSeriesCollection data = new XYSeriesCollection();

    Random r = new Random(System.currentTimeMillis());

    for (int i = 0; i < 3; i++) {
        XYSeries s = new XYSeries("Series" + i);
        for (int x = 0; x < 100; x++) {
            double v = r.nextGaussian() * (i + 1);
            s.add(x, v);
        }
        data.addSeries(s);
    }
    return data;
}

From source file:pwm.visualizer.MotivationDistributionPanel.java

public MotivationDistributionPanel(String title) {
    motivationDataSet = new XYSeriesCollection();
    JPanel panel = createPanel(title);
    this.setPreferredSize(new Dimension(500, 300));
    this.setLayout(new BorderLayout());
    this.add(panel);
}

From source file:lifnetwork.ChartSave.java

public ChartSave() {
    super(ChartFactory.createScatterPlot("Population Fire", "Time (s)", "Neuron #", (new XYSeriesCollection()),
            PlotOrientation.VERTICAL, false, false, false));
    fireChart = this.getChart();
    fireChart.setNotify(false);// w w w.  j  ava  2 s  .co  m
    XYPlot plot = fireChart.getXYPlot();
    plot.setBackgroundPaint(Color.WHITE);
    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setSeriesShapesVisible(0, true);
    renderer.setSeriesShape(0, new Rectangle2D.Double(0, 0, 1, 1));
    fireCollection = (XYSeriesCollection) plot.getDataset();
    fireSeries = new XYSeries("fires");
    fireCollection.addSeries(fireSeries);
}