Example usage for org.jfree.chart.axis ExtendedCategoryAxis addSubLabel

List of usage examples for org.jfree.chart.axis ExtendedCategoryAxis addSubLabel

Introduction

In this page you can find the example usage for org.jfree.chart.axis ExtendedCategoryAxis addSubLabel.

Prototype

public void addSubLabel(Comparable category, String label) 

Source Link

Document

Adds a sublabel for a category.

Usage

From source file:org.opennms.web.charts.ChartUtils.java

/**
 * @param barChart TODO/*from  w ww.  j  a  v  a  2 s .  c  o  m*/
 * @param subLabelClass
 */
private static void addSubLabels(JFreeChart barChart, String subLabelClass) {
    ExtendedCategoryAxis subLabels;
    CategoryPlot plot = barChart.getCategoryPlot();
    try {
        subLabels = (ExtendedCategoryAxis) Class.forName(subLabelClass).newInstance();
        List<?> cats = plot.getCategories();
        for (int i = 0; i < cats.size(); i++) {
            subLabels.addSubLabel((Comparable<?>) cats.get(i), cats.get(i).toString());
        }
        plot.setDomainAxis(subLabels);
    } catch (InstantiationException e) {
        LOG.error("getBarChart: Couldn't instantiate configured CategorySubLabels class: {}", subLabelClass, e);
    } catch (IllegalAccessException e) {
        LOG.error("getBarChart: Couldn't instantiate configured CategorySubLabels class: {}", subLabelClass, e);
    } catch (ClassNotFoundException e) {
        LOG.error("getBarChart: Couldn't instantiate configured CategorySubLabels class: {}", subLabelClass, e);
    }
}

From source file:org.opennms.netmgt.charts.ChartUtils.java

/**
 * @param barChart TODO/*  www. j  a  v  a  2s .co m*/
 * @param subLabelClass
 */
private static void addSubLabels(JFreeChart barChart, String subLabelClass) {
    ExtendedCategoryAxis subLabels;
    CategoryPlot plot = barChart.getCategoryPlot();
    try {
        subLabels = (ExtendedCategoryAxis) Class.forName(subLabelClass).newInstance();
        List<?> cats = plot.getCategories();
        for (int i = 0; i < cats.size(); i++) {
            subLabels.addSubLabel((Comparable<?>) cats.get(i), cats.get(i).toString());
        }
        plot.setDomainAxis(subLabels);
    } catch (InstantiationException e) {
        log().error("getBarChart: Couldn't instantiate configured CategorySubLabels class: " + subLabelClass,
                e);
    } catch (IllegalAccessException e) {
        log().error("getBarChart: Couldn't instantiate configured CategorySubLabels class: " + subLabelClass,
                e);
    } catch (ClassNotFoundException e) {
        log().error("getBarChart: Couldn't instantiate configured CategorySubLabels class: " + subLabelClass,
                e);
    }
}

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

/**
 * Creates a chart.//  www  .ja  v a 2s .  c  om
 * 
 * @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:org.jfree.chart.demo.SurveyResultsDemo3.java

/**
 * Creates a chart./*from   www  .  ja  va2 s.c om*/
 * 
 * @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;

}