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:edu.dlnu.liuwenpeng.ChartFactory.ChartFactory.java

/**    
 * Creates and returns a default instance of a box and whisker chart    
 * based on data from a {@link BoxAndWhiskerCategoryDataset}.    
 *    //from   www.  j  a  v  a 2  s  .  c o  m
 * @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).    
 * @param dataset  the dataset for the chart (<code>null</code> permitted).    
 * @param legend  a flag specifying whether or not a legend is required.    
 *    
 * @return A box and whisker chart.    
 *     
 * @since 1.0.4    
 */
public static JFreeChart createBoxAndWhiskerChart(String title, String categoryAxisLabel, String valueAxisLabel,
        BoxAndWhiskerCategoryDataset dataset, boolean legend) {

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

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

    CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer);
    return new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
}

From source file:KIDLYFactory.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  ww  w  . j  a  v a  2s. c om*/
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param legend  a flag specifying whether or not a legend is required.
 *
 * @return A box and whisker chart.
 *
 * @since 1.0.4
 */
public static JFreeChart createBoxAndWhiskerChart(String title, String categoryAxisLabel, String valueAxisLabel,
        BoxAndWhiskerCategoryDataset dataset, boolean legend) {

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

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

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

From source file:edu.ucla.stat.SOCR.chart.ChartGenerator_JTable.java

private JFreeChart createBoxAndWhiskerChart(String title, String xLabel, String yLabel,
        BoxAndWhiskerCategoryDataset dataset) {

    CategoryAxis domainAxis = new CategoryAxis(xLabel);
    NumberAxis rangeAxis = new NumberAxis(yLabel);

    // CategoryItemRenderer renderer = new BoxAndWhiskerRenderer();
    BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    CategoryPlot plot = new CategoryPlot(dataset, domainAxis, rangeAxis, renderer);
    JFreeChart chart = new JFreeChart(title, plot);

    chart.setBackgroundPaint(Color.white);

    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);

    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    //columnCount -- category count
    //RowCount -- serie count
    if (dataset.getColumnCount() * dataset.getRowCount() < 5) {

        domainAxis.setLowerMargin(0.2);/*from   ww  w. j a v a  2 s. c o  m*/
        domainAxis.setUpperMargin(0.2);
        if (dataset.getColumnCount() == 1)
            renderer.setItemMargin(0.5);
        //   domainAxis.setCategoryMargin(domainAxis.getCategoryMargin()*2);

    }

    else if (dataset.getColumnCount() * dataset.getRowCount() < 10) {
        domainAxis.setLowerMargin(domainAxis.getLowerMargin() * 2);
        domainAxis.setUpperMargin(domainAxis.getUpperMargin() * 2);
        if (dataset.getColumnCount() == 1)
            renderer.setItemMargin(renderer.getItemMargin() * 2);
        else
            domainAxis.setCategoryMargin(domainAxis.getCategoryMargin() * 2);
    }

    return chart;
}

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

public static <T extends Number> JFreeChart createScatterCategoryChart(Map<String, List<T>> dataset,
        String title, String xAxis, String yAxis, boolean showLegend) {
    // Make the PDB series and add it to the predicted strand locations
    CategoryDataset data = createMultiValueCategoryDataset(dataset);

    Range rangeBounds = DatasetUtilities.findRangeBounds(data);
    NumberAxis numberAxis = new NumberAxis(yAxis);
    numberAxis.setRangeWithMargins(rangeBounds);

    CategoryPlot plot = new CategoryPlot(data, new CategoryAxis(xAxis), numberAxis, new SR());

    JFreeChart chart = new JFreeChart(title, plot);

    if (!showLegend)
        chart.removeLegend();//from w w w. j  a v a  2  s .c o m
    setCategoryStandardTooltips(chart);

    ((CategoryPlot) chart.getPlot()).setDomainGridlinesVisible(false);
    ((CategoryPlot) chart.getPlot()).setRangeGridlinesVisible(false);
    ;

    chart.setBackgroundPaint(Color.white);
    chart.getPlot().setBackgroundPaint(Color.white);
    return chart;
}

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

public static <T extends Number> JFreeChart create2DScatterCategoryChart(Map<String[], List<T>> dataset,
        String title, String xAxis, String yAxis, boolean showLegend) {
    // Make the PDB series and add it to the predicted strand locations
    CategoryDataset data = create2DMultiValueCategoryDataset(dataset);

    Range rangeBounds = DatasetUtilities.findRangeBounds(data);
    NumberAxis numberAxis = new NumberAxis(yAxis);
    numberAxis.setRangeWithMargins(rangeBounds);

    CategoryPlot plot = new CategoryPlot(data, new CategoryAxis(xAxis), numberAxis, new SR());

    JFreeChart chart = new JFreeChart(title, plot);

    if (!showLegend)
        chart.removeLegend();/*from  w w  w. j av a  2  s .c  o  m*/
    setCategoryStandardTooltips(chart);

    ((CategoryPlot) chart.getPlot()).setDomainGridlinesVisible(false);
    ((CategoryPlot) chart.getPlot()).setRangeGridlinesVisible(false);
    ;

    chart.setBackgroundPaint(Color.white);
    chart.getPlot().setBackgroundPaint(Color.white);
    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./*w w  w.j  ava  2 s  .  co  m*/
 *
 * @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;

}

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

/**
 * Creates a stacked bar chart with default settings.  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 StackedBarRenderer}
 * as the renderer.//ww w.jav a2  s. co m
 *
 * @param title  the chart title ({@code null} permitted).
 * @param domainAxisLabel  the label for the category axis
 *                         ({@code null} permitted).
 * @param rangeAxisLabel  the label for the value axis
 *                        ({@code null} permitted).
 * @param dataset  the dataset for the chart ({@code null} permitted).
 *
 * @return A stacked bar chart.
 */
public static JFreeChart createStackedBarChart(String title, String domainAxisLabel, String rangeAxisLabel,
        CategoryDataset dataset) {

    CategoryAxis categoryAxis = new CategoryAxis(domainAxisLabel);
    ValueAxis valueAxis = new NumberAxis(rangeAxisLabel);

    StackedBarRenderer renderer = new StackedBarRenderer();
    renderer.setDefaultToolTipGenerator(new StandardCategoryToolTipGenerator());

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

}

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

/**
 * Creates an area chart with default settings.  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 an {@link AreaRenderer} 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).// w  ww .  j a va  2 s  .  c  o m
 * @param dataset  the dataset for the chart ({@code null} permitted).
 *
 * @return An area chart.
 */
public static JFreeChart createAreaChart(String title, String categoryAxisLabel, String valueAxisLabel,
        CategoryDataset dataset) {

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

    ValueAxis valueAxis = new NumberAxis(valueAxisLabel);

    AreaRenderer renderer = new AreaRenderer();
    renderer.setDefaultToolTipGenerator(new StandardCategoryToolTipGenerator());

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

}

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

/**
 * Creates a stacked area chart with default settings.  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 StackedAreaRenderer}
 * as the renderer.//ww w .  j a va 2s .  co m
 *
 * @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 stacked area chart.
 */
public static JFreeChart createStackedAreaChart(String title, String categoryAxisLabel, String valueAxisLabel,
        CategoryDataset dataset) {

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

    StackedAreaRenderer renderer = new StackedAreaRenderer();
    renderer.setDefaultToolTipGenerator(new StandardCategoryToolTipGenerator());

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

}

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

/**
 * Creates a line chart with default settings.  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 LineAndShapeRenderer} 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).// w w  w  .j a  v a2s  .c o  m
 * @param dataset  the dataset for the chart ({@code null} permitted).
 *
 * @return A line chart.
 */
public static JFreeChart createLineChart(String title, String categoryAxisLabel, String valueAxisLabel,
        CategoryDataset dataset) {

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

    LineAndShapeRenderer renderer = new LineAndShapeRenderer(true, false);
    renderer.setDefaultToolTipGenerator(new StandardCategoryToolTipGenerator());
    CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer);
    JFreeChart chart = new JFreeChart(title, plot);
    currentTheme.apply(chart);
    return chart;

}