Example usage for org.jfree.chart.labels ItemLabelPosition ItemLabelPosition

List of usage examples for org.jfree.chart.labels ItemLabelPosition ItemLabelPosition

Introduction

In this page you can find the example usage for org.jfree.chart.labels ItemLabelPosition ItemLabelPosition.

Prototype

public ItemLabelPosition(ItemLabelAnchor itemLabelAnchor, TextAnchor textAnchor) 

Source Link

Document

Creates a new position record (with zero rotation).

Usage

From source file:loansystem.visual.panel.StartPage.java

private void dibujarGrafico(DefaultCategoryDataset datos, int tipoGrafico, String titulo, String ejeX,
        String ejeY, PlotOrientation orientacion, JPanel contenedor) {
    JFreeChart grafica = null;/*from w  ww  .  j a v a  2 s  .  c o  m*/

    switch (tipoGrafico) {
    case BAR:
        grafica = ChartFactory.createBarChart3D(titulo, ejeX, ejeY, datos, orientacion, true, true, false);
        break;
    case LINE:

        break;

    case PIE:

        break;
    }

    grafica.getTitle().setPaint(Color.black);

    CategoryPlot p = grafica.getCategoryPlot();
    p.setRangeGridlinePaint(Color.black);

    CategoryItemRenderer renderer = ((CategoryPlot) grafica.getPlot()).getRenderer();
    renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    renderer.setBaseItemLabelsVisible(true);
    ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_CENTER);
    renderer.setBasePositiveItemLabelPosition(position);

    int style = Font.BOLD;
    Font font = new Font("Tahoma", style, 12);
    renderer.setItemLabelFont(font);

    ChartPanel panel = new ChartPanel(grafica);
    contenedor.add(panel);
    contenedor.revalidate();
    contenedor.repaint();
}

From source file:edu.ucla.stat.SOCR.motionchart.MotionChart.java

/**
 * Creates a new chart with the given title and dataset.  The
 * <code>createLegend</code> argument specifies whether or not a legend
 * should be added to the chart./*  w ww.ja v  a  2 s. c  o m*/
 *
 * @param title        the chart title (<code>null</code> permitted).
 * @param titleFont    the font for displaying the chart title
 *                     (<code>null</code> permitted).
 * @param dataset       the dataset
 *                     (<code>null</code> not permitted).
 * @param createLegend a flag indicating whether or not a legend should
 *                     be created for the chart.
 */
public MotionChart(String title, Font titleFont, MotionDataSet dataset, boolean createLegend) {
    if (dataset == null) {
        throw new NullPointerException("Null 'dataset' argument.");
    }

    this.dataset = dataset;

    NumberAxis xAxis = new NumberAxis(dataset.getXLabel());
    xAxis.setAutoRangeIncludesZero(false);
    xAxis.setUpperMargin(0.20);
    NumberAxis yAxis = new NumberAxis(dataset.getYLabel());
    yAxis.setAutoRangeIncludesZero(false);
    yAxis.setUpperMargin(0.20);

    plot = new XYPlot(dataset, xAxis, yAxis, null);

    renderer = new MotionBubbleRenderer(dataset, XYBubbleRenderer.SCALE_ON_DOMAIN_AXIS);
    renderer.setBaseToolTipGenerator(new MotionToolTipGenerator());
    renderer.setBaseItemLabelGenerator(new MotionItemLabelGenerator());
    renderer.setBasePositiveItemLabelPosition(
            new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER));

    plot.setRenderer(renderer);
    plot.setOrientation(PlotOrientation.VERTICAL);

    dataset.addChangeListener(this);

    chart = new JFreeChart(title, titleFont, plot, createLegend);
    chart.addChangeListener(this);

    currentTheme.apply(chart);

    chartPanel = new ChartPanel(chart);
    chartPanel.addChartMouseListener(new MotionMouseListener());
}

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

/**
 * Creates a chart./*from www .j a  v  a 2 s . c  o m*/
 * 
 * @param dataset  the dataset.
 * 
 * @return The chart.
 */
private JFreeChart createChart(final CategoryDataset dataset) {

    final JFreeChart chart = ChartFactory.createBarChart(null, // chart title
            null, // domain axis label
            null, // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, false);

    chart.setBackgroundPaint(Color.white);
    chart.getPlot().setOutlinePaint(null);
    final TextTitle title = new TextTitle("Figure 8.5 - Case studies are available");
    title.setHorizontalAlignment(HorizontalAlignment.LEFT);
    title.setBackgroundPaint(Color.red);
    title.setPaint(Color.white);

    chart.setTitle(title);
    final CategoryPlot plot = chart.getCategoryPlot();

    final ValueAxis rangeAxis = plot.getRangeAxis();
    rangeAxis.setRange(0.0, 5.0);
    rangeAxis.setVisible(false);

    final ExtendedCategoryAxis domainAxis = new ExtendedCategoryAxis(null);
    domainAxis.setTickLabelFont(new Font("SansSerif", Font.BOLD, 12));
    domainAxis.setCategoryMargin(0.30);
    domainAxis.addSubLabel("Sm.", "(10)");
    domainAxis.addSubLabel("Med.", "(10)");
    domainAxis.addSubLabel("Lg.", "(10)");
    domainAxis.addSubLabel("All", "(10)");
    plot.setDomainAxis(domainAxis);

    final BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setSeriesPaint(0, new Color(0x9C, 0xA4, 0x4A));
    renderer.setBaseOutlineStroke(null);

    renderer.setItemLabelsVisible(true);
    renderer.setItemLabelFont(new Font("SansSerif", Font.PLAIN, 18));
    final ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.INSIDE12, TextAnchor.TOP_CENTER);
    renderer.setPositiveItemLabelPosition(position);
    renderer.setPositiveItemLabelPositionFallback(new ItemLabelPosition());

    return chart;

}

From source file:com.att.aro.main.TraceOverviewPanel.java

/**
 * Initializes the Main panel and its various components.
 *///from  ww  w .ja va2s  .c  om
private void initialize() {
    JFreeChart chart = ChartFactory.createBarChart(rb.getString("overview.traceoverview.title"), null, null,
            createDataset(null), PlotOrientation.HORIZONTAL, false, true, false);
    chart.setBackgroundPaint(this.getBackground());
    chart.getTitle().setFont(AROUIManager.HEADER_FONT);

    this.plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.gray);
    plot.setRangeGridlinePaint(Color.gray);
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);

    CategoryAxis valueRangeAxis = plot.getDomainAxis();
    valueRangeAxis.setMaximumCategoryLabelWidthRatio(1.0f);
    valueRangeAxis.setMaximumCategoryLabelLines(2);
    valueRangeAxis.setLabelFont(AROUIManager.LABEL_FONT);
    valueRangeAxis.setTickLabelFont(AROUIManager.LABEL_FONT);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setLabel(rb.getString("analysisresults.percentile"));
    rangeAxis.setRange(0.0, 100.0);
    rangeAxis.setTickUnit(new NumberTickUnit(10));
    rangeAxis.setLabelFont(AROUIManager.LABEL_FONT);
    rangeAxis.setTickLabelFont(AROUIManager.LABEL_FONT);

    BarRenderer renderer = new StackedBarRenderer();
    renderer.setBasePaint(AROUIManager.CHART_BAR_COLOR);
    renderer.setAutoPopulateSeriesPaint(false);
    renderer.setBaseItemLabelGenerator(new PercentLabelGenerator());
    renderer.setBaseItemLabelsVisible(true);
    renderer.setBaseItemLabelPaint(Color.black);

    // Make second bar in stack invisible
    renderer.setSeriesItemLabelsVisible(1, false);
    renderer.setSeriesPaint(1, new Color(0, 0, 0, 0));

    ItemLabelPosition insideItemlabelposition = new ItemLabelPosition(ItemLabelAnchor.INSIDE3,
            TextAnchor.CENTER_RIGHT);
    renderer.setBasePositiveItemLabelPosition(insideItemlabelposition);

    ItemLabelPosition outsideItemlabelposition = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3,
            TextAnchor.CENTER_LEFT);
    renderer.setPositiveItemLabelPositionFallback(outsideItemlabelposition);

    renderer.setBarPainter(new StandardBarPainter());
    renderer.setShadowVisible(false);
    renderer.setMaximumBarWidth(BAR_WIDTH_PERCENT);
    renderer.setBaseToolTipGenerator(new CategoryToolTipGenerator() {
        @Override
        public String generateToolTip(CategoryDataset arg0, int arg1, int arg2) {
            String traceInfo = "";
            switch (arg2) {
            case TRACE_AVERAGE:
                traceInfo = rb.getString("tooltip.traceAnalysis.avg");
                break;
            case TRACE_ENERGY:
                traceInfo = rb.getString("tooltip.traceAnalysis.engy");
                break;
            case TRACE_OVERHEAD:
                traceInfo = rb.getString("tooltip.traceAnalysis.ovrhd");
                break;
            }

            return traceInfo;
        }
    });

    plot.setRenderer(renderer);
    plot.getDomainAxis().setMaximumCategoryLabelLines(2);

    ChartPanel chartPanel = new ChartPanel(chart, WIDTH, HEIGHT, ChartPanel.DEFAULT_MINIMUM_DRAW_WIDTH + 100,
            100, ChartPanel.DEFAULT_MAXIMUM_DRAW_WIDTH, ChartPanel.DEFAULT_MAXIMUM_DRAW_HEIGHT, USER_BUFFER,
            PROPERTIES, COPY, SAVE, PRINT, ZOOM, TOOL_TIPS);
    chartPanel.setDomainZoomable(false);
    chartPanel.setRangeZoomable(false);
    this.add(chartPanel, BorderLayout.CENTER);
}

From source file:com.att.aro.main.ProperSessionTerminationPanel.java

/**
 * Initializes the Panel for Proper Session Termination plot.
 *//* w  w w.jav a  2 s.  c o  m*/
private void initialize() {
    JFreeChart chart = ChartFactory.createBarChart(rb.getString("overview.sessionoverview.title"), null, null,
            createDataset(null), PlotOrientation.HORIZONTAL, false, false, false);
    chart.setBackgroundPaint(this.getBackground());
    chart.getTitle().setFont(AROUIManager.HEADER_FONT);

    this.plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.gray);
    plot.setRangeGridlinePaint(Color.gray);
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setMaximumCategoryLabelWidthRatio(1.0f);
    domainAxis.setMaximumCategoryLabelLines(2);
    domainAxis.setLabelFont(AROUIManager.LABEL_FONT);
    domainAxis.setTickLabelFont(AROUIManager.LABEL_FONT);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setLabel(rb.getString("analysisresults.percentage"));
    rangeAxis.setRange(0.0, 100.0);
    rangeAxis.setTickUnit(new NumberTickUnit(10));
    rangeAxis.setLabelFont(AROUIManager.LABEL_FONT);
    rangeAxis.setTickLabelFont(AROUIManager.LABEL_FONT);

    BarRenderer renderer = new StackedBarRenderer();
    renderer.setBasePaint(AROUIManager.CHART_BAR_COLOR);
    renderer.setAutoPopulateSeriesPaint(false);
    renderer.setBaseItemLabelGenerator(new PercentLabelGenerator());
    renderer.setBaseItemLabelsVisible(true);
    renderer.setBaseItemLabelPaint(Color.black);

    // Make second bar in stack invisible
    renderer.setSeriesItemLabelsVisible(1, false);
    renderer.setSeriesPaint(1, new Color(0, 0, 0, 0));

    ItemLabelPosition insideItemlabelposition = new ItemLabelPosition(ItemLabelAnchor.INSIDE3,
            TextAnchor.CENTER_RIGHT);
    renderer.setBasePositiveItemLabelPosition(insideItemlabelposition);

    ItemLabelPosition outsideItemlabelposition = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3,
            TextAnchor.CENTER_LEFT);
    renderer.setPositiveItemLabelPositionFallback(outsideItemlabelposition);

    renderer.setBarPainter(new StandardBarPainter());
    renderer.setShadowVisible(false);
    renderer.setMaximumBarWidth(BAR_WIDTH_PERCENT);

    renderer.setBaseToolTipGenerator(new CategoryToolTipGenerator() {
        @Override
        public String generateToolTip(CategoryDataset arg0, int arg1, int arg2) {
            String sessionInfo = "";
            switch (arg2) {
            case SESSION_TERMINATION:
                sessionInfo = rb.getString("tooltip.sessionTermination");
                break;
            case SESSION_TIGHT_CONN:
                sessionInfo = rb.getString("tooltip.sessionTightConn");
                break;
            case SESSION_BURST:
                sessionInfo = rb.getString("tooltip.sessionBurst");
                break;
            case SESSION_LONG_BURST:
                sessionInfo = rb.getString("tooltip.sessionLongBurst");
                break;
            }

            return sessionInfo;
        }
    });

    plot.setRenderer(renderer);
    plot.getDomainAxis().setMaximumCategoryLabelLines(2);

    ChartPanel chartPanel = new ChartPanel(chart, WIDTH, HEIGHT, ChartPanel.DEFAULT_MINIMUM_DRAW_WIDTH + 100,
            100, ChartPanel.DEFAULT_MAXIMUM_DRAW_WIDTH, ChartPanel.DEFAULT_MAXIMUM_DRAW_HEIGHT, USER_BUFFER,
            PROPERTIES, COPY, SAVE, PRINT, ZOOM, TOOL_TIPS);

    chartPanel.setDomainZoomable(false);
    chartPanel.setRangeZoomable(false);
    this.add(chartPanel, BorderLayout.CENTER);
}

From source file:org.drools.planner.benchmark.core.statistic.PlannerStatistic.java

private void writeBestScoreSummaryChart() {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (SolverBenchmark solverBenchmark : plannerBenchmark.getSolverBenchmarkList()) {
        ScoreDefinition scoreDefinition = solverBenchmark.getSolverConfig().getScoreDirectorFactoryConfig()
                .buildScoreDefinition();
        for (SingleBenchmark singleBenchmark : solverBenchmark.getSingleBenchmarkList()) {
            if (singleBenchmark.isSuccess()) {
                Score score = singleBenchmark.getScore();
                Double scoreGraphValue = scoreDefinition.translateScoreToGraphValue(score);
                String solverLabel = solverBenchmark.getName();
                if (solverBenchmark.isRankingBest()) {
                    solverLabel += " (winner)";
                }//from   w  w  w.  j  av  a 2s  .  c  o m
                String planningProblemLabel = singleBenchmark.getProblemBenchmark().getName();
                dataset.addValue(scoreGraphValue, solverLabel, planningProblemLabel);
            }
        }
    }
    CategoryAxis xAxis = new CategoryAxis("Data");
    xAxis.setCategoryMargin(0.40);
    NumberAxis yAxis = new NumberAxis("Score");
    BarRenderer renderer = new BarRenderer();
    ItemLabelPosition positiveItemLabelPosition = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12,
            TextAnchor.BOTTOM_CENTER);
    renderer.setBasePositiveItemLabelPosition(positiveItemLabelPosition);
    ItemLabelPosition negativeItemLabelPosition = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6,
            TextAnchor.TOP_CENTER);
    renderer.setBaseNegativeItemLabelPosition(negativeItemLabelPosition);
    renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    renderer.setBaseItemLabelsVisible(true);
    CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);
    plot.setOrientation(PlotOrientation.VERTICAL);
    JFreeChart chart = new JFreeChart("Best score summary (higher score is better)",
            JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    BufferedImage chartImage = chart.createBufferedImage(1024, 768);
    bestScoreSummaryFile = new File(plannerBenchmark.getBenchmarkReportDirectory(), "bestScoreSummary.png");
    OutputStream out = null;
    try {
        out = new FileOutputStream(bestScoreSummaryFile);
        ImageIO.write(chartImage, "png", out);
    } catch (IOException e) {
        throw new IllegalArgumentException("Problem writing bestScoreSummaryFile: " + bestScoreSummaryFile, e);
    } finally {
        IOUtils.closeQuietly(out);
    }
}

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

private static JFreeChart createChart(IntervalCategoryDataset intervalcategorydataset) {
    JFreeChart jfreechart = ChartFactory.createGanttChart("Gantt Chart Demo", "Task", "Date",
            intervalcategorydataset, true, true, false);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.getDomainAxis().setMaximumCategoryLabelWidthRatio(10F);
    DateAxis dateaxis = (DateAxis) categoryplot.getRangeAxis();
    dateaxis.setUpperMargin(0.20000000000000001D);
    GanttRenderer ganttrenderer = (GanttRenderer) categoryplot.getRenderer();
    ganttrenderer.setDrawBarOutline(false);
    ganttrenderer.setBaseItemLabelGenerator(new MyLabelGenerator(new SimpleDateFormat("d-MMM")));
    ganttrenderer.setBaseItemLabelsVisible(true);
    ganttrenderer.setBasePositiveItemLabelPosition(
            new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3, TextAnchor.CENTER_LEFT));
    return jfreechart;
}

From source file:com.att.aro.ui.view.overviewtab.TraceBenchmarkChartPanel.java

private JFreeChart initializeChart() {

    JFreeChart chart = ChartFactory.createBarChart(
            ResourceBundleHelper.getMessageString("overview.traceoverview.title"), null, null, createDataset(),
            PlotOrientation.HORIZONTAL, false, true, false);
    chart.setBackgroundPaint(this.getBackground());
    chart.getTitle().setFont(AROUIManager.HEADER_FONT);

    this.plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.gray);
    plot.setRangeGridlinePaint(Color.gray);
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);

    CategoryAxis valueRangeAxis = plot.getDomainAxis();
    valueRangeAxis.setMaximumCategoryLabelWidthRatio(1.0f);
    valueRangeAxis.setMaximumCategoryLabelLines(2);
    valueRangeAxis.setLabelFont(AROUIManager.LABEL_FONT);
    valueRangeAxis.setTickLabelFont(AROUIManager.LABEL_FONT);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setLabel(ResourceBundleHelper.getMessageString("analysisresults.percentile"));
    rangeAxis.setRange(0.0, 100.0);/*from www . j  a v  a  2  s.c om*/
    rangeAxis.setTickUnit(new NumberTickUnit(10));
    rangeAxis.setLabelFont(AROUIManager.LABEL_FONT);
    rangeAxis.setTickLabelFont(AROUIManager.LABEL_FONT);

    BarRenderer renderer = new StackedBarRenderer();
    renderer.setBasePaint(AROUIManager.CHART_BAR_COLOR);
    renderer.setAutoPopulateSeriesPaint(false);
    renderer.setBaseItemLabelGenerator(new PercentLabelGenerator());
    renderer.setBaseItemLabelsVisible(true);
    renderer.setBaseItemLabelPaint(Color.black);

    // Make second bar in stack invisible
    renderer.setSeriesItemLabelsVisible(1, false);
    renderer.setSeriesPaint(1, new Color(0, 0, 0, 0));

    ItemLabelPosition insideItemlabelposition = new ItemLabelPosition(ItemLabelAnchor.INSIDE3,
            TextAnchor.CENTER_RIGHT);
    renderer.setBasePositiveItemLabelPosition(insideItemlabelposition);

    ItemLabelPosition outsideItemlabelposition = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3,
            TextAnchor.CENTER_LEFT);
    renderer.setPositiveItemLabelPositionFallback(outsideItemlabelposition);

    renderer.setBarPainter(new StandardBarPainter());
    renderer.setShadowVisible(false);
    renderer.setMaximumBarWidth(BAR_WIDTH_PERCENT);
    renderer.setBaseToolTipGenerator(new CategoryToolTipGenerator() {
        @Override
        public String generateToolTip(CategoryDataset arg0, int arg1, int arg2) {
            String traceInfo = "";
            switch (arg2) {
            case TRACE_AVERAGE:
                traceInfo = ResourceBundleHelper.getMessageString("tooltip.traceAnalysis.avg");
                break;
            case TRACE_ENERGY:
                traceInfo = ResourceBundleHelper.getMessageString("tooltip.traceAnalysis.engy");
                break;
            case TRACE_OVERHEAD:
                traceInfo = ResourceBundleHelper.getMessageString("tooltip.traceAnalysis.ovrhd");
                break;
            default:
                break;
            }

            return traceInfo;
        }
    });

    plot.setRenderer(renderer);
    plot.getDomainAxis().setMaximumCategoryLabelLines(2);

    return chart;

}

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

/**
 * Creates a chart./*from   w  w w. j a va  2  s  .co m*/
 * 
 * @param dataset  the dataset.
 * 
 * @return The chart.
 */
private JFreeChart createChart(final CategoryDataset dataset) {

    final JFreeChart chart = ChartFactory.createBarChart(null, // chart title
            null, // domain axis label
            null, // range axis label
            dataset, // data
            PlotOrientation.HORIZONTAL, // orientation
            false, // include legend
            true, false);

    chart.setBackgroundPaint(Color.white);
    chart.getPlot().setOutlinePaint(null);
    final TextTitle title = new TextTitle("Figure 6 | Overall SEO Rating");
    title.setHorizontalAlignment(HorizontalAlignment.LEFT);
    title.setBackgroundPaint(Color.red);
    title.setPaint(Color.white);

    chart.setTitle(title);
    final CategoryPlot plot = chart.getCategoryPlot();

    final ValueAxis rangeAxis = plot.getRangeAxis();
    rangeAxis.setRange(0.0, 4.0);
    rangeAxis.setVisible(false);

    final ExtendedCategoryAxis domainAxis = new ExtendedCategoryAxis(null);
    domainAxis.setTickLabelFont(new Font("SansSerif", Font.BOLD, 12));
    domainAxis.setCategoryMargin(0.30);
    domainAxis.addSubLabel("Sm.", "(10)");
    domainAxis.addSubLabel("Med.", "(10)");
    domainAxis.addSubLabel("Lg.", "(10)");
    domainAxis.addSubLabel("All", "(10)");
    final CategoryLabelPositions p = domainAxis.getCategoryLabelPositions();
    final CategoryLabelPosition left = new CategoryLabelPosition(RectangleAnchor.LEFT,
            TextBlockAnchor.CENTER_LEFT);
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.replaceLeftPosition(p, left));
    plot.setDomainAxis(domainAxis);

    final BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setSeriesPaint(0, new Color(0x9C, 0xA4, 0x4A));
    renderer.setBaseOutlineStroke(null);

    //        final StandardCategoryLabelGenerator generator = new StandardCategoryLabelGenerator(
    //          "{2}", new DecimalFormat("0.00")
    //    );
    //  renderer.setLabelGenerator(generator);
    renderer.setItemLabelsVisible(true);
    renderer.setItemLabelFont(new Font("SansSerif", Font.PLAIN, 18));
    final ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.INSIDE3, TextAnchor.CENTER_RIGHT);
    renderer.setPositiveItemLabelPosition(position);
    renderer.setPositiveItemLabelPositionFallback(new ItemLabelPosition());

    return chart;

}

From source file:com.att.aro.ui.view.overviewtab.ConnectionStatisticsChartPanel.java

public JFreeChart initializeChart() {
    JFreeChart chart = ChartFactory.createBarChart(
            ResourceBundleHelper.getMessageString("overview.sessionoverview.title"), null, null,
            createDataset(), PlotOrientation.HORIZONTAL, false, false, false);
    chart.setBackgroundPaint(this.getBackground());
    chart.getTitle().setFont(AROUIManager.HEADER_FONT);

    this.plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.gray);
    plot.setRangeGridlinePaint(Color.gray);
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setMaximumCategoryLabelWidthRatio(1.0f);
    domainAxis.setMaximumCategoryLabelLines(2);
    domainAxis.setLabelFont(AROUIManager.LABEL_FONT);
    domainAxis.setTickLabelFont(AROUIManager.LABEL_FONT);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setLabel(ResourceBundleHelper.getMessageString("analysisresults.percentage"));
    rangeAxis.setRange(0.0, 100.0);//  w ww  .j a  v  a  2  s .  co m
    rangeAxis.setTickUnit(new NumberTickUnit(10));
    rangeAxis.setLabelFont(AROUIManager.LABEL_FONT);
    rangeAxis.setTickLabelFont(AROUIManager.LABEL_FONT);

    BarRenderer renderer = new StackedBarRenderer();
    renderer.setBasePaint(AROUIManager.CHART_BAR_COLOR);
    renderer.setAutoPopulateSeriesPaint(false);
    renderer.setBaseItemLabelGenerator(new PercentLabelGenerator());
    renderer.setBaseItemLabelsVisible(true);
    renderer.setBaseItemLabelPaint(Color.black);

    // Make second bar in stack invisible
    renderer.setSeriesItemLabelsVisible(1, false);
    renderer.setSeriesPaint(1, new Color(0, 0, 0, 0));

    ItemLabelPosition insideItemlabelposition = new ItemLabelPosition(ItemLabelAnchor.INSIDE3,
            TextAnchor.CENTER_RIGHT);
    renderer.setBasePositiveItemLabelPosition(insideItemlabelposition);

    ItemLabelPosition outsideItemlabelposition = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3,
            TextAnchor.CENTER_LEFT);
    renderer.setPositiveItemLabelPositionFallback(outsideItemlabelposition);

    renderer.setBarPainter(new StandardBarPainter());
    renderer.setShadowVisible(false);
    renderer.setMaximumBarWidth(BAR_WIDTH_PERCENT);

    renderer.setBaseToolTipGenerator(new CategoryToolTipGenerator() {
        @Override
        public String generateToolTip(CategoryDataset arg0, int arg1, int arg2) {
            String sessionInfo = "";
            switch (arg2) {
            case SESSION_TERMINATION:
                sessionInfo = ResourceBundleHelper.getMessageString("tooltip.sessionTermination");
                break;
            case SESSION_TIGHT_CONN:
                sessionInfo = ResourceBundleHelper.getMessageString("tooltip.sessionTightConn");
                break;
            case SESSION_BURST:
                sessionInfo = ResourceBundleHelper.getMessageString("tooltip.sessionBurst");
                break;
            case SESSION_LONG_BURST:
                sessionInfo = ResourceBundleHelper.getMessageString("tooltip.sessionLongBurst");
                break;
            default:
                break;
            }

            return sessionInfo;
        }
    });

    plot.setRenderer(renderer);
    plot.getDomainAxis().setMaximumCategoryLabelLines(2);

    return chart;
}