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

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

Introduction

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

Prototype

public void setLowerMargin(double margin) 

Source Link

Document

Sets the lower margin for the axis 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);
    categoryaxis.setUpperMargin(0.0D);//from   www.  java2 s  .  co m
    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:org.jfree.chart.demo.ParetoChartDemo1.java

public static JFreeChart createChart(CategoryDataset acategorydataset[]) {
    JFreeChart jfreechart = ChartFactory.createBarChart("Freshmeat Software Projects", "Language", "Projects",
            acategorydataset[0], PlotOrientation.VERTICAL, true, true, false);
    jfreechart.addSubtitle(new TextTitle("By Programming Language"));
    jfreechart.addSubtitle(new TextTitle("As at 5 March 2003"));
    jfreechart.setBackgroundPaint(Color.white);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setBackgroundPaint(Color.lightGray);
    categoryplot.setRangeGridlinePaint(Color.white);
    CategoryAxis categoryaxis = categoryplot.getDomainAxis();
    categoryaxis.setLowerMargin(0.02D);
    categoryaxis.setUpperMargin(0.02D);/*w ww.j  ava2  s.com*/
    categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    LineAndShapeRenderer lineandshaperenderer = new LineAndShapeRenderer();
    NumberAxis numberaxis1 = new NumberAxis("Percent");
    numberaxis1.setNumberFormatOverride(NumberFormat.getPercentInstance());
    categoryplot.setRangeAxis(1, numberaxis1);
    categoryplot.setDataset(1, acategorydataset[1]);
    categoryplot.setRenderer(1, lineandshaperenderer);
    categoryplot.mapDatasetToRangeAxis(1, 1);
    categoryplot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    return jfreechart;
}

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

private static JFreeChart createChart(CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createLineChart("Statistical Line Chart Demo 1", "Type", "Value",
            categorydataset, PlotOrientation.VERTICAL, true, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setBackgroundPaint(Color.lightGray);
    categoryplot.setRangeGridlinePaint(Color.white);
    CategoryAxis categoryaxis = categoryplot.getDomainAxis();
    categoryaxis.setUpperMargin(0.0D);/*from  w  w  w  .  ja v a2s  . c  o  m*/
    categoryaxis.setLowerMargin(0.0D);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    numberaxis.setAutoRangeIncludesZero(true);
    StatisticalLineAndShapeRenderer statisticallineandshaperenderer = new StatisticalLineAndShapeRenderer(true,
            false);
    categoryplot.setRenderer(statisticallineandshaperenderer);
    return jfreechart;
}

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

private static JFreeChart createChart(CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createAreaChart("Area Chart", "Category", "Value", categorydataset,
            PlotOrientation.VERTICAL, true, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    TextTitle texttitle = new TextTitle(
            "An area chart demonstration.  We use this subtitle as an example of what happens when you get a really long title or subtitle.");
    texttitle.setFont(new Font("SansSerif", 0, 12));
    texttitle.setPosition(RectangleEdge.TOP);
    texttitle.setPadding(new RectangleInsets(UnitType.RELATIVE, 0.050000000000000003D, 0.050000000000000003D,
            0.050000000000000003D, 0.050000000000000003D));
    texttitle.setVerticalAlignment(VerticalAlignment.BOTTOM);
    jfreechart.addSubtitle(texttitle);//from w  w w. jav a2 s  .  c  o  m
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setForegroundAlpha(0.5F);
    categoryplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
    categoryplot.setBackgroundPaint(Color.lightGray);
    categoryplot.setDomainGridlinesVisible(true);
    categoryplot.setDomainGridlinePaint(Color.white);
    categoryplot.setRangeGridlinesVisible(true);
    categoryplot.setRangeGridlinePaint(Color.white);
    CategoryAxis categoryaxis = categoryplot.getDomainAxis();
    categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    categoryaxis.setLowerMargin(0.0D);
    categoryaxis.setUpperMargin(0.0D);
    categoryaxis.addCategoryLabelToolTip("Type 1", "The first type.");
    categoryaxis.addCategoryLabelToolTip("Type 2", "The second type.");
    categoryaxis.addCategoryLabelToolTip("Type 3", "The third type.");
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    numberaxis.setLabelAngle(0.0D);
    return jfreechart;
}

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 ww w  .  j  a  v a  2  s.c  om*/
    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: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);//from w ww  . jav a 2 s . co  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:org.jenkinsci.plugins.todos.TodosChartBuilder.java

/**
 * Build a trend chart from the provided data.
 * //from  ww  w.  j a  v  a2  s.c o 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:com.mxgraph.examples.swing.chart.BarChartDemo1.java

/**
 * Creates a sample chart.//from ww  w .j  a  v a 2s .c  om
 *
 * @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: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  w  w  . j ava2  s  .  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:presentation.webgui.vitroappservlet.StyleCreator.java

private static JFreeChart createChart(CategoryDataset dataset, Vector<String> givCategColors,
        Model3dStylesEntry givStyleEntry) {
    String capSimpleName = givStyleEntry.getCorrCapability();
    capSimpleName = capSimpleName.replaceAll(Capability.dcaPrefix, "");
    JFreeChart chart = ChartFactory.createBarChart("Style Legend for " + capSimpleName, // chart title
            null, // domain axis label
            null, // range axis label
            dataset, // data
            PlotOrientation.HORIZONTAL, false, // include legend
            true, false);/*from ww  w.j  a  va 2s .c  o  m*/

    chart.getTitle().setFont(new Font("SansSerif", Font.BOLD, 14));
    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white); // seen
    CategoryPlot plot = chart.getCategoryPlot();
    chart.setPadding(new RectangleInsets(0, 0, 0, 0)); //new

    plot.setNoDataMessage("NO DATA!");

    Paint[] tmpPaintCategories = { Color.white };
    if (givCategColors.size() > 0) {
        tmpPaintCategories = new Paint[givCategColors.size()];
        for (int i = 0; i < givCategColors.size(); i++) {
            tmpPaintCategories[i] = Color.decode(givCategColors.elementAt(i));
        }
    }

    CategoryItemRenderer renderer = new CustomRenderer(tmpPaintCategories);

    renderer.setSeriesPaint(0, new Color(255, 204, 51)); //new

    plot.setRenderer(renderer);

    plot.setAxisOffset(new RectangleInsets(0, 0, 0, 0)); //new
    plot.setForegroundAlpha(1f); //new
    plot.setBackgroundAlpha(1f); //new
    plot.setInsets(new RectangleInsets(5, 0, 5, 0)); //new was 5,0,5,0
    plot.setRangeGridlinesVisible(false); //new was true
    plot.setBackgroundPaint(Color.white);//new: was (Color.lightGray);
    plot.setOutlinePaint(Color.white);

    //plot.setOrientation(PlotOrientation.HORIZONTAL);

    CategoryAxis domainAxis = plot.getDomainAxis();

    domainAxis.setLowerMargin(0.04);
    domainAxis.setUpperMargin(0.04);
    domainAxis.setVisible(true);
    domainAxis.setLabelAngle(Math.PI / 2);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setRange(0.0, 100.0); // new: was 100
    rangeAxis.setVisible(false);
    // OPTIONAL CUSTOMISATION COMPLETED.
    return chart;
}