Example usage for org.jfree.chart.renderer.category BarRenderer setItemMargin

List of usage examples for org.jfree.chart.renderer.category BarRenderer setItemMargin

Introduction

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

Prototype

public void setItemMargin(double percent) 

Source Link

Document

Sets the item margin and sends a RendererChangeEvent to all registered listeners.

Usage

From source file:org.jfree.chart.demo.GradientPaintTransformerDemo1.java

private static JFreeChart createChart(String s, CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createBarChart(s, null, "Value", categorydataset,
            PlotOrientation.VERTICAL, true, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setBackgroundPaint(Color.lightGray);
    categoryplot.setDomainGridlinePaint(Color.white);
    categoryplot.setRangeGridlinePaint(Color.white);
    categoryplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
    BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer();
    barrenderer.setItemMargin(0.02D);
    return jfreechart;
}

From source file:eu.delving.sip.base.ReportChartHelper.java

private static JPanel finishBarChart(JFreeChart chart, Color... colors) {
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    plot.setRangePannable(true);/*w ww. j av a  2 s.  c  o m*/
    if (colors.length > 0)
        plot.setRenderer(new CustomRenderer(colors));
    BarRenderer bar = (BarRenderer) plot.getRenderer();
    bar.setItemLabelAnchorOffset(9D);
    bar.setBaseItemLabelsVisible(true);
    bar.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    bar.setMaximumBarWidth(0.05);
    bar.setItemMargin(0.03D);
    bar.setBasePositiveItemLabelPosition(
            new ItemLabelPosition(INSIDE12, CENTER_RIGHT, CENTER_RIGHT, -1.5707963267948966D));
    bar.setPositiveItemLabelPositionFallback(
            new ItemLabelPosition(OUTSIDE12, CENTER_LEFT, CENTER_LEFT, -1.5707963267948966D));
    CategoryAxis x = plot.getDomainAxis();
    x.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90);
    x.setCategoryMargin(0.25D);
    x.setUpperMargin(0.02D);
    x.setLowerMargin(0.02D);
    NumberAxis y = (NumberAxis) plot.getRangeAxis();
    y.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    y.setUpperMargin(0.10000000000000001D);
    ChartUtilities.applyCurrentTheme(chart);
    return new ChartPanel(chart);
}

From source file:eu.delving.stats.ChartHelper.java

private static JFreeChart finishBarChart(JFreeChart chart, Color... colors) {
    CategoryPlot categoryplot = (CategoryPlot) chart.getPlot();
    categoryplot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    categoryplot.setRangePannable(true);
    if (colors.length > 0)
        categoryplot.setRenderer(new CustomRenderer(colors));
    BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer();
    barrenderer.setItemLabelAnchorOffset(9D);
    barrenderer.setBaseItemLabelsVisible(true);
    barrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    barrenderer.setMaximumBarWidth(0.05);
    barrenderer.setItemMargin(0.03D);
    ItemLabelPosition itemlabelposition = new ItemLabelPosition(INSIDE12, CENTER_RIGHT, CENTER_RIGHT,
            -1.5707963267948966D);//from  w w  w. jav a2  s . co m
    barrenderer.setBasePositiveItemLabelPosition(itemlabelposition);
    ItemLabelPosition itemlabelposition1 = new ItemLabelPosition(OUTSIDE12, CENTER_LEFT, CENTER_LEFT,
            -1.5707963267948966D);
    barrenderer.setPositiveItemLabelPositionFallback(itemlabelposition1);
    CategoryAxis categoryaxis = categoryplot.getDomainAxis();
    categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45);
    categoryaxis.setCategoryMargin(0.25D);
    categoryaxis.setUpperMargin(0.02D);
    categoryaxis.setLowerMargin(0.02D);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    numberaxis.setUpperMargin(0.10000000000000001D);
    ChartUtilities.applyCurrentTheme(chart);
    return chart;
}

From source file:org.pau.assetmanager.viewmodel.chart.PrepareChart.java

public static void prepareJFreeBarChartForStocks(JFreeChart jfchart, CategoryDataset categoryModel) {

    CategoryPlot categoryPlot = ((CategoryPlot) jfchart.getPlot());
    categoryPlot.getRangeAxis().resizeRange(1.2);
    categoryPlot.setBackgroundPaint(Color.WHITE);
    categoryPlot.setDomainGridlinePaint(Color.WHITE);
    categoryPlot.setRangeMinorGridlinePaint(Color.WHITE);
    categoryPlot.setRangeGridlinePaint(Color.BLACK);
    BarRenderer renderer = (BarRenderer) categoryPlot.getRenderer();

    renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());

    renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2} {1} ",
            NumberFomatter.PERCENTAGE_FORMATTER, NumberFormat.getPercentInstance()));
    renderer.setBaseItemLabelsVisible(true);
    renderer.setBaseItemLabelFont(new Font("Serif", Font.PLAIN, 12));
    renderer.setItemLabelAnchorOffset(15);

    renderer.setDrawBarOutline(false);/*from   w ww .j  a va 2s  .c o m*/
    renderer.setShadowVisible(false);
    renderer.setItemMargin(.1);
    renderer.setBarPainter(new StandardBarPainter());

}

From source file:gov.nih.nci.rembrandt.web.graphing.data.GeneExpressionPlot.java

public static HashMap generateBarChart(String gene, String reporter, HttpSession session, PrintWriter pw,
        GeneExpressionDataSetType geType) {
    String log2Filename = null;//w  w  w  . j  a  v a 2s.  c  o m
    String rawFilename = null;
    String medianFilename = null;
    String bwFilename = "";
    String legendHtml = null;
    HashMap charts = new HashMap();
    PlotSize ps = PlotSize.MEDIUM;

    final String geneName = gene;
    final String alg = geType.equals(GeneExpressionDataSetType.GeneExpressionDataSet)
            ? RembrandtConstants.REPORTER_SELECTION_AFFY
            : RembrandtConstants.REPORTER_SELECTION_UNI;
    try {
        InstitutionCriteria institutionCriteria = InsitutionAccessHelper.getInsititutionCriteria(session);

        final GenePlotDataSet gpds = new GenePlotDataSet(gene, reporter, institutionCriteria, geType,
                session.getId());
        //final GenePlotDataSet gpds = new GenePlotDataSet(gene, institutionCriteria,GeneExpressionDataSetType.GeneExpressionDataSet );

        //LOG2 Dataset
        DefaultStatisticalCategoryDataset dataset = (DefaultStatisticalCategoryDataset) gpds.getLog2Dataset();

        //RAW Dataset
        CategoryDataset meanDataset = (CategoryDataset) gpds.getRawDataset();

        //B&W dataset
        DefaultBoxAndWhiskerCategoryDataset bwdataset = (DefaultBoxAndWhiskerCategoryDataset) gpds
                .getBwdataset();

        //Median dataset
        CategoryDataset medianDataset = (CategoryDataset) gpds.getMedianDataset();

        charts.put("diseaseSampleCountMap", gpds.getDiseaseSampleCountMap());

        //IMAGE Size Control
        if (bwdataset != null && bwdataset.getRowCount() > 5) {
            ps = PlotSize.LARGE;
        } else {
            ps = PlotSize.MEDIUM;
        }
        //SMALL/MEDIUM == 650 x 400
        //LARGE == 1000 x 400
        //put as external Props?
        int imgW = 650;
        if (ps == PlotSize.LARGE) {
            imgW = new BigDecimal(bwdataset.getRowCount()).multiply(new BigDecimal(75)).intValue() > 1000
                    ? new BigDecimal(bwdataset.getRowCount()).multiply(new BigDecimal(75)).intValue()
                    : 1000;
        }

        JFreeChart bwChart = null;

        //B&W plot
        CategoryAxis xAxis = new CategoryAxis("Disease Type");
        NumberAxis yAxis = new NumberAxis("Log2 Expression Intensity");
        yAxis.setAutoRangeIncludesZero(true);
        BoxAndWhiskerCoinPlotRenderer bwRenderer = null;
        // BoxAndWhiskerRenderer bwRenderer = new BoxAndWhiskerRenderer();
        if (reporter != null) {
            //single reporter, show the coins
            bwRenderer = new BoxAndWhiskerCoinPlotRenderer(gpds.getCoinHash());
            bwRenderer.setDisplayCoinCloud(true);
            bwRenderer.setDisplayMean(false);
            bwRenderer.setDisplayAllOutliers(true);
            bwRenderer.setToolTipGenerator(new CategoryToolTipGenerator() {
                public String generateToolTip(CategoryDataset dataset, int series, int item) {
                    String tt = "";
                    NumberFormat formatter = new DecimalFormat(".####");
                    String key = "";
                    //String s = formatter.format(-1234.567);  // -001235
                    if (dataset instanceof DefaultBoxAndWhiskerCategoryDataset) {
                        DefaultBoxAndWhiskerCategoryDataset ds = (DefaultBoxAndWhiskerCategoryDataset) dataset;
                        try {
                            String med = formatter.format(ds.getMedianValue(series, item));
                            tt += "Median: " + med + "<br/>";
                            tt += "Mean: " + formatter.format(ds.getMeanValue(series, item)) + "<br/>";
                            tt += "Q1: " + formatter.format(ds.getQ1Value(series, item)) + "<br/>";
                            tt += "Q3: " + formatter.format(ds.getQ3Value(series, item)) + "<br/>";
                            tt += "Max: " + formatter.format(
                                    FaroutOutlierBoxAndWhiskerCalculator.getMaxFaroutOutlier(ds, series, item))
                                    + "<br/>";
                            tt += "Min: " + formatter.format(
                                    FaroutOutlierBoxAndWhiskerCalculator.getMinFaroutOutlier(ds, series, item))
                                    + "<br/>";
                            //tt += "<br/><br/>Please click on the box and whisker to view a plot for this reporter.<br/>";
                            //tt += "X: " + ds.getValue(series, item).toString()+"<br/>";
                            //tt += "<br/><a href=\\\'#\\\' id=\\\'"+ds.getRowKeys().get(series)+"\\\' onclick=\\\'alert(this.id);return false;\\\'>"+ds.getRowKeys().get(series)+" plot</a><br/><br/>";
                            key = ds.getRowKeys().get(series).toString();
                        } catch (Exception e) {
                        }
                    }

                    return tt;
                }

            });
        } else {
            //groups, dont show coins
            bwRenderer = new BoxAndWhiskerCoinPlotRenderer();
            bwRenderer.setDisplayAllOutliers(true);
            bwRenderer.setToolTipGenerator(new CategoryToolTipGenerator() {
                public String generateToolTip(CategoryDataset dataset, int series, int item) {
                    String tt = "";
                    NumberFormat formatter = new DecimalFormat(".####");
                    String key = "";
                    //String s = formatter.format(-1234.567);  // -001235
                    if (dataset instanceof DefaultBoxAndWhiskerCategoryDataset) {
                        DefaultBoxAndWhiskerCategoryDataset ds = (DefaultBoxAndWhiskerCategoryDataset) dataset;
                        try {
                            String med = formatter.format(ds.getMedianValue(series, item));
                            tt += "Median: " + med + "<br/>";
                            tt += "Mean: " + formatter.format(ds.getMeanValue(series, item)) + "<br/>";
                            tt += "Q1: " + formatter.format(ds.getQ1Value(series, item)) + "<br/>";
                            tt += "Q3: " + formatter.format(ds.getQ3Value(series, item)) + "<br/>";
                            tt += "Max: " + formatter.format(
                                    FaroutOutlierBoxAndWhiskerCalculator.getMaxFaroutOutlier(ds, series, item))
                                    + "<br/>";
                            tt += "Min: " + formatter.format(
                                    FaroutOutlierBoxAndWhiskerCalculator.getMinFaroutOutlier(ds, series, item))
                                    + "<br/>";
                            tt += "<br/><br/>Please click on the box and whisker to view a plot for this reporter.<br/>";
                            //tt += "X: " + ds.getValue(series, item).toString()+"<br/>";
                            //tt += "<br/><a href=\\\'#\\\' id=\\\'"+ds.getRowKeys().get(series)+"\\\' onclick=\\\'alert(this.id);return false;\\\'>"+ds.getRowKeys().get(series)+" plot</a><br/><br/>";
                            key = ds.getRowKeys().get(series).toString();
                        } catch (Exception e) {
                        }
                    }
                    return "onclick=\"popCoin('" + geneName + "','" + key + "', '" + alg + "');\" | " + tt;

                }

            });
        }
        bwRenderer.setFillBox(false);

        CategoryPlot bwPlot = new CategoryPlot(bwdataset, xAxis, yAxis, bwRenderer);
        bwChart = new JFreeChart(bwPlot);

        //    JFreeChart bwChart = new JFreeChart(
        //       null /*"Gene Expression Plot (" + gene.toUpperCase() + ")"*/,
        //        new Font("SansSerif", Font.BOLD, 14),
        //        bwPlot,
        //        true
        //    );

        bwChart.setBackgroundPaint(java.awt.Color.white);
        //bwChart.getTitle().setHorizontalAlignment(TextTitle.DEFAULT_HORIZONTAL_ALIGNMENT.LEFT);

        bwChart.removeLegend();
        //END BW plot

        // create the chart...for LOG2 dataset
        JFreeChart log2Chart = ChartFactory.createBarChart(
                null /*"Gene Expression Plot (" + gene.toUpperCase() + ")"*/, // chart
                // title
                "Groups", // domain axis label
                "Log2 Expression Intensity", // range axis label
                dataset, // data
                PlotOrientation.VERTICAL, // orientation
                true, // include legend
                true, // tooltips?
                false // URLs?
        );

        //create the chart .... for RAW dataset
        JFreeChart meanChart = ChartFactory.createBarChart(
                null /*"Gene Expression Plot (" + gene.toUpperCase() + ")"*/, // chart
                // title
                "Groups", // domain axis label
                "Mean Expression Intensity", // range axis label
                meanDataset, // data
                PlotOrientation.VERTICAL, // orientation
                true, // include legend
                true, // tooltips?
                false // URLs?
        );

        //         create the chart .... for Median dataset
        JFreeChart medianChart = ChartFactory.createBarChart(
                null /*"Gene Expression Plot (" + gene.toUpperCase() + ")"*/, // chart
                // title
                "Groups", // domain axis label
                "Median Expression Intensity", // range axis label
                medianDataset, // data
                PlotOrientation.VERTICAL, // orientation
                true, // include legend
                true, // tooltips?
                false // URLs?
        );

        log2Chart.setBackgroundPaint(java.awt.Color.white);
        // lets start some customization to retro fit w/jcharts lookand feel
        CategoryPlot log2Plot = log2Chart.getCategoryPlot();
        CategoryAxis log2Axis = log2Plot.getDomainAxis();
        log2Axis.setLowerMargin(0.02); // two percent
        log2Axis.setCategoryMargin(0.20); // 20 percent
        log2Axis.setUpperMargin(0.02); // two percent

        // same for our fake chart - just to get the tooltips
        meanChart.setBackgroundPaint(java.awt.Color.white);
        CategoryPlot meanPlot = meanChart.getCategoryPlot();
        CategoryAxis meanAxis = meanPlot.getDomainAxis();
        meanAxis.setLowerMargin(0.02); // two percent
        meanAxis.setCategoryMargin(0.20); // 20 percent
        meanAxis.setUpperMargin(0.02); // two percent

        //   median plot
        medianChart.setBackgroundPaint(java.awt.Color.white);
        CategoryPlot medianPlot = medianChart.getCategoryPlot();
        CategoryAxis medianAxis = medianPlot.getDomainAxis();
        medianAxis.setLowerMargin(0.02); // two percent
        medianAxis.setCategoryMargin(0.20); // 20 percent
        medianAxis.setUpperMargin(0.02); // two percent

        // customise the renderer...
        StatisticalBarRenderer log2Renderer = new StatisticalBarRenderer();

        // BarRenderer renderer = (BarRenderer) plot.getRenderer();
        log2Renderer.setItemMargin(0.01); // one percent
        log2Renderer.setDrawBarOutline(true);
        log2Renderer.setOutlinePaint(Color.BLACK);
        log2Renderer.setToolTipGenerator(new CategoryToolTipGenerator() {

            public String generateToolTip(CategoryDataset dataset, int series, int item) {
                HashMap pv = gpds.getPValuesHashMap();
                HashMap std_d = gpds.getStdDevMap();

                String currentPV = (String) pv
                        .get(dataset.getRowKey(series) + "::" + dataset.getColumnKey(item));
                String stdDev = (String) std_d
                        .get(dataset.getRowKey(series) + "::" + dataset.getColumnKey(item));

                return "Probeset : " + dataset.getRowKey(series) + "<br/>Intensity : "
                        + new DecimalFormat("0.0000").format(dataset.getValue(series, item)) + "<br/>"
                        + RembrandtConstants.PVALUE + " : " + currentPV + "<br/>Std. Dev.: " + stdDev + "<br/>";
            }

        });
        log2Plot.setRenderer(log2Renderer);
        // customize the  renderer
        BarRenderer meanRenderer = (BarRenderer) meanPlot.getRenderer();
        meanRenderer.setItemMargin(0.01); // one percent
        meanRenderer.setDrawBarOutline(true);
        meanRenderer.setOutlinePaint(Color.BLACK);
        meanRenderer.setToolTipGenerator(new CategoryToolTipGenerator() {

            public String generateToolTip(CategoryDataset dataset, int series, int item) {
                HashMap pv = gpds.getPValuesHashMap();
                HashMap std_d = gpds.getStdDevMap();
                String currentPV = (String) pv
                        .get(dataset.getRowKey(series) + "::" + dataset.getColumnKey(item));

                String stdDev = (String) std_d
                        .get(dataset.getRowKey(series) + "::" + dataset.getColumnKey(item));

                return "Probeset : " + dataset.getRowKey(series) + "<br/>Intensity : "
                        + new DecimalFormat("0.0000").format(dataset.getValue(series, item)) + "<br/>"
                        + RembrandtConstants.PVALUE + ": " + currentPV + "<br/>";
                //"<br/>Std. Dev.: " + stdDev + "<br/>";
            }

        });

        meanPlot.setRenderer(meanRenderer);
        // customize the  renderer
        BarRenderer medianRenderer = (BarRenderer) medianPlot.getRenderer();
        medianRenderer.setItemMargin(0.01); // one percent
        medianRenderer.setDrawBarOutline(true);
        medianRenderer.setOutlinePaint(Color.BLACK);
        medianRenderer.setToolTipGenerator(new CategoryToolTipGenerator() {

            public String generateToolTip(CategoryDataset dataset, int series, int item) {
                HashMap pv = gpds.getPValuesHashMap();
                HashMap std_d = gpds.getStdDevMap();
                String currentPV = (String) pv
                        .get(dataset.getRowKey(series) + "::" + dataset.getColumnKey(item));

                String stdDev = (String) std_d
                        .get(dataset.getRowKey(series) + "::" + dataset.getColumnKey(item));

                return "Probeset : " + dataset.getRowKey(series) + "<br/>Intensity : "
                        + new DecimalFormat("0.0000").format(dataset.getValue(series, item)) + "<br/>"
                        + RembrandtConstants.PVALUE + ": " + currentPV + "<br/>";
                //"<br/>Std. Dev.: " + stdDev + "<br/>";
            }

        });

        // LegendTitle lg = chart.getLegend();

        medianPlot.setRenderer(medianRenderer);
        // lets generate a custom legend - assumes theres only one source?
        LegendItemCollection lic = log2Chart.getLegend().getSources()[0].getLegendItems();
        legendHtml = LegendCreator.buildLegend(lic, "Probesets");

        log2Chart.removeLegend();
        meanChart.removeLegend();
        medianChart.removeLegend();

        //bwChart.removeLegend(); // <-- do this above

        // Write the chart image to the temporary directory
        ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());

        // BW
        if (bwChart != null) {
            int bwwidth = new BigDecimal(1.5).multiply(new BigDecimal(imgW)).intValue();
            bwFilename = ServletUtilities.saveChartAsPNG(bwChart, bwwidth, 400, info, session);
            CustomOverlibToolTipTagFragmentGenerator ttip = new CustomOverlibToolTipTagFragmentGenerator();
            String toolTip = " href='javascript:void(0);' alt='GeneChart JFreechart Plot' ";
            ttip.setExtra(toolTip); //must have href for area tags to have cursor:pointer
            ChartUtilities.writeImageMap(pw, bwFilename, info, ttip, new StandardURLTagFragmentGenerator());
            info.clear(); // lose the first one
            info = new ChartRenderingInfo(new StandardEntityCollection());
        }
        //END  BW
        log2Filename = ServletUtilities.saveChartAsPNG(log2Chart, imgW, 400, info, session);
        CustomOverlibToolTipTagFragmentGenerator ttip = new CustomOverlibToolTipTagFragmentGenerator();
        String toolTip = " alt='GeneChart JFreechart Plot' ";
        ttip.setExtra(toolTip); //must have href for area tags to have cursor:pointer
        ChartUtilities.writeImageMap(pw, log2Filename, info, ttip, new StandardURLTagFragmentGenerator());
        // clear the first one and overwrite info with our second one - no
        // error bars
        info.clear(); // lose the first one
        info = new ChartRenderingInfo(new StandardEntityCollection());
        rawFilename = ServletUtilities.saveChartAsPNG(meanChart, imgW, 400, info, session);
        // Write the image map to the PrintWriter
        // can use a different writeImageMap to pass tooltip and URL custom
        ttip = new CustomOverlibToolTipTagFragmentGenerator();
        toolTip = " alt='GeneChart JFreechart Plot' ";
        ttip.setExtra(toolTip); //must have href for area tags to have cursor:pointer
        ChartUtilities.writeImageMap(pw, rawFilename, info, ttip, new StandardURLTagFragmentGenerator());

        info.clear(); // lose the first one
        info = new ChartRenderingInfo(new StandardEntityCollection());
        medianFilename = ServletUtilities.saveChartAsPNG(medianChart, imgW, 400, info, session);

        // Write the image map to the PrintWriter
        // can use a different writeImageMap to pass tooltip and URL custom
        ttip = new CustomOverlibToolTipTagFragmentGenerator();
        toolTip = " alt='GeneChart JFreechart Plot' ";
        ttip.setExtra(toolTip); //must have href for area tags to have cursor:pointer
        ChartUtilities.writeImageMap(pw, medianFilename, info, ttip, new StandardURLTagFragmentGenerator());

        // ChartUtilities.writeImageMap(pw, filename, info, true);

        pw.flush();

    } catch (Exception e) {
        System.out.println("Exception - " + e.toString());
        e.printStackTrace(System.out);
        log2Filename = "public_error_500x300.png";
    }
    // return filename;
    charts.put("errorBars", log2Filename);
    charts.put("noErrorBars", rawFilename);
    charts.put("medianBars", medianFilename);
    charts.put("bwFilename", bwFilename);
    charts.put("legend", legendHtml);
    charts.put("size", ps.toString());

    return charts;
}

From source file:lu.lippmann.cdb.weka.SilhouetteUtil.java

/**
 * //from   w  w w. j ava  2s .c  om
 * @param sils
 * @return
 */
public static JPanel buildSilhouettePanel(final Instances ds, final WekaClusteringResult result) {

    final Map<Integer, List<Double>> sils = computeSilhouette(ds, result);

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    final JFreeChart chart = ChartFactory.createBarChart("Silhouette", "Category", "Value", dataset,
            PlotOrientation.HORIZONTAL, true, true, false);

    int nbClass = sils.keySet().size();

    int id = 0;
    double minValue = 0;

    int counter[][] = new int[nbClass][4];
    for (int i = 0; i < nbClass; i++) {

        final double[] tree = ArrayUtils.toPrimitive(sils.get(i).toArray(new Double[0]));

        for (double val : tree) {
            if (val > 0.75) {
                dataset.addValue(val, "Cluster " + i + " ++", "" + id);
                counter[i][0]++;
            } else if (val > 0.50) {
                dataset.addValue(val, "Cluster " + i + " +", "" + id);
                counter[i][1]++;
            } else if (val > 0.25) {
                dataset.addValue(val, "Cluster " + i + " =", "" + id);
                counter[i][2]++;
            } else {
                dataset.addValue(val, "Cluster " + i + " -", "" + id);
                counter[i][3]++;
            }
            if (val < minValue) {
                minValue = val;
            }
            id++;
        }

    }

    final CategoryPlot categoryplot = (CategoryPlot) chart.getPlot();
    categoryplot.setBackgroundPaint(Color.WHITE);
    categoryplot.getDomainAxis().setVisible(false);
    categoryplot.setDomainGridlinesVisible(false);
    categoryplot.setRangeGridlinesVisible(false);
    categoryplot.getRangeAxis().setRange(minValue, 1.0);

    //Add line markers
    ValueMarker target = new ValueMarker(0.75);
    target.setPaint(Color.BLACK);
    target.setLabel("  ++");
    target.setLabelAnchor(RectangleAnchor.TOP_LEFT);
    target.setLabelTextAnchor(TextAnchor.TOP_LEFT);
    categoryplot.addRangeMarker(target);

    target = new ValueMarker(0.5);
    target.setPaint(Color.BLACK);
    target.setLabel("  +");
    target.setLabelAnchor(RectangleAnchor.TOP_LEFT);
    target.setLabelTextAnchor(TextAnchor.TOP_LEFT);
    categoryplot.addRangeMarker(target);

    target = new ValueMarker(0.25);
    target.setPaint(Color.BLACK);
    target.setLabel("  =");
    target.setLabelAnchor(RectangleAnchor.TOP_LEFT);
    target.setLabelTextAnchor(TextAnchor.TOP_LEFT);
    categoryplot.addRangeMarker(target);

    target = new ValueMarker(0);
    target.setPaint(Color.BLACK);
    target.setLabel("  -");
    target.setLabelAnchor(RectangleAnchor.TOP_LEFT);
    target.setLabelTextAnchor(TextAnchor.TOP_LEFT);
    categoryplot.addRangeMarker(target);

    //Remove visual effects on bar
    final BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer();
    barrenderer.setBarPainter(new StandardBarPainter());

    //set bar colors
    int p = 0;
    final int max = ColorHelper.COLORBREWER_SEQUENTIAL_PALETTES.size();

    for (int i = 0; i < nbClass; i++) {
        final Color[] color = new ArrayList<Color[]>(ColorHelper.COLORBREWER_SEQUENTIAL_PALETTES.values())
                .get((max - i) % max);
        final int nbColors = color.length;
        for (int k = 0; k < counter[i].length; k++) {
            if (counter[i][k] > 0)
                barrenderer.setSeriesPaint(p++, color[(nbColors - k - 3) % nbColors]);
        }
    }

    //remove blank line between bars
    barrenderer.setItemMargin(-dataset.getRowCount());

    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setMouseWheelEnabled(true);
    chartPanel.setPreferredSize(new Dimension(1200, 900));
    chartPanel.setBorder(new TitledBorder("Silhouette plot"));
    chartPanel.setBackground(Color.WHITE);
    chart.setTitle("");
    return chartPanel;

}

From source file:com.jtk.pengelolaanujian.view.dashboard.PipePanelSample.java

private ChartPanel createChart(DefaultCategoryDataset data) {
    barchart = ChartFactory.createBarChart3D("Data Keterlambatan pengelolaan Soal Ujian", "Aktifitas",
            "Jumlah Keterlambatan", data, PlotOrientation.VERTICAL, true, true, false);
    barchart.setBackgroundPaint(new Color(135, 206, 250));
    CategoryPlot plot = (CategoryPlot) barchart.getPlot();
    plot.setNoDataMessage("Data Tidak ada");
    CategoryAxis axis = plot.getDomainAxis();
    axis.setCategoryLabelPositions(CategoryLabelPositions.STANDARD);
    CategoryItemRenderer renderer = plot.getRenderer();
    renderer.setBaseItemLabelsVisible(true);
    BarRenderer barRenderer = (BarRenderer) renderer;
    barRenderer.setItemMargin(0.1D);
    barRenderer.setDrawBarOutline(true);
    return new ChartPanel(barchart);
}

From source file:org.matsim.core.utils.charts.BarChart.java

/**
 * Creates a new BarChart with the specified category-labels.
 *
 * @param title/*from   www  .  j  a  v a 2  s.co m*/
 * @param xAxisLabel
 * @param yAxisLabel
 * @param categories
 */
public BarChart(final String title, final String xAxisLabel, final String yAxisLabel,
        final String[] categories) {
    super(title, xAxisLabel, yAxisLabel);
    this.dataset = new DefaultCategoryDataset();
    this.chart = createChart(title, xAxisLabel, yAxisLabel, this.dataset);
    this.plot = this.chart.getCategoryPlot();
    this.categories = categories.clone();

    addDefaultFormatting();

    // leave a gap of 20% between categories (groups of bars)
    final CategoryAxis axis1 = this.plot.getDomainAxis();
    axis1.setCategoryMargin(0.20);

    // leave a gap of 10% between individual bars within one category
    BarRenderer renderer = (BarRenderer) this.plot.getRenderer();
    renderer.setItemMargin(0.10);
}

From source file:org.matsim.core.utils.charts.StackedBarChart.java

/**
 * Creates a new BarChart with the specified category-labels.
 *
 * @param title/*from  w w  w. j  a  va  2s  . c  o  m*/
 * @param xAxisLabel
 * @param yAxisLabel
 * @param categories
 */
public StackedBarChart(final String title, final String xAxisLabel, final String yAxisLabel,
        final String[] categories) {
    super(title, xAxisLabel, yAxisLabel);
    this.dataset = new DefaultCategoryDataset();
    this.chart = createChart(title, xAxisLabel, yAxisLabel, this.dataset);
    this.plot = this.chart.getCategoryPlot();
    this.categories = categories.clone();

    addDefaultFormatting();

    // leave a gap of 20% between categories (groups of bars)
    final CategoryAxis axis1 = this.plot.getDomainAxis();
    axis1.setCategoryMargin(0.20);

    // leave a gap of 10% between individual bars within one category
    BarRenderer renderer = (BarRenderer) this.plot.getRenderer();
    renderer.setItemMargin(0.10);
}

From source file:app.Histogram.java

public void histogramDesign(JFreeChart chart) {
    final CategoryPlot plot = chart.getCategoryPlot();
    final BarRenderer renderer = (BarRenderer) plot.getRenderer();

    renderer.setDrawBarOutline(false);//from   w  w w .j  a  v  a 2 s  . co  m
    renderer.setItemMargin(0.10);
    renderer.setShadowVisible(false);

    final GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.black, 0.0f, 0.0f, Color.black);

    final org.jfree.chart.axis.CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setLowerMargin(0.02);
    domainAxis.setUpperMargin(0.02);
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(1));

    renderer.setSeriesPaint(0, gp0);
    plot.setBackgroundPaint(Color.white);
    plot.setRangeGridlinePaint(Color.black);
    plot.setRenderer(renderer);

    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(650, 500));

    JPanel panelJPanel = new JPanel();
    panelJPanel.removeAll();
    //panelJComboBox.removeAll();
    PlotWindow hist = new PlotWindow();
    hist.setVisible(true);
    // HistogtamWindow f = new HistogtamWindow();
    // HistogtamWindow f2 = f.getInstance();
    // f2.setVisible(true);
    // f2.getHistogramPanel().add(chartPanel);
    panelJPanel.add(chartPanel);
    hist.setContentPane(panelJPanel);
}