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

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

Introduction

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

Prototype

public void setCategoryMargin(double margin) 

Source Link

Document

Sets the category margin and sends an AxisChangeEvent to all registered listeners.

Usage

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

public static JFreeChart createChart(CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createStackedAreaChart("Stacked Area Chart", "Category", "Value",
            categorydataset, PlotOrientation.VERTICAL, true, true, false);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setForegroundAlpha(0.85F);
    CategoryAxis categoryaxis = categoryplot.getDomainAxis();
    categoryaxis.setLowerMargin(0.0D);/*from w w  w  . j  a  v a  2s  .co  m*/
    categoryaxis.setUpperMargin(0.0D);
    categoryaxis.setCategoryMargin(0.0D);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    CategoryItemRenderer categoryitemrenderer = categoryplot.getRenderer();
    categoryitemrenderer.setBaseItemLabelsVisible(true);
    return jfreechart;
}

From source file:eu.delving.sip.base.ReportChartHelper.java

private static JPanel finishBarChart(JFreeChart chart, Color... colors) {
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    plot.setRangePannable(true);//w w  w . j  a  v a  2  s.c o  m
    if (colors.length > 0)
        plot.setRenderer(new CustomRenderer(colors));
    BarRenderer bar = (BarRenderer) plot.getRenderer();
    bar.setItemLabelAnchorOffset(9D);
    bar.setBaseItemLabelsVisible(true);
    bar.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    bar.setMaximumBarWidth(0.05);
    bar.setItemMargin(0.03D);
    bar.setBasePositiveItemLabelPosition(
            new ItemLabelPosition(INSIDE12, CENTER_RIGHT, CENTER_RIGHT, -1.5707963267948966D));
    bar.setPositiveItemLabelPositionFallback(
            new ItemLabelPosition(OUTSIDE12, CENTER_LEFT, CENTER_LEFT, -1.5707963267948966D));
    CategoryAxis x = plot.getDomainAxis();
    x.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90);
    x.setCategoryMargin(0.25D);
    x.setUpperMargin(0.02D);
    x.setLowerMargin(0.02D);
    NumberAxis y = (NumberAxis) plot.getRangeAxis();
    y.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    y.setUpperMargin(0.10000000000000001D);
    ChartUtilities.applyCurrentTheme(chart);
    return new ChartPanel(chart);
}

From source file:com.mxgraph.examples.swing.chart.BarChartDemo1.java

/**
 * Creates a sample chart.//from  www .  j  av  a2 s . c o  m
 *
 * @param dataset  the dataset.
 *
 * @return The chart.
 */
public static JFreeChart createChart(final CategoryDataset dataset) {
    // create the chart...
    JFreeChart chart = ChartFactory.createBarChart("", // chart title
            "X-value", // domain axis label
            "Y-value", // range axis label
            dataset, // data
            PlotOrientation.HORIZONTAL, // orientation
            true, // include legend
            true, false);
    chart.addSubtitle(new TextTitle("http://www.bupt.edu.cn", new Font("", Font.ITALIC, 10)));
    //   chart.setBackgroundPaint(Color.white);
    //   chart.setBackgroundPaint(Color.getHSBColor(2, 29, 100));
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.white);
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setBaseItemLabelsVisible(true);

    //
    renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    CategoryAxis categoryAxis = plot.getDomainAxis();
    categoryAxis.setCategoryMargin(0.1);//
    categoryAxis.setUpperMargin(0.02);
    categoryAxis.setLowerMargin(0.02);
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setUpperMargin(0.10);

    // 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));
    GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0));
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    renderer.setSeriesPaint(2, gp2);

    chart.getTitle().setFont(new Font("", Font.PLAIN, 16));//

    CategoryAxis domainAxis = plot.getDomainAxis();
    //
    domainAxis.setLabelFont(new Font("", Font.PLAIN, 14));
    //
    domainAxis.setTickLabelFont(new Font("", Font.PLAIN, 10));

    //
    rangeAxis.setLabelFont(new Font("", Font.PLAIN, 15));

    chart.getLegend().setItemFont(new Font("", Font.PLAIN, 15));

    return chart;
}

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

private static JFreeChart createChart(CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createBarChart(null, null, null, categorydataset,
            PlotOrientation.HORIZONTAL, false, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    TextTitle texttitle = new TextTitle(
            "Figure 7 | I. Resources - The site offers users relevant, informative and educational resources");
    texttitle.setHorizontalAlignment(HorizontalAlignment.LEFT);
    texttitle.setBackgroundPaint(Color.red);
    texttitle.setPaint(Color.white);
    jfreechart.setTitle(texttitle);/*from   w w  w.j  a  v a2 s  .co m*/
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setOutlinePaint(null);
    categoryplot.setDomainGridlinesVisible(true);
    categoryplot.setDomainGridlinePosition(CategoryAnchor.END);
    categoryplot.setDomainGridlineStroke(new BasicStroke(0.5F));
    categoryplot.setDomainGridlinePaint(Color.black);
    categoryplot.setRangeGridlinesVisible(false);
    categoryplot.clearRangeMarkers();
    CategoryAxis categoryaxis = categoryplot.getDomainAxis();
    categoryaxis.setVisible(false);
    categoryaxis.setCategoryMargin(0.5D);
    categoryplot.getRangeAxis().setVisible(false);
    BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer();
    barrenderer.setSeriesPaint(0, new Color(156, 164, 74));
    barrenderer.setDrawBarOutline(false);
    barrenderer.setBaseItemLabelsVisible(true);
    barrenderer.setBaseItemLabelFont(new Font("SansSerif", 1, 10));
    ItemLabelPosition itemlabelposition = new ItemLabelPosition(ItemLabelAnchor.INSIDE3,
            TextAnchor.CENTER_RIGHT);
    barrenderer.setBasePositiveItemLabelPosition(itemlabelposition);
    CategoryTextAnnotation categorytextannotation = new CategoryTextAnnotation("1. White papers are available.",
            "Category 1", 0.0D);
    categorytextannotation.setFont(new Font("SansSerif", 1, 12));
    categorytextannotation.setTextAnchor(TextAnchor.BOTTOM_LEFT);
    categorytextannotation.setCategoryAnchor(CategoryAnchor.START);
    categoryplot.addAnnotation(categorytextannotation);
    CategoryTextAnnotation categorytextannotation1 = new CategoryTextAnnotation(
            "2. White papers enhance users understanding of the firm and its expertise.", "Category 2", 0.0D);
    categorytextannotation1.setFont(new Font("SansSerif", 0, 12));
    categorytextannotation1.setTextAnchor(TextAnchor.BOTTOM_LEFT);
    categorytextannotation1.setCategoryAnchor(CategoryAnchor.START);
    categoryplot.addAnnotation(categorytextannotation1);
    CategoryTextAnnotation categorytextannotation2 = new CategoryTextAnnotation(
            "3. White papers are relevant to the firm's prospects and clients.", "Category 3", 0.0D);
    categorytextannotation2.setFont(new Font("SansSerif", 0, 12));
    categorytextannotation2.setTextAnchor(TextAnchor.BOTTOM_LEFT);
    categorytextannotation2.setCategoryAnchor(CategoryAnchor.START);
    categoryplot.addAnnotation(categorytextannotation2);
    CategoryTextAnnotation categorytextannotation3 = new CategoryTextAnnotation(
            "4. White papers are relevant to the firm's positioning.", "Category 4", 0.0D);
    categorytextannotation3.setFont(new Font("SansSerif", 0, 12));
    categorytextannotation3.setTextAnchor(TextAnchor.BOTTOM_LEFT);
    categorytextannotation3.setCategoryAnchor(CategoryAnchor.START);
    categoryplot.addAnnotation(categorytextannotation3);
    CategoryTextAnnotation categorytextannotation4 = new CategoryTextAnnotation(
            "5. Case studies are available.", "Category 5", 0.0D);
    categorytextannotation4.setFont(new Font("SansSerif", 1, 12));
    categorytextannotation4.setTextAnchor(TextAnchor.BOTTOM_LEFT);
    categorytextannotation4.setCategoryAnchor(CategoryAnchor.START);
    categoryplot.addAnnotation(categorytextannotation4);
    CategoryTextAnnotation categorytextannotation5 = new CategoryTextAnnotation(
            "6. Case studies enhance users understanding of the firm and its expertise.", "Category 6", 0.0D);
    categorytextannotation5.setFont(new Font("SansSerif", 0, 12));
    categorytextannotation5.setTextAnchor(TextAnchor.BOTTOM_LEFT);
    categorytextannotation5.setCategoryAnchor(CategoryAnchor.START);
    categoryplot.addAnnotation(categorytextannotation5);
    CategoryTextAnnotation categorytextannotation6 = new CategoryTextAnnotation(
            "7. Case studies are relevant to the firm's prospects and clients.", "Category 7", 0.0D);
    categorytextannotation6.setFont(new Font("SansSerif", 0, 12));
    categorytextannotation6.setTextAnchor(TextAnchor.BOTTOM_LEFT);
    categorytextannotation6.setCategoryAnchor(CategoryAnchor.START);
    categoryplot.addAnnotation(categorytextannotation6);
    CategoryTextAnnotation categorytextannotation7 = new CategoryTextAnnotation(
            "8. White papers are relevant to the firm's positioning.", "Category 8", 0.0D);
    categorytextannotation7.setFont(new Font("SansSerif", 0, 12));
    categorytextannotation7.setTextAnchor(TextAnchor.BOTTOM_LEFT);
    categorytextannotation7.setCategoryAnchor(CategoryAnchor.START);
    categoryplot.addAnnotation(categorytextannotation7);
    CategoryTextAnnotation categorytextannotation8 = new CategoryTextAnnotation(
            "9. Case studies are available.", "Category 9", 0.0D);
    categorytextannotation8.setFont(new Font("SansSerif", 1, 12));
    categorytextannotation8.setTextAnchor(TextAnchor.BOTTOM_LEFT);
    categorytextannotation8.setCategoryAnchor(CategoryAnchor.START);
    categoryplot.addAnnotation(categorytextannotation8);
    CategoryTextAnnotation categorytextannotation9 = new CategoryTextAnnotation(
            "10. Case studies enhance users understanding of the firm and its expertise.", "Category 10", 0.0D);
    categorytextannotation9.setFont(new Font("SansSerif", 0, 12));
    categorytextannotation9.setTextAnchor(TextAnchor.BOTTOM_LEFT);
    categorytextannotation9.setCategoryAnchor(CategoryAnchor.START);
    categoryplot.addAnnotation(categorytextannotation9);
    CategoryTextAnnotation categorytextannotation10 = new CategoryTextAnnotation(
            "11. Case studies are relevant to the firm's prospects and clients.", "Category 11", 0.0D);
    categorytextannotation10.setFont(new Font("SansSerif", 0, 12));
    categorytextannotation10.setTextAnchor(TextAnchor.BOTTOM_LEFT);
    categorytextannotation10.setCategoryAnchor(CategoryAnchor.START);
    categoryplot.addAnnotation(categorytextannotation10);
    CategoryTextAnnotation categorytextannotation11 = new CategoryTextAnnotation(
            "12. White papers are relevant to the firm's positioning.", "Category 12", 0.0D);
    categorytextannotation11.setFont(new Font("SansSerif", 0, 12));
    categorytextannotation11.setTextAnchor(TextAnchor.BOTTOM_LEFT);
    categorytextannotation11.setCategoryAnchor(CategoryAnchor.START);
    categoryplot.addAnnotation(categorytextannotation11);
    CategoryTextAnnotation categorytextannotation12 = new CategoryTextAnnotation(
            "13. Users can easily access resources based on viewer interest.", "Category 13", 0.0D);
    categorytextannotation12.setFont(new Font("SansSerif", 1, 12));
    categorytextannotation12.setTextAnchor(TextAnchor.BOTTOM_LEFT);
    categorytextannotation12.setCategoryAnchor(CategoryAnchor.START);
    categoryplot.addAnnotation(categorytextannotation12);
    CategoryTextAnnotation categorytextannotation13 = new CategoryTextAnnotation(
            "14. Access to additional hyperlinks enhances users's ability to find relevant information.",
            "Category 14", 0.0D);
    categorytextannotation13.setFont(new Font("SansSerif", 1, 12));
    categorytextannotation13.setTextAnchor(TextAnchor.BOTTOM_LEFT);
    categorytextannotation13.setCategoryAnchor(CategoryAnchor.START);
    categoryplot.addAnnotation(categorytextannotation13);
    CategoryTextAnnotation categorytextannotation14 = new CategoryTextAnnotation("15. OVERALL EFFECTIVENESS.",
            "Overall", 0.0D);
    categorytextannotation14.setFont(new Font("SansSerif", 1, 12));
    categorytextannotation14.setTextAnchor(TextAnchor.BOTTOM_LEFT);
    categorytextannotation14.setCategoryAnchor(CategoryAnchor.START);
    categoryplot.addAnnotation(categorytextannotation14);
    return jfreechart;
}

From source file:es.bsc.autonomic.powermodeller.graphics.TotalPowerVsPredictionDecomposed.java

private static JFreeChart createChart() {

    ///*from   ww  w  .  j  a  v  a  2  s .c o m*/
    DefaultCategoryDataset Pactual = jFreeChartDataSets.get(CoreConfiguration.PACTUAL_LABEL);
    DefaultCategoryDataset Ppredicted = jFreeChartDataSets.get(CoreConfiguration.PPREDICTED_LABEL);

    StandardCategoryItemLabelGenerator standardcategoryitemlabelgenerator = new StandardCategoryItemLabelGenerator();

    LineAndShapeRenderer renderer1 = new LineAndShapeRenderer();
    /*renderer1.setBaseItemLabelGenerator(standardcategoryitemlabelgenerator);
    renderer1.setBaseItemLabelsVisible(true);*/
    StackedAreaRenderer renderer2 = new StackedAreaRenderer();

    //plot
    CategoryPlot plot = new CategoryPlot();
    plot.setDataset(Ppredicted);
    plot.setRenderer(renderer2);
    plot.setDataset(1, Pactual);
    plot.setRenderer(1, renderer1);
    CategoryAxis axis = new CategoryAxis("Sample");
    axis.setTickLabelsVisible(false);
    axis.setCategoryMargin(0.0);
    plot.setDomainAxis(axis);

    //more rangeAxis
    plot.setRangeAxis(new NumberAxis("Power (Watts)"));
    plot.mapDatasetToRangeAxis(2, 1);
    //
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setRangeGridlinesVisible(true);
    plot.setDomainGridlinesVisible(true);
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45);

    //chart
    JFreeChart chart = new JFreeChart(plot);
    chart.setTitle(NAME);
    return chart;
}

From source file:com.thalesgroup.hudson.plugins.sourcemonitor.SourceMonitorChartBuilder.java

public static JFreeChart buildChart(SourceMonitorBuildAction action) {
    JFreeChart chart = ChartFactory.createStackedAreaChart(null, null, "Number of errors", buildDataset(action),
            PlotOrientation.VERTICAL, true, false, true);

    chart.setBackgroundPaint(Color.white);

    CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setOutlinePaint(null);/*from   w  w  w  . ja v  a 2  s .c  o  m*/
    plot.setForegroundAlpha(0.8f);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.black);

    CategoryAxis domainAxis = new ShiftedCategoryAxis(null);
    plot.setDomainAxis(domainAxis);
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);
    domainAxis.setCategoryMargin(0.0);
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    // crop extra space around the graph
    plot.setInsets(new RectangleInsets(0, 0, 0, 5.0));

    CategoryItemRenderer firstRender = new DefaultCategoryItemRenderer();
    SourceMonitorRenderer renderer = new SourceMonitorRenderer(action.getUrlName());
    plot.setRenderer(firstRender);

    return chart;
}

From source file:com.mxgraph.examples.swing.chart.BarChartDemo1.java

public static JFreeChart createChart1(CategoryDataset dataset) {

    // create the chart...
    JFreeChart chart = ChartFactory.createBarChart("", // chart title
            "X-value", // domain axis label
            "Y-value", // range axis label
            dataset, // data
            PlotOrientation.HORIZONTAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );//from  w  ww  .  j  av  a 2s  .  co m

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...

    // set the background color for the chart...
    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    CategoryAxis categoryAxis = plot.getDomainAxis();
    categoryAxis.setCategoryMargin(0.1);//
    categoryAxis.setUpperMargin(0.02);
    categoryAxis.setLowerMargin(0.02);

    // ******************************************************************
    //  More than 150 demo applications are included with the JFreeChart
    //  Developer Guide...for more information, see:
    //
    //  >   http://www.object-refinery.com/jfreechart/guide.html
    //
    // ******************************************************************

    // set the range axis to display integers only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setUpperMargin(0.10);
    // disable bar outlines...
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(true);
    renderer.setBaseItemLabelsVisible(true);
    renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    // 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));
    GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0));
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    renderer.setSeriesPaint(2, gp2);

    renderer.setBasePositiveItemLabelPosition(
            new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));
    renderer.setItemLabelAnchorOffset(10D);
    renderer.setItemLabelFont(new Font("", Font.PLAIN, 12));
    renderer.setItemLabelsVisible(true);

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 180));

    // OPTIONAL CUSTOMISATION COMPLETED.      

    chart.getTitle().setFont(new Font("", Font.BOLD, 16));//

    //
    domainAxis.setLabelFont(new Font("", Font.BOLD, 14));
    //
    domainAxis.setTickLabelFont(new Font("", Font.PLAIN, 10));

    //
    rangeAxis.setLabelFont(new Font("", Font.BOLD, 15));

    chart.getLegend().setItemFont(new Font("", Font.BOLD, 15));

    /**
     *  chart.getTitle().setFont(new Font("",Font.BOLD,20));//
            
    //
    domainAxis.setLabelFont(new Font("",Font.BOLD,14));
    //
    domainAxis.setTickLabelFont(new Font("",Font.BOLD,12));
    //
    rangeAxis.setLabelFont(new Font("",Font.BOLD,15));
            
    chart.getLegend().setItemFont(new Font("", Font.BOLD, 15));
     */
    return chart;

}

From source file:org.jenkinsci.plugins.todos.TodosChartBuilder.java

/**
 * Build a trend chart from the provided data.
 * //from w  w  w.ja  v a 2s  . co m
 * @param action
 *            the build action
 * @return the trend chart
 */
public static JFreeChart buildChart(TodosBuildAction action) {
    String strComments = Messages.Todos_ReportSummary_Comments();

    JFreeChart chart = ChartFactory.createStackedAreaChart(null, null, strComments, buildDataset(action),
            PlotOrientation.VERTICAL, true, false, true);

    chart.setBackgroundPaint(Color.white);

    CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setOutlinePaint(null);
    plot.setForegroundAlpha(0.8f);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.black);

    CategoryAxis domainAxis = new ShiftedCategoryAxis(null);
    plot.setDomainAxis(domainAxis);
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);
    domainAxis.setCategoryMargin(0.0);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // Crop extra space around the graph
    plot.setInsets(new RectangleInsets(0, 0, 0, 5.0));

    TodosAreaRenderer renderer = new TodosAreaRenderer(action.getUrlName());
    plot.setRenderer(renderer);

    return chart;
}

From source file:eu.delving.stats.ChartHelper.java

private static JFreeChart finishBarChart(JFreeChart chart, Color... colors) {
    CategoryPlot categoryplot = (CategoryPlot) chart.getPlot();
    categoryplot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    categoryplot.setRangePannable(true);
    if (colors.length > 0)
        categoryplot.setRenderer(new CustomRenderer(colors));
    BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer();
    barrenderer.setItemLabelAnchorOffset(9D);
    barrenderer.setBaseItemLabelsVisible(true);
    barrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    barrenderer.setMaximumBarWidth(0.05);
    barrenderer.setItemMargin(0.03D);/*from   w  w w .j  av  a2  s. c o m*/
    ItemLabelPosition itemlabelposition = new ItemLabelPosition(INSIDE12, CENTER_RIGHT, CENTER_RIGHT,
            -1.5707963267948966D);
    barrenderer.setBasePositiveItemLabelPosition(itemlabelposition);
    ItemLabelPosition itemlabelposition1 = new ItemLabelPosition(OUTSIDE12, CENTER_LEFT, CENTER_LEFT,
            -1.5707963267948966D);
    barrenderer.setPositiveItemLabelPositionFallback(itemlabelposition1);
    CategoryAxis categoryaxis = categoryplot.getDomainAxis();
    categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45);
    categoryaxis.setCategoryMargin(0.25D);
    categoryaxis.setUpperMargin(0.02D);
    categoryaxis.setLowerMargin(0.02D);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    numberaxis.setUpperMargin(0.10000000000000001D);
    ChartUtilities.applyCurrentTheme(chart);
    return chart;
}

From source file:com.tonbeller.jpivot.chart.ChartFactory.java

/**
 * Creates an area chart with default settings.
 *
 * @param title  the chart title.//from   w  w w .  ja v  a 2s .  c  om
 * @param categoryAxisLabel  the label for the category axis.
 * @param valueAxisLabel  the label for the value axis.
 * @param data  the dataset for the chart.
 * @param legend  a flag specifying whether or not a legend is required.
 * @param tooltips  configure chart to generate tool tips?
 * @param urls  configure chart to generate URLs?
 *
 * @return an area chart.
 */
public static JFreeChart createAreaChart(String title, java.awt.Font titleFont, String categoryAxisLabel,
        String valueAxisLabel, CategoryDataset data, PlotOrientation orientation, boolean legend,
        boolean tooltips, boolean urls, CategoryURLGenerator urlGenerator) {

    CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel);
    categoryAxis.setCategoryMargin(0.0);
    ValueAxis valueAxis = new NumberAxis(valueAxisLabel);
    AreaRenderer renderer = new AreaRenderer();
    if (tooltips) {
        renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator());
    }
    if (urls) {
        renderer.setItemURLGenerator(urlGenerator);
    }
    CategoryPlot plot = new CategoryPlot(data, categoryAxis, valueAxis, renderer);
    plot.setOrientation(orientation);
    JFreeChart chart = new JFreeChart(title, titleFont, plot, legend);

    return chart;

}