Example usage for org.jfree.chart.axis CategoryAxis CategoryAxis

List of usage examples for org.jfree.chart.axis CategoryAxis CategoryAxis

Introduction

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

Prototype

public CategoryAxis(String label) 

Source Link

Document

Constructs a category axis, using default values where necessary.

Usage

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

/**
 * Creates a Gantt chart using the supplied attributes plus default values
 * where required.  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 DateAxis} as the range axis, and a
 * {@link GanttRenderer} as the renderer.
 *
 * @param title  the chart title ({@code null} permitted).
 * @param categoryAxisLabel  the label for the category axis
 *                           ({@code null} permitted).
 * @param dateAxisLabel  the label for the date axis
 *                       ({@code null} permitted).
 * @param dataset  the dataset for the chart ({@code null} permitted).
 *
 * @return A Gantt chart./*  w  w  w.  j  a  va  2  s .c o m*/
 */
public static JFreeChart createGanttChart(String title, String categoryAxisLabel, String dateAxisLabel,
        IntervalCategoryDataset dataset) {

    CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel);
    DateAxis dateAxis = new DateAxis(dateAxisLabel);

    CategoryItemRenderer renderer = new GanttRenderer();
    renderer.setDefaultToolTipGenerator(
            new IntervalCategoryToolTipGenerator("{3} - {4}", DateFormat.getDateInstance()));

    CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, dateAxis, renderer);
    plot.setOrientation(PlotOrientation.HORIZONTAL);
    JFreeChart chart = new JFreeChart(title, plot);
    currentTheme.apply(chart);
    return chart;

}

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

/**
 * Creates a waterfall chart.  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 WaterfallBarRenderer} as the renderer.
 *
 * @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).// www  .j  ava2 s  . c  o m
 * @param dataset  the dataset for the chart ({@code null} permitted).
 *
 * @return A waterfall chart.
 */
public static JFreeChart createWaterfallChart(String title, String categoryAxisLabel, String valueAxisLabel,
        CategoryDataset dataset) {

    CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel);
    categoryAxis.setCategoryMargin(0.0);

    ValueAxis valueAxis = new NumberAxis(valueAxisLabel);

    WaterfallBarRenderer renderer = new WaterfallBarRenderer();
    // FIXME create a new method for the horizontal version
    //        if (orientation == PlotOrientation.HORIZONTAL) {
    //            ItemLabelPosition position = new ItemLabelPosition(
    //                    ItemLabelAnchor.CENTER, TextAnchor.CENTER,
    //                    TextAnchor.CENTER, Math.PI / 2.0);
    //            renderer.setBasePositiveItemLabelPosition(position);
    //            renderer.setBaseNegativeItemLabelPosition(position);
    //         }
    ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER,
            TextAnchor.CENTER, 0.0);
    renderer.setDefaultPositiveItemLabelPosition(position);
    renderer.setDefaultNegativeItemLabelPosition(position);
    StandardCategoryToolTipGenerator generator = new StandardCategoryToolTipGenerator();
    renderer.setDefaultToolTipGenerator(generator);

    CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer);
    plot.clearRangeMarkers();
    Marker baseline = new ValueMarker(0.0);
    baseline.setPaint(Color.BLACK);
    plot.addRangeMarker(baseline, Layer.FOREGROUND);
    JFreeChart chart = new JFreeChart(title, plot);
    currentTheme.apply(chart);
    return chart;

}

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

/**
 * Creates and returns a default instance of a box and whisker chart
 * based on data from a {@link BoxAndWhiskerCategoryDataset}.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param categoryAxisLabel  a label for the category axis
 *     (<code>null</code> permitted).
 * @param valueAxisLabel  a label for the value axis (<code>null</code>
 *     permitted)./*from w  w w . j  a  v a  2s .  c o m*/
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 *
 * @return A box and whisker chart.
 *
 * @since 1.0.4
 */
public static JFreeChart createBoxAndWhiskerChart(String title, String categoryAxisLabel, String valueAxisLabel,
        BoxAndWhiskerCategoryDataset dataset) {

    CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel);
    NumberAxis valueAxis = new NumberAxis(valueAxisLabel);
    valueAxis.setAutoRangeIncludesZero(false);

    BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setDefaultToolTipGenerator(new BoxAndWhiskerToolTipGenerator());

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