Example usage for org.jfree.chart ChartUtilities writeScaledChartAsPNG

List of usage examples for org.jfree.chart ChartUtilities writeScaledChartAsPNG

Introduction

In this page you can find the example usage for org.jfree.chart ChartUtilities writeScaledChartAsPNG.

Prototype

public static void writeScaledChartAsPNG(OutputStream out, JFreeChart chart, int width, int height,
        int widthScaleFactor, int heightScaleFactor) throws IOException 

Source Link

Document

Writes a scaled version of a chart to an output stream in PNG format.

Usage

From source file:edu.msu.cme.rdp.classifier.train.validation.distance.BoxPlotUtils.java

public static void createBoxplot(DefaultBoxAndWhiskerCategoryDataset scatterDataset, PrintStream outStream,
        String title, String xAxisLabel, String yAxisLabel, Font lableFont) throws IOException {

    CategoryAxis xAxis = new CategoryAxis(xAxisLabel);
    xAxis.setLabelFont(lableFont);//w ww. ja v a  2s.  com
    NumberAxis yAxis = new NumberAxis(yAxisLabel);
    yAxis.setTickLabelFont(lableFont);
    yAxis.setAutoRangeIncludesZero(false);
    yAxis.setRange(0, 100);
    yAxis.setLabelFont(lableFont);

    BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setFillBox(true);
    renderer.setBaseLegendTextFont(lableFont);
    renderer.setStroke(new BasicStroke(5.0f));

    CategoryPlot plot = new CategoryPlot(scatterDataset, xAxis, yAxis, renderer);
    JFreeChart boxchart = new JFreeChart(title, new Font("Helvetica", Font.BOLD, 40), plot, true);

    // higher scale factor gives higher resolution
    ChartUtilities.writeScaledChartAsPNG(outStream, boxchart, 800, 1000, 3, 3);
}

From source file:scrum.server.common.BurndownChart.java

static void writeSprintBurndownChart(OutputStream out, List<? extends BurndownSnapshot> snapshots,
        Date firstDay, Date lastDay, Date originallyLastDay, WeekdaySelector freeDays, int width, int height) {
    LOG.debug("Creating burndown chart:", snapshots.size(), "snapshots from", firstDay, "to", lastDay,
            "(" + width + "x" + height + " px)");

    int dayCount = firstDay.getPeriodTo(lastDay).toDays();
    int dateMarkTickUnit = 1;
    float widthPerDay = (float) width / (float) dayCount * dateMarkTickUnit;
    while (widthPerDay < 20) {
        dateMarkTickUnit++;/*  w w w  .j  av  a 2  s.  c o  m*/
        widthPerDay = (float) width / (float) dayCount * dateMarkTickUnit;
    }

    List<BurndownSnapshot> burndownSnapshots = new ArrayList<BurndownSnapshot>(snapshots);
    JFreeChart chart = createSprintBurndownChart(burndownSnapshots, firstDay, lastDay, originallyLastDay,
            freeDays, dateMarkTickUnit, widthPerDay);
    try {
        ChartUtilities.writeScaledChartAsPNG(out, chart, width, height, 1, 1);
        out.flush();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:edu.msu.cme.rdp.classifier.train.validation.distance.TaxaSimilarityMain.java

public void createPlot(String plotTitle, File outdir) throws IOException {
    XYSeriesCollection dataset = new XYSeriesCollection();
    DefaultBoxAndWhiskerCategoryDataset scatterDataset = new DefaultBoxAndWhiskerCategoryDataset();

    PrintStream boxchart_dataStream = new PrintStream(new File(outdir, plotTitle + ".boxchart.txt"));

    boxchart_dataStream.println(//from w  w w  .jav  a 2s .  co m
            "#\tkmer" + "\trank" + "\t" + "max" + "\t" + "avg" + "\t" + "min" + "\t" + "Q1" + "\t" + "median"
                    + "\t" + "Q3" + "\t" + "98Pct" + "\t" + "2Pct" + "\t" + "comparisons" + "\t" + "sum");
    for (int i = 0; i < ranks.size(); i++) {
        long[] countArray = sabCoutMap.get(ranks.get(i));
        if (countArray == null)
            continue;

        double sum = 0.0;
        int max = 0;
        int min = 100;
        double mean = 0;
        int Q1 = -1;
        int median = -1;
        int Q3 = -1;
        int pct_98 = -1;
        int pct_2 = -1;
        long comparisons = 0;
        int minOutlier = 0; // we don't care about the outliers
        int maxOutlier = 0; //

        XYSeries series = new XYSeries(ranks.get(i));

        for (int c = 0; c < countArray.length; c++) {
            if (countArray[c] == 0)
                continue;
            comparisons += countArray[c];
            sum += countArray[c] * c;
            if (c < min) {
                min = c;
            }
            if (c > max) {
                max = c;
            }
        }

        // create series
        double cum = 0;
        for (int c = 0; c < countArray.length; c++) {
            if (countArray[c] == 0)
                continue;
            cum += countArray[c];
            int pct = (int) Math.floor(100 * cum / comparisons);
            series.add(c, pct);

            if (pct_2 == -1 && pct >= 5) {
                pct_2 = c;
            }
            if (Q3 == -1 && pct >= 25) {
                Q3 = c;
            }
            if (median == -1 && pct >= 50) {
                median = c;
            }
            if (Q1 == -1 && pct >= 75) {
                Q1 = c;
            }
            if (pct_98 == -1 && pct >= 98) {
                pct_98 = c;
            }
        }
        if (!series.isEmpty()) {
            dataset.addSeries(series);

            BoxAndWhiskerItem item = new BoxAndWhiskerItem(sum / comparisons, median, Q1, Q3, pct_2, pct_98,
                    minOutlier, maxOutlier, new ArrayList());
            scatterDataset.add(item, ranks.get(i), "");

            boxchart_dataStream.println("#\t" + GoodWordIterator.getWordsize() + "\t" + ranks.get(i) + "\t"
                    + max + "\t" + format.format(sum / comparisons) + "\t" + min + "\t" + Q1 + "\t" + median
                    + "\t" + Q3 + "\t" + pct_98 + "\t" + pct_2 + "\t" + comparisons + "\t" + sum);
        }
    }
    boxchart_dataStream.close();
    Font lableFont = new Font("Helvetica", Font.BOLD, 28);

    JFreeChart chart = ChartFactory.createXYLineChart(plotTitle, "Similarity%", "Percent Comparisions", dataset,
            PlotOrientation.VERTICAL, true, true, false);
    ((XYPlot) chart.getPlot()).getRenderer().setStroke(new BasicStroke(2.0f));
    chart.getLegend().setItemFont(new Font("Helvetica", Font.BOLD, 24));
    chart.getTitle().setFont(lableFont);
    ((XYPlot) chart.getPlot()).getDomainAxis().setLabelFont(lableFont);
    ((XYPlot) chart.getPlot()).getDomainAxis().setTickLabelFont(lableFont);
    ValueAxis rangeAxis = ((XYPlot) chart.getPlot()).getRangeAxis();
    rangeAxis.setRange(0, 100);
    rangeAxis.setTickLabelFont(lableFont);
    rangeAxis.setLabelFont(lableFont);
    ((NumberAxis) rangeAxis).setTickUnit(new NumberTickUnit(5));
    ChartUtilities.writeScaledChartAsPNG(new PrintStream(new File(outdir, plotTitle + ".linechart.png")), chart,
            800, 1000, 3, 3);

    BoxPlotUtils.createBoxplot(scatterDataset, new PrintStream(new File(outdir, plotTitle + ".boxchart.png")),
            plotTitle, "Rank", "Similarity%", lableFont);

}