Example usage for org.jfree.chart ChartFactory createBoxAndWhiskerChart

List of usage examples for org.jfree.chart ChartFactory createBoxAndWhiskerChart

Introduction

In this page you can find the example usage for org.jfree.chart ChartFactory createBoxAndWhiskerChart.

Prototype

public static JFreeChart createBoxAndWhiskerChart(String title, String timeAxisLabel, String valueAxisLabel,
        BoxAndWhiskerXYDataset dataset, boolean legend) 

Source Link

Document

Creates and returns a default instance of a box and whisker chart.

Usage

From source file:org.webcat.grader.graphs.BoxAndWhiskerChart.java

@Override
protected JFreeChart generateChart(WCChartTheme chartTheme) {
    setChartHeight(36);//  w  w  w .j a  v  a 2s . c  o m

    JFreeChart chart = ChartFactory.createBoxAndWhiskerChart(null, null, yAxisLabel(), boxAndWhiskerXYDataset(),
            false);
    chart.getXYPlot().setOrientation(PlotOrientation.HORIZONTAL);
    chart.setPadding(new RectangleInsets(0, 6, 0, 6));

    XYPlot plot = chart.getXYPlot();
    plot.setInsets(RectangleInsets.ZERO_INSETS);
    plot.setOutlineVisible(false);
    plot.setBackgroundPaint(new Color(0, 0, 0, 0));
    XYBoxAndWhiskerRenderer renderer = (XYBoxAndWhiskerRenderer) plot.getRenderer();
    renderer.setAutoPopulateSeriesOutlinePaint(true);

    ValueAxis domainAxis = plot.getDomainAxis();
    domainAxis.setVisible(false);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setRange(-0.5, assignmentOffering.assignment().submissionProfile().availablePoints() + 0.5);
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    Font oldFont = rangeAxis.getTickLabelFont();
    rangeAxis.setTickLabelFont(oldFont.deriveFont(oldFont.getSize2D() * 0.8f));

    return chart;
}

From source file:adapters.BoxChartAdapter.java

/**
 * Modified Method: set legend to be false instead of true
 * @param title boxplot title//  w ww  . j  a v  a 2s . c o m
 * @param XLabel x axis label
 * @param YLabel y axis label
 */
protected void init(String title, String XLabel, String YLabel) {
    // create the chart...
    chart = ChartFactory.createBoxAndWhiskerChart(title, // chart title
            XLabel, // x axis label
            YLabel, // y axis label
            (DefaultBoxAndWhiskerCategoryDataset) dataset.getSeriesCollection(), // data
            false // include legend
    );

    ((CategoryPlot) chart.getPlot()).setRenderer(dataset.getRenderer());
    // Initialize axis variables
    initAxis();
}

From source file:playground.thibautd.utils.charts.BoxAndWhiskersChart.java

private void createChart() {
    boolean legend = false;

    this.createDataSet();

    this.chart = ChartFactory.createBoxAndWhiskerChart(this.chartTitle, this.xAxisLabel, this.yAxisLabel,
            this.boxes, legend);

    XYPlot plot = this.chart.getXYPlot();
    plot.setDomainAxis(new NumberAxis(this.xAxisLabel));
    plot.getDomainAxis().configure();//from  w  w w.  j  a v  a2  s .  c om

    if (plotStdDev) {
        XYErrorRenderer renderer = new XYErrorRenderer();
        // in black
        renderer.setErrorPaint(Color.BLACK);
        // only plot Y error
        renderer.setDrawXError(false);
        // do not render average (already done by the B&W)
        renderer.setBaseShapesVisible(false);
        plot.setRenderer(1, renderer);
        plot.setDataset(1, deviationBars);
        plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    }

    //this.addMatsimLogo();

    //try {
    //   this.addDefaultFormatting();
    //} catch (NullPointerException e) {
    //   // occurs if no legend
    //}

    //this.chart.setBackgroundPaint(Color.white);
    plot.setBackgroundPaint(Color.white);
    XYBoxAndWhiskerRenderer renderer = (XYBoxAndWhiskerRenderer) plot.getRenderer();
    //renderer.setFillBox(false);
    //renderer.setSeriesOutlinePaint(0, Color.black);
    //renderer.setSeriesPaint(0, Color.black);
    renderer.setBoxPaint(renderer.getSeriesPaint(0));
    //auto-adjust
    renderer.setBoxWidth(-1);
}

From source file:msi.gama.outputs.layers.charts.ChartJFreeChartOutputScatter.java

@Override
public void createChart(final IScope scope) {
    super.createChart(scope);

    jfreedataset.add(0, new XYIntervalSeriesCollection());
    PlotOrientation orientation = PlotOrientation.VERTICAL;
    if (reverse_axes)
        orientation = PlotOrientation.HORIZONTAL;

    switch (type) {
    case SERIES_CHART: {
        chart = ChartFactory.createXYLineChart(getName(), "", "",
                (XYIntervalSeriesCollection) jfreedataset.get(0), orientation, true, false, false);
        break;//from w  ww.  ja  v a  2s  .  com
    }

    case XY_CHART:
        chart = ChartFactory.createXYLineChart(getName(), "", "",
                (XYIntervalSeriesCollection) jfreedataset.get(0), orientation, true, false, false);
        break;
    case SCATTER_CHART:
        chart = ChartFactory.createXYLineChart(getName(), "", "",
                (XYIntervalSeriesCollection) jfreedataset.get(0), orientation, true, false, false);
        break;
    case BOX_WHISKER_CHART: {
        chart = ChartFactory.createBoxAndWhiskerChart(getName(), "Time", "Value",
                (BoxAndWhiskerCategoryDataset) jfreedataset.get(0), true);
        chart.setBackgroundPaint(new Color(249, 231, 236));

        break;
    }

    }

}

From source file:gui.TraitViewerDialog.java

@SuppressWarnings("rawtypes")
private ChartPanel getChart(int selectedRow) {

    ArrayList<Float> data = new ArrayList<Float>();
    for (float[] row : tFile.getRows()) {
        if (row[selectedRow + 1] != (float) -99.0) {
            data.add(row[selectedRow + 1]);
        }/*from ww  w .ja  v  a  2 s.c  o m*/
    }
    BoxAndWhiskerItem a = BoxAndWhiskerCalculator.calculateBoxAndWhiskerStatistics(data);
    java.util.List l = new ArrayList(0);

    a = new BoxAndWhiskerItem(a.getMean(), a.getMedian(), a.getQ1(), a.getQ3(), a.getMinRegularValue(),
            a.getMaxRegularValue(), a.getMinRegularValue(), a.getMaxRegularValue(), l);
    traitstats.setText(showBoxAndWhiskerItem(a));

    DefaultBoxAndWhiskerCategoryDataset ds2 = new DefaultBoxAndWhiskerCategoryDataset();

    ds2.add(a, (Comparable) 1, (Comparable) 1);
    JFreeChart chart = ChartFactory.createBoxAndWhiskerChart(null, null, null, ds2, false);

    chart.removeLegend();

    // XYPlot plot = chart.getXYPlot();
    CategoryPlot plot = chart.getCategoryPlot();
    plot.getDomainAxis().setVisible(false);
    BoxAndWhiskerRenderer b = (BoxAndWhiskerRenderer) plot.getRenderer();
    // b.setFillBox(false);
    b.setSeriesPaint(0, new Color(236, 55, 169));
    b.setSeriesOutlinePaint(1, new Color(131, 79, 112));
    b.setBaseOutlineStroke(new BasicStroke(1.0f));
    // b.get
    b.setWhiskerWidth(0.8);
    b.setBaseOutlinePaint(new Color(84, 144, 201));
    b.setDefaultEntityRadius(2);
    b.setMaximumBarWidth(0.18);

    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPopupMenu(null);
    return chartPanel;
}

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

public static void logRelativeError(LinkedList<ParkingEventDetails> parkingEventDetails,
        String outputFileName) {//from ww  w  .j  a va2s . 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:fr.ens.transcriptome.corsen.gui.qt.ResultGraphs.java

/**
 * Create a box plot qimage.// www  .java  2  s . co  m
 * @param data Data to use
 * @return a QImage
 */
public QImage createBoxPlot(final double[] data, final String unit) {

    if (data == null || data.length < 2)
        return null;

    this.width = this.width / 2;

    List<Float> listData = new ArrayList<Float>(data.length);
    for (int i = 0; i < data.length; i++)
        listData.add((float) data[i]);

    DefaultBoxAndWhiskerCategoryDataset defaultboxandwhiskercategorydataset = new DefaultBoxAndWhiskerCategoryDataset();
    defaultboxandwhiskercategorydataset.add(listData, "Distances", "Min");

    JFreeChart chart = ChartFactory.createBoxAndWhiskerChart("Intensities Boxplot", "",
            "Distance" + unitLegend(unit), defaultboxandwhiskercategorydataset, false);

    addTransparency(chart);

    final BufferedImage image = chart.createBufferedImage(this.width, this.height, BufferedImage.TYPE_INT_ARGB,
            null);

    return new QImage(toByte(image.getData().getDataBuffer()), this.width, this.height,
            QImage.Format.Format_ARGB32);

}

From source file:fr.ens.transcriptome.corsen.gui.qt.ResultGraphs.java

/**
 * Create a boxplot.//from www.  j  a va 2s .  c  o m
 * @param results Results to use
 * @return a QImage
 */
public QImage createBoxPlot(final CorsenResult results, final String unit) {

    this.width = this.width / 2;

    Map<Particle3D, Distance> distsMin = results.getMinDistances();
    Map<Particle3D, Distance> distsMax = results.getMaxDistances();

    if (distsMin == null || distsMax == null)
        return null;

    List<Float> listMin = new ArrayList<Float>();
    List<Float> listMax = new ArrayList<Float>();

    for (Map.Entry<Particle3D, Distance> e : distsMin.entrySet()) {

        final Particle3D p = e.getKey();

        final long intensity = p.getIntensity();
        final float distanceMin = e.getValue().getDistance();
        final float distanceMax = distsMax.get(p).getDistance();

        for (int i = 0; i < intensity; i++) {
            listMin.add(distanceMin);
            listMax.add(distanceMax);
        }
    }

    DefaultBoxAndWhiskerCategoryDataset defaultboxandwhiskercategorydataset = new DefaultBoxAndWhiskerCategoryDataset();

    if (results.getMinAnalyser().count() > 0)
        defaultboxandwhiskercategorydataset
                .add(convertDistanceAnalyserToBoxAndWhiskerItem(results.getMinAnalyser()), "Distances", "Min");

    // defaultboxandwhiskercategorydataset.add(listMin, "Distances", "Min");
    // defaultboxandwhiskercategorydataset.add(listMax, "Distances", "Max");

    JFreeChart chart = ChartFactory.createBoxAndWhiskerChart("Intensities Boxplot", "",
            "Distance" + unitLegend(unit), defaultboxandwhiskercategorydataset, false);

    addTransparency(chart);

    // CategoryPlot categoryplot = (CategoryPlot) chart.getPlot();
    // // chart.setBackgroundPaint(Color.white);
    // categoryplot.setBackgroundPaint(Color.lightGray);
    // categoryplot.setDomainGridlinePaint(Color.white);
    // categoryplot.setDomainGridlinesVisible(true);
    // categoryplot.setRangeGridlinePaint(Color.white);
    //
    // NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    // numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    final BufferedImage image = chart.createBufferedImage(this.width, this.height, BufferedImage.TYPE_INT_ARGB,
            null);

    return new QImage(toByte(image.getData().getDataBuffer()), this.width, this.height,
            QImage.Format.Format_ARGB32);
}

From source file:net.sf.jsfcomp.chartcreator.utils.ChartUtils.java

public static JFreeChart createChartWithXYDataSet(ChartData chartData) {
    XYDataset dataset = (XYDataset) chartData.getDatasource();
    String type = chartData.getType();
    String xAxis = chartData.getXlabel();
    String yAxis = chartData.getYlabel();
    boolean legend = chartData.isLegend();

    JFreeChart chart = null;//from   w w w . j  a  va  2  s.c om
    PlotOrientation plotOrientation = ChartUtils.getPlotOrientation(chartData.getOrientation());

    if (type.equalsIgnoreCase("timeseries")) {
        chart = ChartFactory.createTimeSeriesChart("", xAxis, yAxis, dataset, legend, true, false);
    } else if (type.equalsIgnoreCase("xyline")) {
        chart = ChartFactory.createXYLineChart("", xAxis, yAxis, dataset, plotOrientation, legend, true, false);
    } else if (type.equalsIgnoreCase("polar")) {
        chart = ChartFactory.createPolarChart("", dataset, legend, true, false);
    } else if (type.equalsIgnoreCase("scatter")) {
        chart = ChartFactory.createScatterPlot("", xAxis, yAxis, dataset, plotOrientation, legend, true, false);
    } else if (type.equalsIgnoreCase("xyarea")) {
        chart = ChartFactory.createXYAreaChart("", xAxis, yAxis, dataset, plotOrientation, legend, true, false);
    } else if (type.equalsIgnoreCase("xysteparea")) {
        chart = ChartFactory.createXYStepAreaChart("", xAxis, yAxis, dataset, plotOrientation, legend, true,
                false);
    } else if (type.equalsIgnoreCase("xystep")) {
        chart = ChartFactory.createXYStepChart("", xAxis, yAxis, dataset, plotOrientation, legend, true, false);
    } else if (type.equalsIgnoreCase("bubble")) {
        chart = ChartFactory.createBubbleChart("", xAxis, yAxis, (XYZDataset) dataset, plotOrientation, legend,
                true, false);
    } else if (type.equalsIgnoreCase("candlestick")) {
        chart = ChartFactory.createCandlestickChart("", xAxis, yAxis, (OHLCDataset) dataset, legend);
    } else if (type.equalsIgnoreCase("boxandwhisker")) {
        chart = ChartFactory.createBoxAndWhiskerChart("", xAxis, yAxis, (BoxAndWhiskerXYDataset) dataset,
                legend);
    } else if (type.equalsIgnoreCase("highlow")) {
        chart = ChartFactory.createHighLowChart("", xAxis, yAxis, (OHLCDataset) dataset, legend);
    } else if (type.equalsIgnoreCase("histogram")) {
        chart = ChartFactory.createHistogram("", xAxis, yAxis, (IntervalXYDataset) dataset, plotOrientation,
                legend, true, false);
    } else if (type.equalsIgnoreCase("wind")) {
        chart = ChartFactory.createWindPlot("", xAxis, yAxis, (WindDataset) dataset, legend, true, false);
    }

    if (chart.getPlot() instanceof XYPlot) {
        chart.getXYPlot().setDomainGridlinesVisible(chartData.isDomainGridLines());
        chart.getXYPlot().setRangeGridlinesVisible(chartData.isRangeGridLines());

        if (chartData.getGenerateMap() != null)
            chart.getXYPlot().getRenderer().setURLGenerator(new StandardXYURLGenerator(""));
    }

    setXYSeriesColors(chart, chartData);

    setXYExtensions(chart, chartData);

    return chart;
}

From source file:jp.ac.tohoku.ecei.sb.metabolome.lims.gui.MainWindowController.java

public JFreeChart getChartForPlate(PlateImpl plate) {
    IntensityMatrixImpl intensityMatrix = dataManager.getIntensityMatrix();
    List<Injection> injections = intensityMatrix.getInjectionsByPlate().get(plate);

    DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset();
    for (Injection one : injections) {
        dataset.add(Arrays.asList(intensityMatrix.getColumn(one)).stream().map((o) -> ((Double) o))
                .collect(Collectors.toList()), "Intensity", one.toString());
    }/*from  w  ww  . j a  va 2  s  .c  om*/
    JFreeChart chart = ChartFactory.createBoxAndWhiskerChart(plate.toString(), "Injection", "Intensity",
            dataset, true);
    chart.getCategoryPlot().getDomainAxis()
            .setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 2));
    return chart;
}