Example usage for org.jfree.chart.renderer.category BoxAndWhiskerRenderer setFillBox

List of usage examples for org.jfree.chart.renderer.category BoxAndWhiskerRenderer setFillBox

Introduction

In this page you can find the example usage for org.jfree.chart.renderer.category BoxAndWhiskerRenderer setFillBox.

Prototype

public void setFillBox(boolean flag) 

Source Link

Document

Sets the flag that controls whether or not the box is filled and sends a RendererChangeEvent to all registered listeners.

Usage

From source file:playground.wrashid.tryouts.mess.Boxplot.java

/**
 * @param args//  w w  w  .  jav a  2  s. c om
 */
public static void main(String[] args) {

    final BoxAndWhiskerCategoryDataset dataset = createSampleDataset();

    final CategoryAxis xAxis = new CategoryAxis("Type");
    final NumberAxis yAxis = new NumberAxis("Value");
    yAxis.setAutoRangeIncludesZero(false);
    final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setFillBox(false);
    renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator());
    final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);
    final JFreeChart chart = ChartFactory.createBoxAndWhiskerChart("Box-and-Whisker Demo", "x", "y", dataset,
            true);
    final ChartPanel chartPanel = new ChartPanel(chart);

    int width = 500;
    int height = 300;

    try {
        ChartUtilities.saveChartAsPNG(new File("boxPlot.png"), chart, width, height);
    } catch (IOException e) {

    }

}

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 .  j a  v  a2 s  .c  om
    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:wsattacker.plugin.intelligentdos.ui.helper.ChartHelper.java

public static JFreeChart createDumyChart() {
    final BoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset();

    final CategoryAxis xAxis = new CategoryAxis("Type");
    final NumberAxis yAxis = new NumberAxis("Value");
    yAxis.setAutoRangeIncludesZero(false);
    final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setFillBox(true);
    renderer.setMeanVisible(false);/*from w w  w .ja v a  2 s. c o  m*/
    renderer.setMedianVisible(false);
    // renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator());
    final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);

    return new JFreeChart(plot);
}

From source file:playground.wrashid.parkingSearch.ppSim.jdepSim.searchStrategies.analysis.ComparisonGarageCounts.java

public static void logRelativeError(LinkedList<ParkingEventDetails> parkingEventDetails,
        String outputFileName) {//from   w  w  w.  j  ava 2  s . c  o m
    int startIndex = 28;
    int endIndex = 76;

    Double countsScalingFactor = ZHScenarioGlobal.loadDoubleParam("ComparisonGarageCounts.countsScalingFactor");

    HashMap<Id, ParkingOccupancyBins> parkingOccupancyBins = new HashMap<Id, ParkingOccupancyBins>();

    for (ParkingEventDetails ped : parkingEventDetails) {
        ParkingActivityAttributes parkingActivityAttributes = ped.parkingActivityAttributes;
        Id facilityId = parkingActivityAttributes.getFacilityId();
        if (mappingOfParkingNameToParkingId.values().contains(facilityId.toString())) {
            if (!parkingOccupancyBins.containsKey(facilityId)) {
                parkingOccupancyBins.put(facilityId, new ParkingOccupancyBins());
            }
            ParkingOccupancyBins parkingOccupancyBin = parkingOccupancyBins.get(facilityId);
            parkingOccupancyBin.inrementParkingOccupancy(parkingActivityAttributes.getParkingArrivalTime(),
                    parkingActivityAttributes.getParkingArrivalTime()
                            + parkingActivityAttributes.getParkingDuration());
        }
    }

    HashMap<String, Double[]> occupancyOfAllSelectedParkings = SingleDayGarageParkingsCount
            .getOccupancyOfAllSelectedParkings(countsMatrix);

    List<Double> relativeErrorList = new ArrayList<Double>();

    for (String parkingName : selectedParkings) {
        Double[] occupancyBins = occupancyOfAllSelectedParkings.get(parkingName);
        double measuredOccupancySum = 0;
        for (int i = startIndex; i < endIndex; i++) {
            measuredOccupancySum += countsScalingFactor * occupancyBins[i];
        }

        Id<PParking> parkingId = Id.create(mappingOfParkingNameToParkingId.get(parkingName), PParking.class);
        ParkingOccupancyBins pob = parkingOccupancyBins.get(parkingId);

        double simulatedOccupancySum = 0;

        if (pob != null) {
            for (int i = startIndex; i < endIndex; i++) {
                simulatedOccupancySum += pob.getOccupancy()[i];
            }
        }

        double relativeError = -1;
        if (measuredOccupancySum != 0) {
            relativeError = Math.abs(simulatedOccupancySum - measuredOccupancySum) / measuredOccupancySum;
        }

        //System.out.println(parkingId + ": " +  relativeError);
        relativeErrorCounts.put(parkingId, relativeError);

        relativeErrorList.add(new Double(relativeError));
    }
    boxPlotDataSet.add(relativeErrorList, "relativeError", ZHScenarioGlobal.iteration);

    final NumberAxis yAxis = new NumberAxis("Value");
    yAxis.setAutoRangeIncludesZero(false);
    final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setFillBox(false);
    final JFreeChart chart = ChartFactory.createBoxAndWhiskerChart("Rel. Error - Garage Parking Counts",
            "Iteration", "rel. Error", boxPlotDataSet, false);

    int width = 500;
    int height = 300;

    try {
        ChartUtilities.saveChartAsPNG(new File(outputFileName), chart, width, height);
    } catch (IOException e) {

    }

    // print median rel. error:
    Double[] numArray = relativeErrorList.toArray(new Double[0]);
    Arrays.sort(numArray);
    double median;
    if (numArray.length % 2 == 0)
        median = (numArray[numArray.length / 2] + numArray[numArray.length / 2 + 1]) / 2;
    else
        median = numArray[numArray.length / 2];
    log.info("median rel. error:" + median);
}

From source file:org.gephi.ui.utils.ChartsUtils.java

/**
 * Build a new box-plot from an array of numbers using a default title and yLabel.
 * String dataName will be used for xLabel.
 * @param numbers Numbers for building box-plot
 * @param dataName Name of the numbers data
 * @return Prepared box-plot//from   w  w  w  .java2  s  . c o  m
 */
public static JFreeChart buildBoxPlot(final Number[] numbers, final String dataName) {
    if (numbers == null || numbers.length == 0) {
        return null;
    }
    DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset();
    final ArrayList<Number> list = new ArrayList<Number>();
    list.addAll(Arrays.asList(numbers));

    final String valuesString = getMessage("ChartsUtils.report.box-plot.values");
    dataset.add(list, valuesString, "");

    final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setMeanVisible(false);
    renderer.setFillBox(false);
    renderer.setMaximumBarWidth(0.5);

    final CategoryAxis xAxis = new CategoryAxis(dataName);
    final NumberAxis yAxis = new NumberAxis(getMessage("ChartsUtils.report.box-plot.values-range"));
    yAxis.setAutoRangeIncludesZero(false);
    renderer.setBaseToolTipGenerator(new BoxAndWhiskerToolTipGenerator());
    final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);
    plot.setRenderer(renderer);

    JFreeChart boxPlot = new JFreeChart(getMessage("ChartsUtils.report.box-plot.title"), plot);
    return boxPlot;
}

From source file:weka.core.ChartUtils.java

/**
 * Create a box plot from summary data (mean, median, q1, q3, min, max,
 * minOutlier, maxOutlier, list of outliers)
 * //from   w w  w  .j  a  v  a 2  s  .  c om
 * @param summary summary data
 * @param outliers list of outlier values
 * @param additionalArgs additional options to the renderer
 * @return a box plot chart
 * @throws Exception if a problem occurs
 */
protected static JFreeChart getBoxPlotFromSummaryData(List<Double> summary, List<Double> outliers,
        List<String> additionalArgs) throws Exception {

    if (summary.size() != 8) {
        throw new Exception("Expected 8 values in the summary argument: mean, median, "
                + "q1, q3, min, max, minOutlier, maxOutlier");
    }

    String plotTitle = "Box Plog";
    String userTitle = getOption(additionalArgs, "-title");
    plotTitle = (userTitle != null) ? userTitle : plotTitle;
    String xLabel = getOption(additionalArgs, "-x-label");
    xLabel = xLabel == null ? "" : xLabel;
    String yLabel = getOption(additionalArgs, "-y-label");
    yLabel = yLabel == null ? "" : yLabel;

    DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset();

    Double mean = summary.get(0);
    Double median = summary.get(1);
    Double q1 = summary.get(2);
    Double q3 = summary.get(3);
    Double min = summary.get(4);
    Double max = summary.get(5);
    Double minOutlier = summary.get(6);
    Double maxOutlier = summary.get(7);

    if (mean.isNaN() || median.isNaN() || min.isNaN() || max.isNaN() || q1.isNaN() || q3.isNaN()) {
        throw new Exception("NaN in summary data - can't generate box plot");
    }

    BoxAndWhiskerItem item = new BoxAndWhiskerItem(mean, median, q1, q3, min, max, minOutlier, maxOutlier,
            outliers);

    dataset.add(item, "", "");

    CategoryAxis xAxis = new CategoryAxis();
    NumberAxis yAxis = new NumberAxis();
    yAxis.setAutoRangeIncludesZero(false);
    BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setFillBox(false);
    renderer.setMaximumBarWidth(0.15);

    CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);

    JFreeChart chart = new JFreeChart(plotTitle, new Font("SansSerif", Font.BOLD, 12), plot, false);

    return chart;
}

From source file:playground.anhorni.PLOC.analysis.MultipleEnsemblesBoxPlot.java

public JFreeChart createChart() {
    String title = chartTitle;/*w w w  .  ja  v  a 2  s .  co m*/

    final CategoryAxis xAxis = new CategoryAxis("Runs ensemble size");
    xAxis.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 10));
    xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);

    final NumberAxis yAxis = new NumberAxis("AvgDaysRuns_OfEnsembleAverageOfTotalExpenditures");
    yAxis.setAutoRangeIncludesZero(true);

    final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setFillBox(false);
    renderer.setSeriesPaint(0, Color.blue);
    CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);

    this.chart_ = new JFreeChart(title, new Font("SansSerif", Font.BOLD, 14), plot, false);
    return this.chart_;
}

From source file:playground.anhorni.PLOC.analysis.RunsEnsembleBoxPlot.java

public JFreeChart createChart() {
    String title = chartTitle;//from  w  ww .j a v  a 2s. co  m

    final CategoryAxis xAxis = new CategoryAxis("Hour");
    xAxis.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 10));
    xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);

    final NumberAxis yAxis = new NumberAxis("AverageDays_Expenditures");
    yAxis.setAutoRangeIncludesZero(true);

    final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setFillBox(false);
    renderer.setSeriesPaint(0, Color.blue);
    CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);

    this.chart_ = new JFreeChart(title, new Font("SansSerif", Font.BOLD, 14), plot, false);
    return this.chart_;
}

From source file:org.fhcrc.cpl.toolbox.gui.chart.PanelWithBoxAndWhiskerChart.java

protected void init() {
    dataset = new DefaultBoxAndWhiskerCategoryDataset();

    final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setFillBox(false);
    renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator());
    final CategoryAxis xAxis = new CategoryAxis("Type");
    final NumberAxis yAxis = new NumberAxis("Value");
    final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);

    final JFreeChart chart = new JFreeChart(getName(), new Font("SansSerif", Font.BOLD, 14), plot, true);

    init(chart.getPlot());//  www . ja  v a 2s .  c o  m
}

From source file:org.jgrasstools.gears.utils.chart.CategoryBoxplot.java

public JFreeChart getChart() {
    if (chart == null) {
        createDataset();//from   w  ww  .  j a v  a2s .c  o m
        chart = ChartFactory.createBarChart(getTitle(),
                // chart title
                "Category",
                // domain axis label
                "Value",
                // range axis label
                dataset,
                // data
                PlotOrientation.VERTICAL,
                // orientation
                false,
                // include legend
                true,
                // tooltips?
                false
        // URLs?
        );
        CategoryPlot plot = (CategoryPlot) chart.getPlot();
        CategoryAxis rangeAxis = plot.getDomainAxis();
        rangeAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
        final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
        renderer.setFillBox(true);
        renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator());
        renderer.setMeanVisible(isMeanVisible);
        plot.setRenderer(renderer);
    }

    return chart;
}