Example usage for org.jfree.chart.ui TextAnchor BOTTOM_CENTER

List of usage examples for org.jfree.chart.ui TextAnchor BOTTOM_CENTER

Introduction

In this page you can find the example usage for org.jfree.chart.ui TextAnchor BOTTOM_CENTER.

Prototype

TextAnchor BOTTOM_CENTER

To view the source code for org.jfree.chart.ui TextAnchor BOTTOM_CENTER.

Click Source Link

Document

Bottom/center.

Usage

From source file:org.jfree.graphics2d.demo.SVGBarChartDemo1.java

/**
 * Creates a sample chart./* w w w  .j a  va 2s  .c om*/
 *
 * @param dataset  a dataset.
 *
 * @return The chart.
 */
private static JFreeChart createChart(CategoryDataset dataset) {

    JFreeChart chart = ChartFactory.createLineChart("Statistical Bar Chart Demo 1", "Type", "Value", dataset);

    CategoryPlot plot = (CategoryPlot) chart.getPlot();

    // customise the range axis...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setAutoRangeIncludesZero(false);

    // customise the renderer...
    StatisticalBarRenderer renderer = new StatisticalBarRenderer();
    renderer.setDrawBarOutline(false);
    renderer.setErrorIndicatorPaint(Color.black);
    renderer.setIncludeBaseInRange(false);
    plot.setRenderer(renderer);

    // ensure the current theme is applied to the renderer just added
    ChartUtilities.applyCurrentTheme(chart);

    renderer.setDefaultItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    renderer.setDefaultItemLabelsVisible(true);
    renderer.setDefaultItemLabelPaint(Color.yellow);
    renderer.setDefaultPositiveItemLabelPosition(
            new ItemLabelPosition(ItemLabelAnchor.INSIDE6, TextAnchor.BOTTOM_CENTER));

    // set up gradient paints for series...
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64));
    GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0));
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    return chart;
}

From source file:org.jfree.graphics2d.demo.CanvasBarChartDemo1.java

/**
 * Creates a sample chart.//from w w  w.  j  av  a 2 s.  c  o  m
 *
 * @param dataset  a dataset.
 *
 * @return The chart.
 */
private static JFreeChart createChart(CategoryDataset dataset) {

    // create the chart...
    JFreeChart chart = ChartFactory.createLineChart("Statistical Bar Chart Demo 1", // chart title
            "Type", // domain axis label
            "Value", // range axis label
            dataset);

    CategoryPlot plot = (CategoryPlot) chart.getPlot();

    // customise the range axis...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setAutoRangeIncludesZero(false);

    // customise the renderer...
    StatisticalBarRenderer renderer = new StatisticalBarRenderer();
    renderer.setDrawBarOutline(false);
    renderer.setErrorIndicatorPaint(Color.black);
    renderer.setIncludeBaseInRange(false);
    plot.setRenderer(renderer);

    // ensure the current theme is applied to the renderer just added
    ChartUtilities.applyCurrentTheme(chart);

    renderer.setDefaultItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    renderer.setDefaultItemLabelsVisible(true);
    renderer.setDefaultItemLabelPaint(Color.yellow);
    renderer.setDefaultPositiveItemLabelPosition(
            new ItemLabelPosition(ItemLabelAnchor.INSIDE6, TextAnchor.BOTTOM_CENTER));

    // set up gradient paints for series...
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64));
    GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0));
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    return chart;
}

From source file:org.jfree.chart.ChartFactory.java

/**
 * Creates a bar chart with a vertical orientation.  The chart object
 * returned by this method uses a {@link CategoryPlot} instance as the
 * plot, with a {@link CategoryAxis} for the domain axis, a
 * {@link NumberAxis} as the range axis, and a {@link BarRenderer} as the
 * renderer.//from  w  w  w  . jav  a  2s  . c om
 *
 * @param title  the chart title ({@code null} permitted).
 * @param categoryAxisLabel  the label for the category axis ({@code null} 
 *     permitted).
 * @param valueAxisLabel  the label for the value axis ({@code null} 
 *     permitted).
 * @param dataset  the dataset for the chart ({@code null} permitted).
 *
 * @return A bar chart.
 */
public static JFreeChart createBarChart(String title, String categoryAxisLabel, String valueAxisLabel,
        CategoryDataset dataset) {

    CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel);
    ValueAxis valueAxis = new NumberAxis(valueAxisLabel);

    BarRenderer renderer = new BarRenderer();
    ItemLabelPosition position1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER);
    renderer.setDefaultPositiveItemLabelPosition(position1);
    ItemLabelPosition position2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6, TextAnchor.TOP_CENTER);
    renderer.setDefaultNegativeItemLabelPosition(position2);
    renderer.setDefaultToolTipGenerator(new StandardCategoryToolTipGenerator());

    CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer);
    JFreeChart chart = new JFreeChart(title, plot);
    currentTheme.apply(chart);
    return chart;

}