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:com.googlecode.logVisualizer.chart.HorizontalIntervallBarChartBuilder.java

private JFreeChart createChart(final CategoryDataset dataset) {
    final JFreeChart chart = ChartFactory.createBarChart(getTitle(), xLable, yLable, dataset,
            PlotOrientation.HORIZONTAL, isIncludeLegend(), true, false);
    final CategoryPlot plot = (CategoryPlot) chart.getPlot();
    final CategoryAxis categoryAxis = plot.getDomainAxis();
    final LayeredBarRenderer renderer = new LayeredBarRenderer();

    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinePaint(Color.black);
    setBarShadowVisible(chart, false);//from www .j a v a  2s  .com

    plot.getRangeAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    plot.getRangeAxis().setLowerBound(-35);
    plot.getRangeAxis().setUpperBound(35);

    renderer.setDrawBarOutline(false);
    renderer.setSeriesPaint(0, Color.blue);
    renderer.setSeriesPaint(1, Color.green);
    renderer.setBaseItemLabelsVisible(true);
    renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    renderer.setSeriesPositiveItemLabelPosition(0,
            new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3, TextAnchor.CENTER));
    renderer.setSeriesPositiveItemLabelPosition(1,
            new ItemLabelPosition(ItemLabelAnchor.OUTSIDE2, TextAnchor.CENTER));
    renderer.setSeriesNegativeItemLabelPosition(0,
            new ItemLabelPosition(ItemLabelAnchor.OUTSIDE9, TextAnchor.CENTER));
    renderer.setSeriesNegativeItemLabelPosition(1,
            new ItemLabelPosition(ItemLabelAnchor.OUTSIDE10, TextAnchor.CENTER));
    renderer.setItemLabelAnchorOffset(9.0);
    renderer.setBaseToolTipGenerator(
            new StandardCategoryToolTipGenerator("{1}, {2}", NumberFormat.getInstance()));
    plot.setRenderer(renderer);
    plot.setRowRenderingOrder(SortOrder.DESCENDING);

    categoryAxis.setCategoryMargin(0.15);
    categoryAxis.setUpperMargin(0.0175);
    categoryAxis.setLowerMargin(0.0175);

    return chart;
}

From source file:org.toobsframework.pres.chart.ChartUtil.java

public static CategoryAxis createCategoryAxis(IRequest componentRequest, DomainAxisDef categoryAxisDef,
        Map params, boolean is3D) {
    CategoryAxis categoryAxis;
    if (is3D) {//from  www  . j  a va2 s. com
        categoryAxis = new CategoryAxis3D();
    } else {
        categoryAxis = new CategoryAxis();
    }
    if (categoryAxisDef != null) {
        if (categoryAxisDef.getDomainLabel() != null) {
            categoryAxis
                    .setLabel(evaluateTextLabel(componentRequest, categoryAxisDef.getDomainLabel(), params));
            if (categoryAxisDef.getDomainLabel().getFont() != null) {
                categoryAxis.setLabelFont(getFont(categoryAxisDef.getDomainLabel(), null));
            }
            categoryAxis.setLabelPaint(getColor(categoryAxisDef.getDomainLabel().getColor()));
        }

        if (categoryAxisDef.getLabelPosition() != null) {
            Integer labelPos = domainLabelPositions.get(ParameterUtil.resolveParam(componentRequest,
                    categoryAxisDef.getLabelPosition(), params, "standard")[0]);
            if (labelPos != null) {
                switch (labelPos) {
                case DOM_LABEL_STANDARD_TYPE:
                    categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.STANDARD);
                    break;
                case DOM_LABEL_UP_45_TYPE:
                    categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
                    break;
                case DOM_LABEL_DOWN_45_TYPE:
                    categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45);
                    break;
                case DOM_LABEL_UP_90_TYPE:
                    categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
                    break;
                case DOM_LABEL_DOWN_90_TYPE:
                    categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90);
                    break;
                }
            }
        }
        double domainMargin = Double.parseDouble(ParameterUtil.resolveParam(componentRequest,
                categoryAxisDef.getDomainMargin(), params, "0.0")[0]);
        double lowerMargin = Double.parseDouble(ParameterUtil.resolveParam(componentRequest,
                categoryAxisDef.getLowerMargin(), params, "0.0")[0]);
        double upperMargin = Double.parseDouble(ParameterUtil.resolveParam(componentRequest,
                categoryAxisDef.getUpperMargin(), params, "0.0")[0]);

        categoryAxis.setCategoryMargin(domainMargin);
        categoryAxis.setLowerMargin(lowerMargin);
        categoryAxis.setUpperMargin(upperMargin);
    }
    return categoryAxis;
}

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

private JFreeChart createCategoryLineStatChart(String title, String xLabel, String yLabel,
        CategoryDataset dataset) {//from   w w  w . j a v  a 2 s .co  m
    // create the chart...
    JFreeChart chart = ChartFactory.createLineChart(title, // chart title
            xLabel, // domain axis label
            yLabel, // range axis label
            dataset, // data
            orientation, // orientation
            true, // include legend
            true, // tooltips
            false // urls
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white);

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.white);

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setUpperMargin(0.0);
    domainAxis.setLowerMargin(0.0);

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

    // customise the renderer...
    StatisticalLineAndShapeRenderer renderer = new StatisticalLineAndShapeRenderer(true, false);
    plot.setRenderer(renderer);

    // OPTIONAL CUSTOMISATION COMPLETED.
    return chart;
}

From source file:org.pentaho.plugin.jfreereport.reportcharts.CategoricalChartExpression.java

protected void configureChart(final JFreeChart chart) {
    super.configureChart(chart);

    final CategoryPlot cpl = chart.getCategoryPlot();
    final CategoryItemRenderer renderer = cpl.getRenderer();
    if (StringUtils.isEmpty(getTooltipFormula()) == false) {
        renderer.setBaseToolTipGenerator(
                new FormulaCategoryTooltipGenerator(getRuntime(), getTooltipFormula()));
    }/*from ww w .  ja v a2  s .  c o  m*/
    if (StringUtils.isEmpty(getUrlFormula()) == false) {
        renderer.setBaseItemURLGenerator(new FormulaCategoryURLGenerator(getRuntime(), getUrlFormula()));
    }
    if (this.categoricalLabelFormat != null) {
        final StandardCategoryItemLabelGenerator scilg;
        if (categoricalLabelDecimalFormat != null) {
            final DecimalFormat numFormat = new DecimalFormat(categoricalLabelDecimalFormat,
                    new DecimalFormatSymbols(getRuntime().getResourceBundleFactory().getLocale()));
            numFormat.setRoundingMode(RoundingMode.HALF_UP);
            scilg = new StandardCategoryItemLabelGenerator(categoricalLabelFormat, numFormat);
        } else if (categoricalLabelDateFormat != null) {
            scilg = new StandardCategoryItemLabelGenerator(categoricalLabelFormat, new SimpleDateFormat(
                    categoricalLabelDateFormat, getRuntime().getResourceBundleFactory().getLocale()));
        } else {
            final DecimalFormat formatter = new DecimalFormat();
            formatter.setDecimalFormatSymbols(
                    new DecimalFormatSymbols(getRuntime().getResourceBundleFactory().getLocale()));
            scilg = new StandardCategoryItemLabelGenerator(categoricalLabelFormat, formatter);
        }
        renderer.setBaseItemLabelGenerator(scilg);
    }
    renderer.setBaseItemLabelsVisible(Boolean.TRUE.equals(getItemsLabelVisible()));
    if (getItemLabelFont() != null) {
        renderer.setBaseItemLabelFont(getItemLabelFont());
    }

    if (categoricalItemLabelRotation != null) {
        final ItemLabelPosition orgPosItemLabelPos = renderer.getBasePositiveItemLabelPosition();
        if (orgPosItemLabelPos == null) {
            final ItemLabelPosition pos2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12,
                    TextAnchor.BOTTOM_CENTER, TextAnchor.CENTER, categoricalItemLabelRotation.doubleValue());
            renderer.setBasePositiveItemLabelPosition(pos2);
        } else {
            final ItemLabelPosition pos2 = new ItemLabelPosition(orgPosItemLabelPos.getItemLabelAnchor(),
                    orgPosItemLabelPos.getTextAnchor(), orgPosItemLabelPos.getRotationAnchor(),
                    categoricalItemLabelRotation.doubleValue());
            renderer.setBasePositiveItemLabelPosition(pos2);
        }

        final ItemLabelPosition orgNegItemLabelPos = renderer.getBaseNegativeItemLabelPosition();
        if (orgNegItemLabelPos == null) {
            final ItemLabelPosition pos2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12,
                    TextAnchor.BOTTOM_CENTER, TextAnchor.CENTER, categoricalItemLabelRotation.doubleValue());
            renderer.setBaseNegativeItemLabelPosition(pos2);
        } else {
            final ItemLabelPosition neg2 = new ItemLabelPosition(orgNegItemLabelPos.getItemLabelAnchor(),
                    orgNegItemLabelPos.getTextAnchor(), orgNegItemLabelPos.getRotationAnchor(),
                    categoricalItemLabelRotation.doubleValue());
            renderer.setBaseNegativeItemLabelPosition(neg2);
        }
    }

    final Font labelFont = Font.decode(getLabelFont());

    final CategoryAxis categoryAxis = cpl.getDomainAxis();
    categoryAxis.setLabelFont(labelFont);
    categoryAxis.setTickLabelFont(labelFont);
    if (getCategoryTitleFont() != null) {
        categoryAxis.setLabelFont(getCategoryTitleFont());
    }
    if (getCategoryTickFont() != null) {
        categoryAxis.setTickLabelFont(getCategoryTickFont());
    }

    if (maxCategoryLabelWidthRatio != null) {
        categoryAxis.setMaximumCategoryLabelWidthRatio(maxCategoryLabelWidthRatio.floatValue());
    }
    cpl.setDomainGridlinesVisible(showGridlines);
    if (labelRotation != null) {
        double angle = labelRotation.doubleValue();
        CategoryLabelPosition top = createUpRotationCategoryLabelPosition(PlaneDirection.TOP, angle);
        CategoryLabelPosition bottom = createUpRotationCategoryLabelPosition(PlaneDirection.BOTTOM, angle);
        CategoryLabelPosition left = createUpRotationCategoryLabelPosition(PlaneDirection.LEFT, angle);
        CategoryLabelPosition right = createUpRotationCategoryLabelPosition(PlaneDirection.RIGHT, angle);
        CategoryLabelPositions rotationLabelPositions = new CategoryLabelPositions(top, bottom, left, right);
        categoryAxis.setCategoryLabelPositions(rotationLabelPositions);
    }

    final String[] colors = getSeriesColor();
    for (int i = 0; i < colors.length; i++) {
        renderer.setSeriesPaint(i, parseColorFromString(colors[i]));
    }

    if (lowerMargin != null) {
        categoryAxis.setLowerMargin(lowerMargin.doubleValue());
    }
    if (upperMargin != null) {
        categoryAxis.setUpperMargin(upperMargin.doubleValue());
    }
    if (categoryMargin != null) {
        categoryAxis.setCategoryMargin(categoryMargin.doubleValue());
    }

    configureRangeAxis(cpl, labelFont);
}

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);
        domainAxis.setUpperMargin(0.2);//from  w  w w  . j a va2s  . c  o  m
        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;
}