Example usage for org.jfree.chart.renderer.category StatisticalBarRenderer setBaseToolTipGenerator

List of usage examples for org.jfree.chart.renderer.category StatisticalBarRenderer setBaseToolTipGenerator

Introduction

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

Prototype

@Override
public void setBaseToolTipGenerator(CategoryToolTipGenerator generator) 

Source Link

Document

Sets the base tool tip generator and sends a RendererChangeEvent to all registered listeners.

Usage

From source file:gov.nih.nci.cma.web.graphing.GEPlot.java

public String generateLog2Chart(String xAxisLabel, String yAxisLabel, HttpSession session, PrintWriter pw) {
    String log2Filename = "";

    JFreeChart log2Chart = null;/*from   ww  w.  j  av  a2s . com*/
    try {

        log2Chart = ChartFactory.createBarChart(null, xAxisLabel, // domain axis label
                yAxisLabel, log2Dataset, // 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 plot = log2Chart.getCategoryPlot();
        CategoryAxis axis = plot.getDomainAxis();
        axis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45);
        axis.setLowerMargin(0.02); // two percent
        axis.setCategoryMargin(0.20); // 20 percent
        axis.setUpperMargin(0.02); // two percent
        StatisticalBarRenderer renderer = new StatisticalBarRenderer();

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

            public String generateToolTip(CategoryDataset dataset, int series, int item) {
                String stdDev = (String) stdDevMap
                        .get(dataset.getRowKey(series) + "::" + dataset.getColumnKey(item));

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

        });

        // LegendTitle lg = chart.getLegend();
        plot.setRenderer(renderer);

        // lets generate a custom legend - assumes theres only one source?
        //LegendItemCollection lic = log2Chart.getLegend().getSources()[0].getLegendItems();
        //legendHtml = LegendCreator.buildLegend(lic, "Probesets");
        log2Chart.removeLegend();
        ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
        log2Filename = ServletUtilities.saveChartAsPNG(log2Chart, imgW, 400, info, session);
        ChartUtilities.writeImageMap(pw, log2Filename, info, new CustomOverlibToolTipTagFragmentGenerator(),
                new StandardURLTagFragmentGenerator());

    } catch (Exception e) {
        System.out.println("Exception - " + e.toString());
        e.printStackTrace(System.out);
    }
    return log2Filename;
}