Search in sources :

Example 6 with XYSeriesCollection

use of org.jfree.data.xy.XYSeriesCollection in project gephi by gephi.

the class ConnectedComponents method getReport.

@Override
public String getReport() {
    Map<Integer, Integer> sizeDist = new HashMap<>();
    for (int v : componentsSize) {
        if (!sizeDist.containsKey(v)) {
            sizeDist.put(v, 0);
        }
        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): 146–160 (1972)<br />" + "</BODY> </HTML>";
    return report;
}
Also used : XYSeries(org.jfree.data.xy.XYSeries) HashMap(java.util.HashMap) DecimalFormat(java.text.DecimalFormat) XYSeriesCollection(org.jfree.data.xy.XYSeriesCollection) JFreeChart(org.jfree.chart.JFreeChart) NumberFormat(java.text.NumberFormat)

Example 7 with XYSeriesCollection

use of org.jfree.data.xy.XYSeriesCollection in project gephi by gephi.

the class Hits method getReport.

/**
     *
     * @return
     */
@Override
public String getReport() {
    //distribution of hub values
    Map<Double, Integer> distHubs = new HashMap<>();
    for (int i = 0; i < hubs.length; i++) {
        Double d = hubs[i];
        if (distHubs.containsKey(d)) {
            Integer v = distHubs.get(d);
            distHubs.put(d, v + 1);
        } else {
            distHubs.put(d, 1);
        }
    }
    //distribution of authority values
    Map<Double, Integer> distAuthorities = new HashMap<>();
    for (int i = 0; i < authority.length; i++) {
        Double d = authority[i];
        if (distAuthorities.containsKey(d)) {
            Integer v = distAuthorities.get(d);
            distAuthorities.put(d, v + 1);
        } else {
            distAuthorities.put(d, 1);
        }
    }
    //Distribution of hub series
    XYSeries dHubsSeries = ChartUtils.createXYSeries(distHubs, "Hubs");
    //Distribution of authority series
    XYSeries dAuthsSeries = ChartUtils.createXYSeries(distAuthorities, "Authority");
    XYSeriesCollection datasetHubs = new XYSeriesCollection();
    datasetHubs.addSeries(dHubsSeries);
    XYSeriesCollection datasetAuths = new XYSeriesCollection();
    datasetAuths.addSeries(dAuthsSeries);
    JFreeChart chart = ChartFactory.createXYLineChart("Hubs Distribution", "Score", "Count", datasetHubs, PlotOrientation.VERTICAL, true, false, false);
    chart.removeLegend();
    ChartUtils.decorateChart(chart);
    ChartUtils.scaleChart(chart, dHubsSeries, true);
    String imageFile1 = ChartUtils.renderChart(chart, "hubs.png");
    JFreeChart chart2 = ChartFactory.createXYLineChart("Authority Distribution", "Score", "Count", datasetAuths, PlotOrientation.VERTICAL, true, false, false);
    chart2.removeLegend();
    ChartUtils.decorateChart(chart2);
    ChartUtils.scaleChart(chart2, dAuthsSeries, true);
    String imageFile2 = ChartUtils.renderChart(chart2, "authorities.png");
    String report = "<HTML> <BODY> <h1> HITS Metric Report </h1>" + "<hr>" + "<br />" + "<h2> Parameters: </h2>  &#917; = " + this.epsilon + "<br /> <h2> Results: </h2><br />" + imageFile1 + "<br />" + imageFile2 + "<br /><br />" + "<h2> Algorithm: </h2>" + "Jon M. Kleinberg, <i>Authoritative Sources in a Hyperlinked Environment</i>, in Journal of the ACM 46 (5): 604–632 (1999)<br />" + "</BODY> </HTML>";
    return report;
}
Also used : XYSeries(org.jfree.data.xy.XYSeries) HashMap(java.util.HashMap) XYSeriesCollection(org.jfree.data.xy.XYSeriesCollection) JFreeChart(org.jfree.chart.JFreeChart)

Example 8 with XYSeriesCollection

use of org.jfree.data.xy.XYSeriesCollection in project gephi by gephi.

the class ChartsUtils method buildScatterPlot.

/**
     * Build new scatter plot from numbers array using a default title and xLabel.
     * String dataName will be used for yLabel.
     * Appearance can be changed later with the other methods of ChartsUtils.
     * @param numbers Numbers for the scatter plot
     * @param dataName Name of the numbers data
     * @param useLines Indicates if lines have to be drawn instead of shapes
     * @param useLinearRegression Indicates if the scatter plot has to have linear regreesion line drawn
     * @return Scatter plot for the data and appearance options
     */
public static JFreeChart buildScatterPlot(final Number[] numbers, final String dataName, final boolean useLines, final boolean useLinearRegression) {
    if (numbers == null || numbers.length == 0) {
        return null;
    }
    XYSeriesCollection dataset = new XYSeriesCollection();
    XYSeries series = new XYSeries(dataName);
    for (int i = 0; i < numbers.length; i++) {
        series.add(i, numbers[i]);
    }
    dataset.addSeries(series);
    JFreeChart scatterPlot = buildScatterPlot(dataset, getMessage("ChartsUtils.report.scatter-plot.title"), getMessage("ChartsUtils.report.scatter-plot.xLabel"), dataName, useLines, useLinearRegression);
    return scatterPlot;
}
Also used : XYSeries(org.jfree.data.xy.XYSeries) XYSeriesCollection(org.jfree.data.xy.XYSeriesCollection) JFreeChart(org.jfree.chart.JFreeChart)

Example 9 with XYSeriesCollection

use of org.jfree.data.xy.XYSeriesCollection in project gephi by gephi.

the class ChartsUtils method setScatterPlotLinearRegressionEnabled.

/**
     * Modify a scatter plot to show linear regression or not.
     * @param scatterPlot Scatter plot to modify
     * @param enabled Indicates if linear regression has to be shown
     */
public static void setScatterPlotLinearRegressionEnabled(final JFreeChart scatterPlot, final boolean enabled) {
    XYPlot plot = (XYPlot) scatterPlot.getPlot();
    if (enabled) {
        StandardXYItemRenderer regressionRenderer = new StandardXYItemRenderer();
        regressionRenderer.setBaseSeriesVisibleInLegend(false);
        plot.setDataset(1, regress((XYSeriesCollection) plot.getDataset(0)));
        plot.setRenderer(1, regressionRenderer);
    } else {
        //Remove linear regression
        plot.setDataset(1, null);
    }
}
Also used : XYPlot(org.jfree.chart.plot.XYPlot) StandardXYItemRenderer(org.jfree.chart.renderer.xy.StandardXYItemRenderer) XYSeriesCollection(org.jfree.data.xy.XYSeriesCollection)

Example 10 with XYSeriesCollection

use of org.jfree.data.xy.XYSeriesCollection in project uncommons-maths by dwdyer.

the class GraphPanel method generateGraph.

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);
    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);
}
Also used : XYSeries(org.jfree.data.xy.XYSeries) XYPlot(org.jfree.chart.plot.XYPlot) XYSplineRenderer(org.jfree.chart.renderer.xy.XYSplineRenderer) XYLineAndShapeRenderer(org.jfree.chart.renderer.xy.XYLineAndShapeRenderer) XYSeriesCollection(org.jfree.data.xy.XYSeriesCollection) Map(java.util.Map) JFreeChart(org.jfree.chart.JFreeChart)

Aggregations

XYSeriesCollection (org.jfree.data.xy.XYSeriesCollection)23 XYSeries (org.jfree.data.xy.XYSeries)22 JFreeChart (org.jfree.chart.JFreeChart)17 DecimalFormat (java.text.DecimalFormat)11 NumberFormat (java.text.NumberFormat)11 HashMap (java.util.HashMap)6 XYPlot (org.jfree.chart.plot.XYPlot)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 Node (org.gephi.graph.api.Node)1 StandardXYItemRenderer (org.jfree.chart.renderer.xy.StandardXYItemRenderer)1 XYLineAndShapeRenderer (org.jfree.chart.renderer.xy.XYLineAndShapeRenderer)1 XYSplineRenderer (org.jfree.chart.renderer.xy.XYSplineRenderer)1 XYDataItem (org.jfree.data.xy.XYDataItem)1