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:playground.artemc.socialCost.MeanTravelTimeWriter.java

/**
 * @return a graphic showing the number of agents in the evacuated area
 *///w  w w .  j ava  2 s  .co m
private JFreeChart getGraphic(String modeName, double data[]) {

    final XYSeriesCollection xyData = new XYSeriesCollection();
    final XYSeries dataSerie = new XYSeries("mean trip travel time", false, true);

    for (int i = 0; i < data.length; i++) {
        dataSerie.add(i, data[i]);
    }

    xyData.addSeries(dataSerie);

    //      final JFreeChart chart = ChartFactory.createXYStepChart(
    final JFreeChart chart = ChartFactory.createXYLineChart("mean travel time, " + modeName, "iteration",
            "travel time", xyData, PlotOrientation.VERTICAL, true, // legend
            false, // tooltips
            false // urls
    );

    XYPlot plot = chart.getXYPlot();

    final CategoryAxis axis1 = new CategoryAxis("hour");
    axis1.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 7));
    plot.setDomainAxis(new NumberAxis("time"));
    return chart;
}

From source file:org.xapagy.ui.tempdyn.GraphEvolution.java

/**
 * Generates the graph which plots the three choice scores (independent,
 * dependent and mood) for the evolution of a choice in time.
 * /* w  ww  .  j a v a 2s .c o  m*/
 * @param tdc
 *            - encompasses the selected choice
 * @param database
 *            - the database of values collected
 * @param agent
 * @param index
 *            - a list of time points which will be plotted on the x axis
 * @param choiceRange
 *            - the y axis will be [0, choiceRange]
 */
public static void graphChoiceEvolution(tdComponent tdc, tdDataBase database, Agent agent, List<Double> index,
        double choiceRange) {
    String label = PpChoice.ppConcise(tdc.getChoice(), agent);

    // create a general purpose xy collection for jfreechart
    XYSeriesCollection xysc = new XYSeriesCollection();
    // focus and memory
    xysc.addSeries(new XYSeries("ChoiceScoreIndependent"));
    xysc.addSeries(new XYSeries("ChoiceScoreDependent"));
    xysc.addSeries(new XYSeries("ChoiceScoreMood"));
    // Fill in the values
    for (Double time : index) {
        double dtime = time;
        double valueChoiceScoreIndependent = database.getChoiceScoreDependent(tdc.getIdentifier(), time);
        xysc.getSeries("ChoiceScoreIndependent").add(dtime, valueChoiceScoreIndependent);
        double valueChoiceScoreDependent = database.getChoiceScoreDependent(tdc.getIdentifier(), time);
        xysc.getSeries("ChoiceScoreDependent").add(dtime, valueChoiceScoreDependent);
        double valueChoiceScoreMood = database.getChoiceScoreDependent(tdc.getIdentifier(), time);
        xysc.getSeries("ChoiceScoreMood").add(dtime, valueChoiceScoreMood);
    }
    //
    // ok, now let us create a graph
    //
    JPanel panel = new JPanel();
    // create a layout
    GroupLayout layout = new GroupLayout(panel);
    panel.setLayout(layout);
    layout.setAutoCreateGaps(true);
    layout.setAutoCreateContainerGaps(true);
    SequentialGroup sgv = layout.createSequentialGroup();
    layout.setVerticalGroup(sgv);
    ParallelGroup pgh = layout.createParallelGroup();
    layout.setHorizontalGroup(pgh);
    //
    // the graph with the focus and the memory
    //
    XYSeriesCollection xysFM = new XYSeriesCollection();
    xysFM.addSeries(xysc.getSeries("ChoiceScoreIndependent"));
    xysFM.addSeries(xysc.getSeries("ChoiceScoreDependent"));
    xysFM.addSeries(xysc.getSeries("ChoiceScoreMood"));
    JFreeChart chart = ChartFactory.createXYLineChart(label + " - Choice", "Time", "Value", xysFM,
            PlotOrientation.VERTICAL, true, false, false);
    GraphEvolution.setChartProperties(chart, GraphEvolution.lineStylesColorful);
    ChartPanel cp = new ChartPanel(chart);
    sgv.addComponent(cp);
    pgh.addComponent(cp);
    JFrame frame = new JFrame();
    frame.add(panel);
    frame.pack();
    frame.setVisible(true);
}

From source file:net.sf.jdmf.visualization.clustering.ChartGenerator.java

public JFreeChart generateXYChart(List<Cluster> clusters, Integer firstAttributeIndex,
        String firstAttributeName, Integer secondAttributeIndex, String secondAttributeName) {
    XYSeriesCollection dataset = new XYSeriesCollection();

    for (Cluster cluster : clusters) {
        XYSeries series = new XYSeries(cluster.getName());

        for (Vector<Double> point : cluster.getPoints()) {
            series.add(point.get(firstAttributeIndex), point.get(secondAttributeIndex));
        }//from w  ww  .ja v a  2 s . co m

        dataset.addSeries(series);
    }

    XYToolTipGenerator xyToolTipGenerator = new XYToolTipGenerator() {
        public String generateToolTip(XYDataset dataset, int series, int item) {
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append(String.format("<html><p style='color:#0000ff;'>Series: '%s'</p>",
                    dataset.getSeriesKey(series)));
            Cluster cl = clusters.get(series);
            Vector<Double> point = cl.getPoints().get(item);
            for (int i = 0; i < point.size(); i++) {
                //stringBuilder.append(String.format("Attr:'%d'<br/>", d));
                try {
                    String attr = _attrName.get(i);
                    stringBuilder.append(attr + " " + point.get(i) + "<br/>");
                } catch (Exception e) {
                    // Do nothing 
                }
            }
            stringBuilder.append("</html>");
            return stringBuilder.toString();
        }
    };

    /***
    return ChartFactory.createScatterPlot( "Cluster Analysis", 
    firstAttributeName, secondAttributeName, dataset, 
    PlotOrientation.VERTICAL, true, true, false );
    ***/
    JFreeChart jfc = ChartFactory.createScatterPlot("Cluster Analysis", firstAttributeName, secondAttributeName,
            dataset, PlotOrientation.VERTICAL, true, true, false);

    XYItemRenderer render = jfc.getXYPlot().getRenderer();
    render.setBaseToolTipGenerator(xyToolTipGenerator);
    return jfc;
}

From source file:umontreal.iro.lecuyer.charts.YListSeriesCollection.java

private void initYListSeries(boolean flag, double[]... data) {
    // if flag = true, h = 1; else h = 1/numPoints
    double h;// w  ww.  ja va2 s.com
    renderer = new XYLineAndShapeRenderer(true, false);
    seriesCollection = new XYSeriesCollection();

    XYSeriesCollection tempSeriesCollection = (XYSeriesCollection) seriesCollection;
    for (int i = 0; i < data.length; i++) {
        XYSeries serie = new XYSeries(" ");
        if (flag)
            h = 1;
        else
            h = 1.0 / data[i].length;
        for (int j = 0; j < data[i].length; j++)
            serie.add(h * (j + 1), data[i][j]);
        tempSeriesCollection.addSeries(serie);
    }

    final int s = tempSeriesCollection.getSeriesCount();

    // set default colors
    for (int i = 0; i < s; i++) {
        renderer.setSeriesPaint(i, getDefaultColor(i));
    }

    // set default plot style
    plotStyle = new String[s];
    marksType = new String[s];
    dashPattern = new String[s];
    for (int i = 0; i < s; i++) {
        marksType[i] = " ";
        plotStyle[i] = "smooth";
        dashPattern[i] = "solid";
    }
    //   dashPattern[s-1] = "dashed";     // for the line y = x
}

From source file:simphy.XYChart.java

public XYChart(Circle c) {
    this.c = c;/*from   ww  w  .  ja v  a 2 s .  c  o m*/
    // Create a simple XY chart
    type = "circle";
    series = new XYSeries("VT Plot");
    dataset = new XYSeriesCollection();
    dataset.addSeries(series);
    // Generate the graph
    chart = ChartFactory.createXYLineChart("Velocity-Time Graph", // Title
            "time(s)", // x-axis Label
            "velocity(m/s)", // y-axis Label
            dataset, // Dataset
            PlotOrientation.VERTICAL, // Plot Orientation
            true, // Show Legend
            true, // Use tooltips
            false // Configure chart to generate URLs?
    );
    this.setTitle(c.getID());
    this.setBounds(950, 0, 400, 700);
    panel = new ChartPanel(chart, false);
    this.add(panel, BorderLayout.CENTER);
    this.setAlwaysOnTop(true);
    this.addWindowListener(this);
    this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    this.pack();

    SwingUtilities.invokeLater(() -> {
        XYChart.this.setVisible(true);
    });

}

From source file:net.sf.mzmine.modules.peaklistmethods.peakpicking.adap3decompositionV1_5.EICPlot.java

public EICPlot(List<List<NavigableMap<Double, Double>>> clusters, List<Double> colors, List<List<String>> info,
        List<NavigableMap<Double, Double>> modelPeaks) {
    super(null, true);

    setBackground(Color.white);/*from ww  w  .  j  a  v a 2s .  com*/
    setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));

    NumberAxis xAxis = new NumberAxis("Retention Time");
    xAxis.setAutoRangeIncludesZero(false);
    xAxis.setUpperMargin(0);
    xAxis.setLowerMargin(0);

    NumberAxis yAxis = new NumberAxis("Intensity");
    yAxis.setAutoRangeIncludesZero(false);
    yAxis.setUpperMargin(0);
    yAxis.setLowerMargin(0);

    xyDataset = new XYSeriesCollection();
    colorDataset = new ArrayList<>();
    toolTips = new ArrayList<>();

    int seriesID = 0;

    for (int i = 0; i < clusters.size(); ++i) {
        List<NavigableMap<Double, Double>> cluster = clusters.get(i);
        double color = colors.get(i);

        for (int j = 0; j < cluster.size(); ++j) {
            XYSeries series = new XYSeries(seriesID++);

            for (Entry<Double, Double> e : cluster.get(j).entrySet())
                series.add(e.getKey(), e.getValue());

            xyDataset.addSeries(series);
            colorDataset.add(color);
            toolTips.add(info.get(i).get(j));
        }
    }

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer() {
        @Override
        public Paint getItemPaint(int row, int col) {
            double c = colorDataset.get(row);
            return Color.getHSBColor((float) c, 1.0f, 1.0f);
        }
    };

    renderer.setDefaultShapesVisible(false);
    renderer.setDefaultToolTipGenerator(new XYToolTipGenerator() {
        @Override
        public String generateToolTip(XYDataset dataset, int series, int item) {
            try {
                return toolTips.get(series);
            } catch (NullPointerException | IndexOutOfBoundsException e) {
                return "";
            }
        }
    });

    XYPlot plot = new XYPlot(xyDataset, xAxis, yAxis, renderer);
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinesVisible(true);

    JFreeChart chart = new JFreeChart("", new Font("SansSerif", Font.BOLD, 12), plot, false);
    chart.setBackgroundPaint(Color.white);

    super.setChart(chart);
}

From source file:physical_network.OscilloscopePanel.java

public OscilloscopePanel() {

    super("Oscilloscope");

    // Set initial (time, voltage) datapoint of (0.0, 0.0).
    voltages.add(0.0, 0.0);/*from   w  w w .j a va  2 s  .c o m*/

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

    JFreeChart chart = ChartFactory.createXYLineChart("Oscilloscope", "Time (seconds)", "Voltage", dataset,
            PlotOrientation.VERTICAL, true, false, false);

    XYPlot plot = (XYPlot) chart.getPlot();

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0, true);

    NumberAxis domain = (NumberAxis) plot.getDomainAxis();
    domain.setRange(0.0, 10.0);
    domain.setTickUnit(new NumberTickUnit(1.0));
    domain.setVerticalTickLabels(true);

    NumberAxis range = (NumberAxis) plot.getRangeAxis();
    range.setRange(-5.0, 5.0);
    range.setTickUnit(new NumberTickUnit(1.0));

    plot.setRenderer(renderer);

    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 300));

    setContentPane(chartPanel);
}

From source file:org.physionet.graphics.Plot.java

public static XYDataset createDataset(ArrayList[] data) {
    //XYDataset result = DatasetUtilities.sampleFunction2D(new X2(),
    //        -4.0, 4.0, 40, "f(x)");
    XYSeriesCollection result = new XYSeriesCollection();
    XYSeries series = new XYSeries(1);
    //Insert data into plotting series 
    for (int n = 0; n < data[1].size(); n++) {
        series.add(Double.valueOf((String) data[0].get(n)), Double.valueOf((String) data[1].get(n)));
    }/*  ww w . j  a  v  a2  s .c o m*/
    result.addSeries(series);
    return result;
}

From source file:org.usfirst.frc.team2084.neuralnetwork.RobotHeadingTest.java

/**
 * /*  w  w  w  .j a v  a 2  s .  c  o  m*/
 */
@Override
public void run() {
    try {
        final DefaultValueDataset headingData = new DefaultValueDataset(0);
        final DefaultValueDataset desiredHeadingData = new DefaultValueDataset(0);
        final CompassPlot headingPlot = new CompassPlot();
        headingPlot.addDataset(headingData);
        headingPlot.addDataset(desiredHeadingData);
        final JFreeChart headingChart = new JFreeChart("Heading", headingPlot);

        final XYSeries headingTimeSeries = new XYSeries("Heading");
        final XYSeriesCollection headingTimeData = new XYSeriesCollection();
        headingTimeData.addSeries(headingTimeSeries);
        final JFreeChart headingTimeChart = ChartFactory.createXYLineChart("Heading vs. Time", "Time",
                "Heading", headingTimeData, PlotOrientation.VERTICAL, true, true, false);

        final XYSeries errorTimeSeries = new XYSeries("Error");
        final XYSeriesCollection errorTimeData = new XYSeriesCollection();
        errorTimeData.addSeries(errorTimeSeries);
        final JFreeChart errorTimeChart = ChartFactory.createXYLineChart("Error vs. Time", "Time", "Error",
                errorTimeData, PlotOrientation.VERTICAL, true, true, false);

        SwingUtilities.invokeAndWait(() -> {
            final JFrame frame = new JFrame("Charts");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            final Container content = frame.getContentPane();
            content.setLayout(new BoxLayout(content, BoxLayout.PAGE_AXIS));

            final JPanel chartPanel = new JPanel();
            chartPanel.setLayout(new GridLayout(2, 2));
            content.add(chartPanel);

            final ChartPanel headingPanel = new ChartPanel(headingChart);
            chartPanel.add(headingPanel);

            final ChartPanel headingTimePanel = new ChartPanel(headingTimeChart);
            chartPanel.add(headingTimePanel);

            final ChartPanel errorTimePanel = new ChartPanel(errorTimeChart);
            chartPanel.add(errorTimePanel);

            final JPanel buttonPanel = new JPanel();
            content.add(buttonPanel);

            final JButton startButton = new JButton("Start");
            final JButton stopButton = new JButton("Stop");

            startButton.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    stop();
                    startButton.setEnabled(false);
                    stopButton.setEnabled(true);
                    start(headingData, desiredHeadingData, headingTimeSeries, errorTimeSeries);
                }
            });
            buttonPanel.add(startButton);

            stopButton.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    stop();
                    startButton.setEnabled(true);
                    stopButton.setEnabled(false);
                }
            });
            stopButton.setEnabled(false);
            buttonPanel.add(stopButton);

            frame.pack();
            frame.setVisible(true);
        });
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:de.fhffm.jad.demo.view.LineChartPanel.java

/**
 * Creates a sample dataset./*from  ww w . j  a v a 2  s .  co m*/
 * 
 * @return a sample dataset.
 */
private XYDataset createDataset() {

    series1 = new XYSeries("IP.Src Entrophy");
    series1.add(1.0, 0);
    series1.add(2.0, 0);
    series1.add(3.0, 0);
    series1.add(4.0, 0);
    series1.add(5.0, 0);
    series1.add(6.0, 0);
    series1.add(7.0, 0);
    series1.add(8.0, 0);

    series2 = new XYSeries("TCP.Dst.Port Entrophy");
    series2.add(1.0, 1);
    series2.add(2.0, 1);
    series2.add(3.0, 1);
    series2.add(4.0, 1);
    series2.add(5.0, 1);
    series2.add(6.0, 1);
    series2.add(7.0, 1);
    series2.add(8.0, 1);

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