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:com.kurvlrgui.gui.ChartPanel.java

/**
 * Creates new form ChartPanel//from  www.  j a  v  a2  s. c  om
 */
public ChartPanel(String title, NumericData s1, NumericData s2) {
    initComponents();

    calculated = new XYSeries("Calculated");
    for (NumericPair np : s1.values) {
        calculated.add(np.x, np.y);
    }

    observed = null;
    if (s2 != null) {
        observed = new XYSeries("Observed");
        for (NumericPair np : s2.values) {
            observed.add(np.x, np.y);
        }
    }

    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(calculated);
    if (s2 != null)
        dataset.addSeries(observed);

    JFreeChart chart = ChartFactory.createXYLineChart(title, "X", "Y", dataset, PlotOrientation.VERTICAL, true,
            true, false);
    chart.setBackgroundPaint(Color.white);

    XYPlot plot = chart.getXYPlot();

    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesLinesVisible(1, false);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    panel = new org.jfree.chart.ChartPanel(chart);

    panel.setHorizontalAxisTrace(true);
    panel.setVerticalAxisTrace(true);

    this.add(panel);
}

From source file:org.graphstream.algorithm.measure.ChartSeriesMeasure.java

public JFreeChart createChart(PlotParameters params) throws PlotException {
    JFreeChart chart;/*from  w  w w  . jav  a  2  s. c o  m*/
    XYSeriesCollection dataset = new XYSeriesCollection();

    dataset.addSeries(getXYSeries());

    switch (params.type) {
    case LINE:
        chart = ChartFactory.createXYLineChart(params.title, params.xAxisLabel, params.yAxisLabel, dataset,
                params.orientation, params.showLegend, false, false);
        break;
    case BAR:
        chart = ChartFactory.createXYBarChart(params.title, params.xAxisLabel, false, params.yAxisLabel,
                dataset, params.orientation, params.showLegend, false, false);
        break;
    case SCATTER:
        chart = ChartFactory.createScatterPlot(params.title, params.xAxisLabel, params.yAxisLabel, dataset,
                params.orientation, params.showLegend, false, false);
        break;
    default:
        throw new PlotException("unsupported plot type");
    }

    return chart;
}

From source file:mes2.Chart.java

public void createwykres() {
    XYSeriesCollection xySeriesCollection = new XYSeriesCollection(dataSet);
    // Dodanie kolejnych serii do kolekcji:
    xySeriesCollection.addSeries(dataSet2);

    // tworzenie XYDataSet 
    XYDataset xyDataset = xySeriesCollection;
    // tworzenie wykresu 
    JFreeChart lineGraph = ChartFactory.createXYLineChart("Wykres nagrzewania wsadu", // Title 
            "Czas", // X-Axis label 
            "Temperatura", // Y-Axis label 
            xyDataset, // Dataset 
            PlotOrientation.VERTICAL, //Plot orientation 
            true, //show legend 
            true, // Show tooltips 
            false //url show 
    );//from  w w w . ja v a 2 s. co m
    ChartFrame frame1 = new ChartFrame("Szybkie wyswietlanie wykresu - klasa ChartFrame", lineGraph);
    frame1.pack();
    frame1.setVisible(true);
    frame1.setLocationRelativeTo(null);
    //frame1.setDefaultCloseOperation(DISPOSE_ON_CLOSE);

    ChartPanel chartPanel = new ChartPanel(lineGraph);
    //frame.getContentPane().add(chartPanel);
    // frame.getContentPane().add(new JLabel("<<< wykres dodany jako ChartPanel"));

}

From source file:edu.ucla.stat.SOCR.chart.demo.XYStepRendererDemo1.java

/**
 * Creates a sample dataset./*from   w  w w . j  av  a  2  s  .com*/
 * 
 * @return A dataset.
 */
protected XYDataset createDataset(boolean isDemo) {
    if (isDemo) {
        XYSeries series1 = new XYSeries("Series 1");
        series1.add(1.0, 3.0);
        series1.add(2.0, 4.0);
        series1.add(3.0, 2.0);
        //series1.add(5.0, 6.0);
        series1.add(6.0, 3.0);
        XYSeries series2 = new XYSeries("Series 2");
        series2.add(1.0, 7.0);
        series2.add(2.0, 6.0);
        series2.add(3.0, 9.0);
        series2.add(4.0, 5.0);
        series2.add(6.0, 4.0);
        XYSeriesCollection dataset = new XYSeriesCollection();
        dataset.addSeries(series1);
        dataset.addSeries(series2);
        return dataset;
    } else
        return super.createDataset(false);
}

From source file:br.com.ant.system.util.ChartUtil.java

public void createTempoTotalExecucao(Set<EstatisticaColetor> estatisticas) {

    // Create a simple XY chart
    XYSeries series = new XYSeries("Formiga");

    JFrame frame = new JFrame();

    for (EstatisticaColetor e : estatisticas) {
        series.add(e.getId(), e.getTempoExecucao());
    }//  w  w w.  j a  v a  2s .co m

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

    // Generate the graph
    JFreeChart chart = ChartFactory.createXYLineChart("Tempo total de Execuo", "Execuo", "Tempo (ms)",
            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.jfree.chart.demo.XYAreaChartDemo.java

/**
 * Creates a new demo.//from  w w  w .  j av  a  2s  .c o m
 *
 * @param title  the frame title.
 */
public XYAreaChartDemo(final String title) {

    super(title);

    final XYSeries series1 = new XYSeries("Random 1");
    series1.add(new Integer(1), new Double(500.2));
    series1.add(new Integer(2), new Double(694.1));
    series1.add(new Integer(3), new Double(-734.4));
    series1.add(new Integer(4), new Double(453.2));
    series1.add(new Integer(5), new Double(500.2));
    series1.add(new Integer(6), new Double(300.7));
    series1.add(new Integer(7), new Double(734.4));
    series1.add(new Integer(8), new Double(453.2));

    final XYSeries series2 = new XYSeries("Random 2");
    series2.add(new Integer(1), new Double(700.2));
    series2.add(new Integer(2), new Double(534.1));
    series2.add(new Integer(3), new Double(323.4));
    series2.add(new Integer(4), new Double(125.2));
    series2.add(new Integer(5), new Double(653.2));
    series2.add(new Integer(6), new Double(432.7));
    series2.add(new Integer(7), new Double(564.4));
    series2.add(new Integer(8), new Double(322.2));

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

    final JFreeChart chart = createChart(dataset);

    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(chartPanel);

}

From source file:org.uncommons.maths.demo.GraphPanel.java

public void generateGraph(String title, Map<Double, Double> observedValues, Map<Double, Double> expectedValues,
        double expectedMean, double expectedStandardDeviation, boolean discrete) {
    XYSeriesCollection dataSet = new XYSeriesCollection();
    XYSeries observedSeries = new XYSeries("Observed");
    dataSet.addSeries(observedSeries);
    XYSeries expectedSeries = new XYSeries("Expected");
    dataSet.addSeries(expectedSeries);//from   w  w w  .ja  v  a 2  s .c om

    for (Map.Entry<Double, Double> entry : observedValues.entrySet()) {
        observedSeries.add(entry.getKey(), entry.getValue());
    }

    for (Map.Entry<Double, Double> entry : expectedValues.entrySet()) {
        expectedSeries.add(entry.getKey(), entry.getValue());
    }

    JFreeChart chart = ChartFactory.createXYLineChart(title, "Value", "Probability", dataSet,
            PlotOrientation.VERTICAL, true, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    if (discrete) {
        // Render markers at each data point (these discrete points are the
        // distibution, not the lines between them).
        plot.setRenderer(new XYLineAndShapeRenderer());
    } else {
        // Render smooth lines between points for a continuous distribution.
        XYSplineRenderer renderer = new XYSplineRenderer();
        renderer.setBaseShapesVisible(false);
        plot.setRenderer(renderer);
    }

    chartPanel.setChart(chart);
}

From source file:com.seniorproject.augmentedreality.chart.ChartCreator.java

protected XYDataset createDataset() {
    //        System.out.println("Create Dataset of" + textX);
    final XYSeries seriesR = new XYSeries(title[1]);
    final XYSeries seriesG = new XYSeries(title[2]);
    final XYSeries seriesB = new XYSeries(title[3]);
    Integer countPixel[] = new Integer[256];
    for (int i = 0; i < 256; i++) {
        countPixel[i] = 0;//from  w  w  w.ja va 2 s  .  co m
        for (int j = 0; j < this.pixelR.length; j++) {
            if (this.pixelR[j] == i) {
                countPixel[i]++;
            }

        }
        seriesR.add(i, countPixel[i] / (this.pixelR.length * 1.0d));
    }
    for (int i = 0; i < 256; i++) {
        countPixel[i] = 0;
        for (int j = 0; j < this.pixelG.length; j++) {
            if (this.pixelG[j] == i) {
                countPixel[i]++;
            }
        }
        seriesG.add(i, countPixel[i] / (this.pixelG.length * 1.0d));
    }
    for (int i = 0; i < 256; i++) {
        countPixel[i] = 0;
        for (int j = 0; j < this.pixelB.length; j++) {
            if (this.pixelB[j] == i) {
                countPixel[i]++;
            }
        }
        seriesB.add(i, countPixel[i] / (this.pixelB.length * 1.0d));
    }
    final XYSeriesCollection dataSeries = new XYSeriesCollection();
    dataSeries.addSeries(seriesR);
    dataSeries.addSeries(seriesB);
    dataSeries.addSeries(seriesG);

    return dataSeries;
}

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

/**
 * Creates a new demo.//from  w ww . ja  va 2  s  .  c  om
 *
 * @param title  the frame title.
 */
public XYAreaChartTest(final String title) {

    super(title);

    final XYSeries series1 = new XYSeries("Random 1");
    series1.add(new Integer(1), new Double(500.2));
    series1.add(new Integer(2), new Double(694.1));
    series1.add(new Integer(3), new Double(-734.4));
    series1.add(new Integer(4), new Double(453.2));
    series1.add(new Integer(5), new Double(500.2));
    series1.add(new Integer(6), new Double(300.7));
    series1.add(new Integer(7), new Double(734.4));
    series1.add(new Integer(8), new Double(453.2));

    final XYSeries series2 = new XYSeries("Random 2");
    series2.add(new Integer(1), new Double(700.2));
    series2.add(new Integer(2), new Double(534.1));
    series2.add(new Integer(3), new Double(323.4));
    series2.add(new Integer(4), new Double(125.2));
    series2.add(new Integer(5), new Double(653.2));
    series2.add(new Integer(6), new Double(432.7));
    series2.add(new Integer(7), new Double(564.4));
    series2.add(new Integer(8), new Double(322.2));

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

    final JFreeChart chart = createChart(dataset);

    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(chartPanel);

}

From source file:org.ow2.clif.jenkins.chart.CallChart.java

@Override
protected JFreeChart createChart() {
    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(this.eventSerie);

    JFreeChart chart;//from  w  w w  . j  a va 2  s .  c  om
    if (this.scatterPlot) {
        chart = ChartFactory.createScatterPlot(getBasicTitle(),
                // chart title
                Messages.CallChart_Time(), // x axis label
                Messages.CallChart_ResponseTime(), // y axis label
                dataset, // data
                PlotOrientation.VERTICAL, true, // include legend
                true, // tooltips
                false // urls
        );
    } else {
        chart = ChartFactory.createXYLineChart(getBasicTitle(),
                // chart title
                Messages.CallChart_Time(), // x axis label
                this.chartId.getEvent(), // y axis label
                dataset, // data
                PlotOrientation.VERTICAL, false, // include legend
                true, // tooltips
                false // urls
        );
    }

    chart.setBackgroundPaint(Color.white);
    // get a reference to the plot for further customisation...
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    Shape cross = ShapeUtilities.createDiamond(3);

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setBaseShape(cross);
    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesShape(0, cross);
    plot.setRenderer(renderer);

    // Force the 0 on vertical axis
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setAutoRangeIncludesZero(true);
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // Force the 0 on horizontal axis
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setAutoRangeIncludesZero(true);
    return chart;
}