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:PlotsBuilding.PlotPanel.java

private JFreeChart fillCollection(ArrayList<PlotsData> plotscollection) {
    XYSeriesCollection col = new XYSeriesCollection();
    ArrayList<Integer> seriesCount = new ArrayList<>();
    int SeriesCount = 0;
    PlotsData plotdata = new PlotsData();
    if (plotscollection.isEmpty()) {
        XYSeries series = new XYSeries("1. ");
        series.add(0, 0);/*from  w  w w.  j a v  a 2 s  .co  m*/
        plotdata.y1 = -10;
        plotdata.y2 = 10;
        col.addSeries(series);
    }
    for (int i = 0; i < plotscollection.size(); i++) {
        plotdata = (PlotsData) plotscollection.get(i);
        col = plotdata.createPlotdataset(i, col);
        seriesCount.add(col.getSeriesCount() - SeriesCount);
        SeriesCount = col.getSeriesCount();
    }
    double y1 = plotdata.y1;
    double y2 = plotdata.y2;
    JFreeChart chart = createChart(col, seriesCount, y1, y2);
    return chart;
}

From source file:edu.ucla.stat.SOCR.chart.SuperIndexChart.java

/**
  * /*from  w w w . j a  v  a  2s.c o m*/
  * @param isDemo data come from demo(true) or dataTable(false)
  * @return
  */
protected XYDataset createDataset(boolean isDemo) {
    if (isDemo) {
        updateStatus("isDemo==true in " + this.getClass().getName()
                + " class! return null Dataset, check the code!");
        return null;
    } else {

        //System.out.println("createDatase false get callled");
        setArrayFromTable();

        double[] raw_xvalue;

        row_count = xyLength;
        //System.out.println("row_count="+row_count);
        raw_x = new String[row_count];
        raw_xvalue = new double[row_count];

        row_count = 0;
        for (int index = 0; index < independentVarLength; index++)
            for (int i = 0; i < xyLength; i++) {
                raw_x[i] = indepValues[i][index];
                //System.out.println("raw_x="+raw_x[i]);
                try {
                    if (raw_x[i] != null && raw_x[i].length() != 0) {
                        raw_xvalue[row_count] = Double.parseDouble(raw_x[i]);
                        row_count++;
                    }
                } catch (Exception e) {
                    System.out.println("wrong data " + raw_x[i]);
                }
            }

        //if(rangeLabel==null || rangeLabel.length()==0)
        rangeLabel = independentHeaders[0];

        double[] y_freq = new double[row_count];

        for (int i = 0; i < row_count; i++) {
            y_freq[i] = i + 1;
        }

        XYSeriesCollection dataset = new XYSeriesCollection();
        XYSeries series1 = new XYSeries(rangeLabel);
        for (int i = 0; i < row_count; i++)
            series1.add(y_freq[i], raw_xvalue[i]);
        dataset.addSeries(series1);

        return dataset;
    }
}

From source file:eremeykin.pete.plotter.PolarPlotterTopComponent.java

public PolarPlotterTopComponent() {
    initComponents();/*from  w  ww .  j  a  v  a  2  s.  c o  m*/
    setName(Bundle.CTL_PolarPlotterTopComponent());
    setToolTipText(Bundle.HINT_PolarPlotterTopComponent());
    final XYSeriesCollection dataset = new XYSeriesCollection();

    final XYSeries toleranceSeries = new XYSeries("Tolerance");
    final XYSeries dataSeries = new XYSeries("U");

    dataset.addSeries(dataSeries);
    dataset.addSeries(toleranceSeries);
    final JFreeChart chart = createChart(dataset);
    chartPanel = new ChartPanel(chart);
    jPanel1.setLayout(new java.awt.BorderLayout());
    jPanel1.add(chartPanel, BorderLayout.CENTER);
    validate();

}

From source file:be.ugent.maf.cellmissy.gui.controller.analysis.doseresponse.DoseResponseController.java

/**
 * Create a dose-response chart containing experimental data, simulated data
 * and an annotated R value.//from   www  .  ja  va  2 s  .c o  m
 *
 * @param dataToPlot The experimental data on which the fit was performed
 * @param analysisGroup The analysis group
 * @param normalized Whether the responses are normalized
 * @return
 */
public JFreeChart createDoseResponseChart(List<DoseResponsePair> dataToPlot,
        DoseResponseAnalysisGroup analysisGroup, boolean normalized) {
    // setup scatter data of experimental concentrations/slopes, renderer and axis
    XYSeriesCollection experimentalData = new XYSeriesCollection();
    XYSeries scatterXYSeries = JFreeChartUtils.generateXYSeries(AnalysisUtils.generateXValues(dataToPlot),
            AnalysisUtils.generateYValues(dataToPlot));
    scatterXYSeries.setKey("Experimental data");
    experimentalData.addSeries(scatterXYSeries);

    // compute how far the simulated data and axes should range: from the lowest and highest dose continue half of the range between these two
    List<Double> extremes = new ArrayList<>();
    Double range = Math.abs(scatterXYSeries.getMaxX() - scatterXYSeries.getMinX());
    extremes.add(scatterXYSeries.getMinX() - (range / 2));
    extremes.add(scatterXYSeries.getMaxX() + (range / 2));

    // Create the simulated line data, renderer, and axis
    XYSeriesCollection fitting = new XYSeriesCollection();
    // create xy series of simulated data from the parameters from the fitting
    SigmoidFittingResultsHolder resultsHolder = analysisGroup.getDoseResponseAnalysisResults()
            .getFittingResults(normalized);
    XYSeries fittingData = simulateData(resultsHolder, extremes);
    fittingData.setKey("Fitting");
    fitting.addSeries(fittingData);

    XYPlot plot = JFreeChartUtils.setupDoseResponseDatasets(experimentalData, fitting,
            getPlotAxesNames(normalized), extremes);

    // show the r squared value, put the value at a certain place between the min and max dose
    double xPlace = extremes.get(1) - range;
    double yPlace = scatterXYSeries.getMinY() + ((scatterXYSeries.getMaxY() - scatterXYSeries.getMinY()) / 4);
    plot.addAnnotation(new XYTextAnnotation(
            "R2=" + AnalysisUtils.roundThreeDecimals(AnalysisUtils.computeRSquared(dataToPlot, resultsHolder)),
            xPlace, yPlace));

    // Create the chart with the plot and no legend
    JFreeChart chart = new JFreeChart("Title", JFreeChart.DEFAULT_TITLE_FONT, plot, false);
    String title = "";
    if (normalized) {
        title = "Normalized fitting";
    } else {
        title = "Initial fitting";
    }
    JFreeChartUtils.setupDoseResponseChart(chart, title);
    return chart;
}

From source file:charts.Chart.java

public static void PontosXY() {

    XYSeries series2 = new XYSeries("Max Value");
    series2.add(30.0, 15.0);/*  w ww. ja va2s  . c  om*/
    series2.add(20.0, 30.0);
    series2.add(10.0, 75.0);
    series2.add(40.0, 23.0);
    series2.add(5.0, 50.0);
    series2.add(25.0, 45.0);

    XYSeries series3 = new XYSeries("Min Value");
    series3.add(10.0, 15.0);

    XYSeriesCollection series = new XYSeriesCollection();
    series.addSeries(series2);
    series.addSeries(series3);

    JFreeChart jfreechart = ChartFactory.createScatterPlot("Sample XY Chart", // Title
            "Height", // X-Axis label
            "Weight", // Y-Axis label
            series, // Dataset
            PlotOrientation.VERTICAL, true, // Show legend
            false, false);
    JFrame janela = new JFrame("Example of the XY series graphic");
    JPanel jpanel = new ChartPanel(jfreechart);
    jpanel.setPreferredSize(new Dimension(defaultwidth, defaultheight));
    janela.setContentPane(jpanel);
    janela.pack();
    RefineryUtilities.centerFrameOnScreen(janela);
    janela.setVisible(true);
}

From source file:gov.nih.nci.caintegrator.plots.kaplanmeier.JFreeChartIKMPlottermpl.java

public JFreeChart createKMPlot(Collection<GroupCoordinates> groupsToBePlotted, String title, String xAxisLabel,
        String yAxisLabel) {/*from   ww  w . j av a  2 s .c om*/
    List<KMPlotPointSeriesSet> kmPlotSets = new ArrayList<KMPlotPointSeriesSet>(
            convertToKaplanMeierPlotPointSeriesSet(groupsToBePlotted));

    XYSeriesCollection finalDataCollection = new XYSeriesCollection();
    /*  Repackage all the datasets to go into the XYSeriesCollection */
    for (KMPlotPointSeriesSet dataSet : kmPlotSets) {
        finalDataCollection.addSeries(dataSet.getCensorPlotPoints());
        finalDataCollection.addSeries(dataSet.getProbabilityPlotPoints());

    }

    JFreeChart chart = ChartFactory.createXYLineChart("", xAxisLabel, yAxisLabel, finalDataCollection,
            PlotOrientation.VERTICAL, true, //legend
            true, //tooltips
            false//urls
    );
    XYPlot plot = (XYPlot) chart.getPlot();
    /*
     * Ideally the actual Renderer settings should have been created
     * at the survivalLength of iterating KaplanMeierPlotPointSeriesSets, adding them to the actual
     * Data Set that is going to be going into the Chart plotter.  But you have no idea how
     * they are going to be sitting in the Plot dataset so there is no guarantee that setting the
     * renderer based on a supposed index will actually work. In fact
     */

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    for (int i = 0; i < finalDataCollection.getSeriesCount(); i++) {
        KMPlotPointSeries kmSeries = (KMPlotPointSeries) finalDataCollection.getSeries(i);

        if (kmSeries.getType() == KMPlotPointSeries.SeriesType.CENSOR) {
            renderer.setSeriesLinesVisible(i, false);
            renderer.setSeriesShapesVisible(i, true);
            renderer.setSeriesShape(i, getCensorShape());
        } else if (kmSeries.getType() == KMPlotPointSeries.SeriesType.PROBABILITY) {
            renderer.setSeriesLinesVisible(i, true);
            renderer.setSeriesShapesVisible(i, false);

        } else {
            //don't show this set as it is not a known type
            renderer.setSeriesLinesVisible(i, false);
            renderer.setSeriesShapesVisible(i, false);
        }
        renderer.setSeriesPaint(i, getKMSetColor(kmPlotSets, kmSeries.getKey(), kmSeries.getType()), true);
    }

    renderer.setToolTipGenerator(new StandardXYToolTipGenerator());
    renderer.setDefaultEntityRadius(6);
    plot.setRenderer(renderer);

    /* change the auto tick unit selection to integer units only... */
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits());

    /* OPTIONAL CUSTOMISATION COMPLETED. */
    rangeAxis.setAutoRange(true);
    rangeAxis.setRange(0.0, 1.0);

    /* set Title and Legend */
    chart.setTitle(title);
    createLegend(chart, kmPlotSets);

    return chart;
}

From source file:edu.umich.eecs.tac.viewer.role.advertiser.CampaignGrpahsPanel.java

private void createGraph(XYSeries reachSeries) {
    XYSeriesCollection seriescollection = new XYSeriesCollection(reachSeries);

    maxSeries = new XYSeries("Total");
    for (int i = 1; i <= 1000; i++) {
        double err = calcEffectiveReachRatio(expectedImpressionReach * i / 1000, expectedImpressionReach);
        maxSeries.add(expectedImpressionReach * i / 1000, err);
    }/* www.  ja  v  a 2 s  .c  om*/

    seriescollection.addSeries(maxSeries);
    JFreeChart chart = createDifferenceChart(advertiserBorder ? null : advertiser, seriescollection,
            "Reach Count", "Reach percentage");
    ChartPanel chartpanel = new ChartPanel(chart, false);
    chartpanel.setMouseZoomable(true, false);
    add(chartpanel);
    this.repaint();
}

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

/**
* Creates a sample dataset.//from  www  .  ja va 2  s .  com
* 
* @return a sample dataset.
*/
protected XYDataset createDataset1(boolean isDemo) {
    if (isDemo) {

        row_count = 20;
        raw_x = new String[row_count];
        raw_x[0] = "3.0";
        raw_x[1] = "-2.0";
        raw_x[2] = "4.0";
        raw_x[3] = "4.0";
        raw_x[4] = "5.0";
        raw_x[5] = "6.0";
        raw_x[6] = "6.0";
        raw_x[7] = "7.0";
        raw_x[8] = "1.0";
        raw_x[9] = "1.0";
        raw_x[10] = "1.0";
        raw_x[11] = "2.0";
        raw_x[12] = "3.0";
        raw_x[13] = "4.0";
        raw_x[14] = "3.0";
        raw_x[15] = "4.0";
        raw_x[16] = "3.0";
        raw_x[17] = "10.0";
        raw_x[18] = "7.0";
        raw_x[19] = "6.0";

        XYSeries series1 = new XYSeries("Data");
        series1.add(0.1, 3.0);
        series1.add(0.1, -2.0);
        series1.add(0.1, 4.0);
        series1.add(0.2, 4.0);
        series1.add(0.1, 5.0);
        series1.add(0.1, 6.0);
        series1.add(0.2, 6.0);
        series1.add(0.1, 7.0);
        series1.add(0.1, 1.0);
        series1.add(0.2, 1.0);
        series1.add(0.3, 1.0);
        series1.add(0.1, 2.0);
        series1.add(0.2, 3.0);
        series1.add(0.3, 4.0);
        series1.add(0.3, 3.0);
        series1.add(0.4, 4.0);
        series1.add(0.4, 3.0);
        series1.add(0.1, 10.0);
        series1.add(0.2, 7.0);
        series1.add(0.3, 6.0);

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

        return dataset;
    } else
        return super.createDataset1(false);

}

From source file:web.diva.server.model.LineChartGenerator.java

/**
 *
 * @return dataset.//from w  ww .  ja va2 s . c  o m
 */
private XYDataset createDataset(Number[][] pointsData, String[] geneNames, int[] selection) {

    final XYSeriesCollection dataset = new XYSeriesCollection();
    if (selection == null) {
        for (int x = 0; x < pointsData.length; x++) {
            XYSeries series = new XYSeries(geneNames[x] + x);
            Number[] data = pointsData[x];
            for (int y = 0; y < data.length; y++) {
                series.add(y, data[y]);
            }
            dataset.addSeries(series);

        }
    } else {

        for (int x = 0; x < selection.length; x++) {
            XYSeries series = new XYSeries(geneNames[selection[x]]);
            Number[] data = pointsData[selection[x]];
            for (int y = 0; y < data.length; y++) {
                series.add(y, data[y]);
            }
            dataset.addSeries(series);

        }

    }

    return dataset;

}