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:projects.upc.exec.HrDiagram.java

/**
 * Update the {@link HrDiagram#chartPanel}.
 *//*from   ww  w  . j  a  v  a2s  .co  m*/
private void updateChart() {

    XYSeries series = new XYSeries("UPC HR diagram");

    for (Entry<UpcStar, SsaCrossMatch> xm : starsToPlot.entrySet()) {

        UpcStar upcStar = xm.getKey();
        SsaCrossMatch ssa = xm.getValue();

        // Get the SSA colours of the UPC star
        double b = ssa.ssaB;
        double r2 = ssa.ssaR2;
        //         double i = ssa.ssaI;

        // Use the parallax to correct the apparent magnitude to absolute magnitude.

        // Extract the parallax and error to use
        double p = (useHip && upcStar.isHipparcosStar()) ? upcStar.srcPi : upcStar.absPi;
        double sigma_p = (useHip && upcStar.isHipparcosStar()) ? upcStar.srcPiErr : upcStar.absPiErr;

        // Filter on the fractional parallax error
        double f = sigma_p / p;
        if (f > fMax) {
            continue;
        }

        // Correct to arcseconds
        p /= 1000;
        sigma_p /= 1000;

        // Get the distance
        double d = DistanceFromParallax.getDistance(p, sigma_p, method);
        // Filter & convert to absolute magnitude
        if (d > 0 && !Double.isInfinite(d)) {
            double B = MagnitudeUtils.getAbsoluteMagnitude(d, b);
            series.add(b - r2, B);
        }
    }

    XYSeriesCollection data = new XYSeriesCollection();
    data.addSeries(series);

    // Set up the renderer
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();

    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesShapesVisible(0, true);
    renderer.setSeriesShape(0, new Ellipse2D.Double(-0.5, -0.5, 1, 1));

    // Configure axes
    NumberAxis xAxis = new NumberAxis("B - R [mag]");
    xAxis.setRange(-1.0, 3.5);

    NumberAxis yAxis = new NumberAxis("B [mag]");
    yAxis.setInverted(true);
    yAxis.setRange(-5, 15);

    // Configure plot
    XYPlot xyplot = new XYPlot(data, xAxis, yAxis, renderer);
    xyplot.setBackgroundPaint(Color.white);

    JFreeChart chart = new JFreeChart("HR diagram of UPC stars with SSA cross-matches", xyplot);
    chart.removeLegend();
    chart.setBackgroundPaint(Color.white);

    if (chartPanel == null) {
        // Branch is used on initialisation
        chartPanel = new ChartPanel(chart);
    } else {
        chartPanel.setChart(chart);
    }

}

From source file:org.gephi.statistics.plugin.ConnectedComponents.java

public String getReport() {
    Map<Integer, Integer> sizeDist = new HashMap<Integer, Integer>();
    for (int v : componentsSize) {
        if (!sizeDist.containsKey(v)) {
            sizeDist.put(v, 0);//from w w  w  .ja v  a 2s.  co  m
        }
        sizeDist.put(v, sizeDist.get(v) + 1);
    }

    //Distribution series
    XYSeries dSeries = ChartUtils.createXYSeries(sizeDist, "Size Distribution");

    XYSeriesCollection dataset1 = new XYSeriesCollection();
    dataset1.addSeries(dSeries);

    JFreeChart chart = ChartFactory.createXYLineChart("Size Distribution", "Size (number of nodes)", "Count",
            dataset1, PlotOrientation.VERTICAL, true, false, false);
    chart.removeLegend();
    ChartUtils.decorateChart(chart);
    ChartUtils.scaleChart(chart, dSeries, false);
    String imageFile = ChartUtils.renderChart(chart, "cc-size-distribution.png");

    NumberFormat f = new DecimalFormat("#0.000");

    String report = "<HTML> <BODY> <h1>Connected Components Report </h1> " + "<hr>" + "<br>"
            + "<h2> Parameters: </h2>" + "Network Interpretation:  " + (isDirected ? "directed" : "undirected")
            + "<br>" + "<br> <h2> Results: </h2>" + "Number of Weakly Connected Components: " + componentCount
            + "<br>" + (isDirected ? "Number of Stronlgy Connected Components: " + stronglyCount + "<br>" : "")
            + "<br /><br />" + imageFile + "<br />" + "<h2> Algorithm: </h2>"
            + "Robert Tarjan, <i>Depth-First Search and Linear Graph Algorithms</i>, in SIAM Journal on Computing 1 (2): 146160 (1972)<br />"
            + "</BODY> </HTML>";

    return report;
}

From source file:org.encog.workbench.tabs.rbf.RadialBasisFunctionsTab.java

public XYDataset createDataset() {
    String title = rbf.getClass().getSimpleName();
    XYSeriesCollection dataset = new XYSeriesCollection();

    Function2D n1 = new RBFFunction2D(this.rbf);// //new NormalDistributionFunction2D(0.0, 1.0);
    XYSeries s1 = DatasetUtilities.sampleFunction2DToSeries(n1, -5.1, 5.1, 121, title);
    dataset.addSeries(s1);

    return dataset;
}

From source file:sanger.team16.gui.genevar.eqtl.gene.RegionalPlot.java

private void addToDataset(XYSeriesCollection dataset, List<QTL> qtls) {
    int size = qtls.size();
    for (int i = 0; i < size; i++) {
        QTL qtl = qtls.get(i);//  w  w  w .jav a  2  s  . c o m

        XYSeries series = new XYSeries(qtl.snp.getName());
        series.add(qtl.snp.getPosition(), qtl.getMinusLog10P());

        dataset.addSeries(series);
    }
}

From source file:org.knime.knip.core.ui.imgviewer.panels.HistogramBC.java

private JFreeChart createChart(final String title, final List<XYSeries> series) {
    final XYSeriesCollection data = new XYSeriesCollection();
    for (XYSeries xys : series) {
        data.addSeries(xys);
    }//from w w w . jav  a  2s .com
    final JFreeChart chart = ChartFactory.createXYBarChart(title, null, false, null, data,
            PlotOrientation.VERTICAL, false, true, false);
    setTheme(chart);
    // chart.getXYPlot().setForegroundAlpha(0.50f);
    return chart;
}

From source file:org.optaplanner.benchmark.impl.statistic.single.constraintmatchtotalbestscore.ConstraintMatchTotalBestScoreSingleStatistic.java

@Override
public void writeGraphFiles(BenchmarkReport benchmarkReport) {
    List<Map<String, XYSeries>> constraintIdToWeightSeriesMapList = new ArrayList<Map<String, XYSeries>>(
            BenchmarkReport.CHARTED_SCORE_LEVEL_SIZE);
    for (ConstraintMatchTotalBestScoreStatisticPoint point : getPointList()) {
        int scoreLevel = point.getScoreLevel();
        if (scoreLevel >= BenchmarkReport.CHARTED_SCORE_LEVEL_SIZE) {
            continue;
        }//from   ww  w  .j  a v  a  2  s .c  o m
        while (scoreLevel >= constraintIdToWeightSeriesMapList.size()) {
            constraintIdToWeightSeriesMapList.add(new LinkedHashMap<String, XYSeries>());
        }
        Map<String, XYSeries> constraintIdToWeightSeriesMap = constraintIdToWeightSeriesMapList.get(scoreLevel);
        if (constraintIdToWeightSeriesMap == null) {
            constraintIdToWeightSeriesMap = new LinkedHashMap<String, XYSeries>();
            constraintIdToWeightSeriesMapList.set(scoreLevel, constraintIdToWeightSeriesMap);
        }
        String constraintId = point.getConstraintPackage() + ":" + point.getConstraintName();
        XYSeries weightSeries = constraintIdToWeightSeriesMap.get(constraintId);
        if (weightSeries == null) {
            weightSeries = new XYSeries(point.getConstraintName() + " weight");
            constraintIdToWeightSeriesMap.put(constraintId, weightSeries);
        }
        long timeMillisSpent = point.getTimeMillisSpent();
        weightSeries.add(timeMillisSpent, point.getWeightTotal());
    }
    graphFileList = new ArrayList<File>(constraintIdToWeightSeriesMapList.size());
    for (int scoreLevelIndex = 0; scoreLevelIndex < constraintIdToWeightSeriesMapList
            .size(); scoreLevelIndex++) {
        XYPlot plot = createPlot(benchmarkReport, scoreLevelIndex);
        // No direct ascending lines between 2 points, but a stepping line instead
        XYItemRenderer renderer = new XYStepRenderer();
        plot.setRenderer(renderer);
        XYSeriesCollection seriesCollection = new XYSeriesCollection();
        for (XYSeries series : constraintIdToWeightSeriesMapList.get(scoreLevelIndex).values()) {
            seriesCollection.addSeries(series);
        }
        plot.setDataset(seriesCollection);
        JFreeChart chart = new JFreeChart(singleBenchmarkResult.getName()
                + " constraint match total best score diff level " + scoreLevelIndex + " statistic",
                JFreeChart.DEFAULT_TITLE_FONT, plot, true);
        graphFileList.add(
                writeChartToImageFile(chart, "ConstraintMatchTotalBestScoreStatisticLevel" + scoreLevelIndex));
    }
}

From source file:org.optaplanner.benchmark.impl.statistic.subsingle.constraintmatchtotalbestscore.ConstraintMatchTotalBestScoreSubSingleStatistic.java

@Override
public void writeGraphFiles(BenchmarkReport benchmarkReport) {
    List<Map<String, XYSeries>> constraintIdToWeightSeriesMapList = new ArrayList<Map<String, XYSeries>>(
            BenchmarkReport.CHARTED_SCORE_LEVEL_SIZE);
    for (ConstraintMatchTotalBestScoreStatisticPoint point : getPointList()) {
        int scoreLevel = point.getScoreLevel();
        if (scoreLevel >= BenchmarkReport.CHARTED_SCORE_LEVEL_SIZE) {
            continue;
        }//  w ww  .j  a  v a  2s .c  o  m
        while (scoreLevel >= constraintIdToWeightSeriesMapList.size()) {
            constraintIdToWeightSeriesMapList.add(new LinkedHashMap<String, XYSeries>());
        }
        Map<String, XYSeries> constraintIdToWeightSeriesMap = constraintIdToWeightSeriesMapList.get(scoreLevel);
        if (constraintIdToWeightSeriesMap == null) {
            constraintIdToWeightSeriesMap = new LinkedHashMap<String, XYSeries>();
            constraintIdToWeightSeriesMapList.set(scoreLevel, constraintIdToWeightSeriesMap);
        }
        String constraintId = point.getConstraintPackage() + ":" + point.getConstraintName();
        XYSeries weightSeries = constraintIdToWeightSeriesMap.get(constraintId);
        if (weightSeries == null) {
            weightSeries = new XYSeries(point.getConstraintName() + " weight");
            constraintIdToWeightSeriesMap.put(constraintId, weightSeries);
        }
        long timeMillisSpent = point.getTimeMillisSpent();
        weightSeries.add(timeMillisSpent, point.getWeightTotal());
    }
    graphFileList = new ArrayList<File>(constraintIdToWeightSeriesMapList.size());
    for (int scoreLevelIndex = 0; scoreLevelIndex < constraintIdToWeightSeriesMapList
            .size(); scoreLevelIndex++) {
        XYPlot plot = createPlot(benchmarkReport, scoreLevelIndex);
        // No direct ascending lines between 2 points, but a stepping line instead
        XYItemRenderer renderer = new XYStepRenderer();
        plot.setRenderer(renderer);
        XYSeriesCollection seriesCollection = new XYSeriesCollection();
        for (XYSeries series : constraintIdToWeightSeriesMapList.get(scoreLevelIndex).values()) {
            seriesCollection.addSeries(series);
        }
        plot.setDataset(seriesCollection);
        JFreeChart chart = new JFreeChart(subSingleBenchmarkResult.getName()
                + " constraint match total best score diff level " + scoreLevelIndex + " statistic",
                JFreeChart.DEFAULT_TITLE_FONT, plot, true);
        graphFileList.add(
                writeChartToImageFile(chart, "ConstraintMatchTotalBestScoreStatisticLevel" + scoreLevelIndex));
    }
}

From source file:userinterface.EnvironmentRole.PollutionCheckJPanel.java

private void btnCheckReportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCheckReportActionPerformed
    int selectedRow = tableCarOwners.getSelectedRow();
    if (selectedRow < 0) {
        JOptionPane.showMessageDialog(null, "Please select a row from the table first", "Warning",
                JOptionPane.WARNING_MESSAGE);
        return;//from   w  w  w .j  av a2s. c  o m
    } else {

        WorkRequest workRequest = (WorkRequest) tableCarOwners.getValueAt(selectedRow, 3);
        UserAccount userAccount = workRequest.getSender();

        XYSeries series = new XYSeries("XYGraph");
        int i = 0;
        for (Fine fine : environmentOrganization.getFineHistory().getFineIncurredhistory()) {
            if (userAccount == fine.getUserAccount()) {
                series.add(fine.getFineIncurred(), i); //fine.getDate().getTime()
                i++;
            }
        }

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

        JFrame frame = new JFrame("Charts");

        frame.setSize(600, 400);
        //            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);

        JFreeChart chart = ChartFactory.createXYLineChart("Test Chart", "Time", "Fine", dataset,
                PlotOrientation.VERTICAL, true, true, false);

        ChartPanel cp = new ChartPanel(chart);

        frame.getContentPane().add(cp);
    }

}

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

/**
 * Sets the time range.//from  w  ww .j  a v a2  s.c  o  m
 * 
 * @param lower  the lower date limit (not used).
 * @param upper  the upper date limit (not used).
 */
public void setTimeRange(Date lower, Date upper) {
    XYSeriesCollection dataset = (XYSeriesCollection) ((XYPlot) this.getPlot()).getDataset();
    XYSeries newSeries = Circuit.getCircuit().getCrossSectionSeries().get(xLabel, yLabel);
    if (newSeries == null)
        return;
    try {
        dataset.removeSeries(0);
    } catch (IllegalArgumentException i) {
    }
    dataset.addSeries(newSeries);
}

From source file:org.jfree.data.xy.junit.XYSeriesCollectionTests.java

/**
 * Confirm that cloning works./*from ww w. j ava  2s .com*/
 */
public void testCloning() {
    XYSeries s1 = new XYSeries("Series");
    s1.add(1.0, 1.1);
    XYSeriesCollection c1 = new XYSeriesCollection();
    c1.addSeries(s1);
    XYSeriesCollection c2 = null;
    try {
        c2 = (XYSeriesCollection) c1.clone();
    } catch (CloneNotSupportedException e) {
        e.printStackTrace();
    }
    assertTrue(c1 != c2);
    assertTrue(c1.getClass() == c2.getClass());
    assertTrue(c1.equals(c2));

    // check independence
    s1.setDescription("XYZ");
    assertFalse(c1.equals(c2));
}