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:ch.opentrainingcenter.charts.bar.OTCCategoryChartViewer.java

void updateAxis(final TrainingChart chartType, final XAxisChart chartSerieType) {
    if (chart != null) {
        chart.setTitle(chartType.getTitle());
        ((CategoryPlot) chart.getPlot()).getRangeAxis().setLabel(chartType.getyAchse());
        final CategoryAxis domainAxis = ((CategoryPlot) chart.getPlot()).getDomainAxis();
        domainAxis.setLabel(CategoryHelper.getDomainAxis(chartSerieType));
        if (XAxisChart.YEAR.equals(chartSerieType) || XAxisChart.YEAR_START_TILL_NOW.equals(chartSerieType)) {
            domainAxis.setCategoryMargin(-0.75d);
        } else {/*from www.j  a va2 s.  c  o  m*/
            domainAxis.setCategoryMargin(0.2d);
        }
    }
}

From source file:nl.strohalm.cyclos.controls.reports.statistics.graphs.ChartPostProcessorImpl.java

/**
 * This method sets the width of the bars, and the spacing between the bars. It sets a general, hard coded standard for this. In JFreeChart, you
 * cannot set the bar width. In stead, you set the gaps: - lowerMargin is the gap between the start of the x-axis and the first bar - upperMargin
 * is the gap between the end of the x-axis and the last bar - categoryMargin is the gap between the categories. Note that the number you provide
 * here, is divided over all the gaps. So if you set this margin to 0.5 (is 50%) and there are 6 categories, this means that there are 5 gaps, so
 * each gap will get 10%. - itemMargin is the gap between the bars within a category. Again, this number is divided over all the itemgaps in the
 * whole graph. The method also takes care that extreme cases (with a very small amount of bars) still look acceptable.
 * @param plot//ww w  .java  2 s.c  om
 */
private void setMargins(final CategoryPlot plot) {
    final CategoryAxis axis = plot.getDomainAxis();
    axis.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 9));
    final int categoryCount = plot.getCategories().size();
    final int seriesCount = plot.getDataset().getRowCount();
    axis.setCategoryMargin(0.23); // sets spacing between categories on x%
    // set spacing between bars inside a catgory (in fractions, so 1 = 100%)
    final BarRenderer renderer = (BarRenderer) plot.getRenderer();
    if (categoryCount == 1) {
        renderer.setItemMargin(0.15);
    } else {
        renderer.setItemMargin(0.03);
    }
    // extreme cases
    if (categoryCount * seriesCount < 4) {
        final double outerMargins = (4.0 - (categoryCount * seriesCount)) / 10.0;
        axis.setLowerMargin(outerMargins);
        axis.setUpperMargin(outerMargins);
    }
}

From source file:hudson.plugins.labeledgroupedtests.TrendGraph.java

protected JFreeChart createGraph() {
    final CategoryDataset dataset = createDataSet().build();

    final JFreeChart chart = ChartFactory.createStackedAreaChart(null, // chart
            // title
            null, // unused
            yLabel, // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, // tooltips
            false // urls
    );//from  w ww.  j  a  v  a2 s.  c  o m

    chart.setBackgroundPaint(Color.white);

    final CategoryPlot plot = chart.getCategoryPlot();

    // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setBackgroundPaint(Color.WHITE);
    plot.setOutlinePaint(null);
    plot.setForegroundAlpha(0.8f);
    // plot.setDomainGridlinesVisible(true);
    // plot.setDomainGridlinePaint(Color.white);
    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);

    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    ChartUtil.adjustChebyshev(dataset, rangeAxis);
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setAutoRange(true);

    StackedAreaRenderer ar = new StackedAreaRenderer2() {
        @Override
        public Paint getItemPaint(int row, int column) {
            ChartLabel key = (ChartLabel) dataset.getColumnKey(column);
            if (key.getColor() != null)
                return key.getColor();
            return super.getItemPaint(row, column);
        }

        @Override
        public String generateURL(CategoryDataset dataset, int row, int column) {
            ChartLabel label = (ChartLabel) dataset.getColumnKey(column);
            return label.getURL() + relativeUrl;
        }

        @Override
        public String generateToolTip(CategoryDataset dataset, int row, int column) {
            ChartLabel label = (ChartLabel) dataset.getColumnKey(column);
            return label.getToolTipText();
        }
    };
    plot.setRenderer(ar);

    ar.setSeriesPaint(0, ColorPalette.RED); // Skips.
    ar.setSeriesPaint(1, ColorPalette.YELLOW); // Failures.
    ar.setSeriesPaint(2, ColorPalette.BLUE); // Total.

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

    return chart;
}

From source file:com.cwctravel.hudson.plugins.suitegroupedtests.TrendGraph.java

@Override
protected JFreeChart createGraph() {
    final CategoryDataset dataset = createDataSet().build();

    final JFreeChart chart = ChartFactory.createStackedAreaChart(null, // chart
            // title
            null, // unused
            yLabel, // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, // tooltips
            false // urls
    );//www.j av  a 2s . c o m

    chart.setBackgroundPaint(Color.white);

    final CategoryPlot plot = chart.getCategoryPlot();

    // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setBackgroundPaint(Color.WHITE);
    plot.setOutlinePaint(null);
    plot.setForegroundAlpha(0.8f);
    // plot.setDomainGridlinesVisible(true);
    // plot.setDomainGridlinePaint(Color.white);
    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);

    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    ChartUtil.adjustChebyshev(dataset, rangeAxis);
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setAutoRange(true);

    StackedAreaRenderer ar = new StackedAreaRenderer2() {
        private static final long serialVersionUID = 7962375662395944968L;

        @Override
        public Paint getItemPaint(int row, int column) {
            ChartLabel key = (ChartLabel) dataset.getColumnKey(column);
            if (key.getColor() != null)
                return key.getColor();
            return super.getItemPaint(row, column);
        }

        @Override
        public String generateURL(CategoryDataset dataset, int row, int column) {
            ChartLabel label = (ChartLabel) dataset.getColumnKey(column);
            return label.getURL() + relativeUrl;
        }

        @Override
        public String generateToolTip(CategoryDataset dataset, int row, int column) {
            ChartLabel label = (ChartLabel) dataset.getColumnKey(column);
            return label.getToolTipText();
        }
    };
    plot.setRenderer(ar);

    ar.setSeriesPaint(0, ColorPalette.RED); // Skips.
    ar.setSeriesPaint(1, ColorPalette.YELLOW); // Failures.
    ar.setSeriesPaint(2, ColorPalette.BLUE); // Total.

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

    return chart;
}

From source file:com.cwctravel.hudson.plugins.multimoduletests.TrendGraph.java

@Override
protected JFreeChart createGraph() {
    final CategoryDataset dataset = createDataSet().build();

    final JFreeChart chart = ChartFactory.createStackedAreaChart(null, // chart
            // title
            null, // unused
            yLabel, // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, // tooltips
            false // urls
    );/* w w  w  .  j  a va2s .com*/

    chart.setBackgroundPaint(Color.white);

    final CategoryPlot plot = chart.getCategoryPlot();

    // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setBackgroundPaint(Color.WHITE);
    plot.setOutlinePaint(null);
    plot.setForegroundAlpha(0.8f);
    // plot.setDomainGridlinesVisible(true);
    // plot.setDomainGridlinePaint(Color.white);
    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);

    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    ChartUtil.adjustChebyshev(dataset, rangeAxis);
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setAutoRange(true);

    StackedAreaRenderer ar = new StackedAreaRenderer2() {
        private static final long serialVersionUID = 7962375662395944968L;

        @Override
        public Paint getItemPaint(int row, int column) {
            ChartLabel key = (ChartLabel) dataset.getColumnKey(column);
            if (key.getColor() != null)
                return key.getColor();
            return super.getItemPaint(row, column);
        }

        @Override
        public String generateURL(CategoryDataset dataset, int row, int column) {
            ChartLabel label = (ChartLabel) dataset.getColumnKey(column);
            return prefixUrl + label.getURL() + suffixUrl;
        }

        @Override
        public String generateToolTip(CategoryDataset dataset, int row, int column) {
            ChartLabel label = (ChartLabel) dataset.getColumnKey(column);
            return label.getToolTipText();
        }
    };
    plot.setRenderer(ar);

    ar.setSeriesPaint(0, ColorPalette.RED); // Skips.
    ar.setSeriesPaint(1, ColorPalette.YELLOW); // Failures.
    ar.setSeriesPaint(2, ColorPalette.BLUE); // Total.

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

    return chart;
}

From source file:org.drools.planner.benchmark.core.report.BenchmarkReport.java

private CategoryPlot createBarChartPlot(DefaultCategoryDataset dataset, String yAxisLabel,
        NumberFormat numberFormat) {
    CategoryAxis xAxis = new CategoryAxis("Data");
    xAxis.setCategoryMargin(0.40);
    NumberAxis yAxis = new NumberAxis(yAxisLabel);
    yAxis.setNumberFormatOverride(numberFormat);
    BarRenderer renderer = createBarChartRenderer(numberFormat);
    CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);
    plot.setOrientation(PlotOrientation.VERTICAL);
    return plot;//  w w  w .  j av  a2s .c o m
}

From source file:hudson.graph.jfreechart.JFreeChartSupport.java

public JFreeChart createChart() {

    if (chartType == Graph.TYPE_STACKED_AREA) {
        jFreeChart = ChartFactory.createStackedAreaChart(null, // chart
                chartTitle, // // title 
                xAxisLabel, // range axis label
                dataset, // data
                PlotOrientation.VERTICAL, // orientation
                false, // include legend
                true, // tooltips
                false // urls
        );//ww w.ja  v  a  2s . co  m
    } else if (chartType == Graph.TYPE_LINE) {
        jFreeChart = ChartFactory.createLineChart(null, // chart title
                chartTitle, // // title 
                xAxisLabel, // range axis label
                dataset, // data
                PlotOrientation.VERTICAL, // orientation
                true, // include legend
                true, // tooltips
                false // urls
        );
    }

    jFreeChart.setBackgroundPaint(Color.white);

    final CategoryPlot plot = jFreeChart.getCategoryPlot();

    // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setBackgroundPaint(Color.WHITE);
    plot.setOutlinePaint(null);
    plot.setForegroundAlpha(0.8f);
    // plot.setDomainGridlinesVisible(true);
    // plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.black);

    if (chartType == Graph.TYPE_LINE) {
        final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
        renderer.setBaseStroke(new BasicStroke(3));

        if (multiStageTimeSeries != null) {
            for (int i = 0; i < multiStageTimeSeries.size(); i++) {
                renderer.setSeriesPaint(i, multiStageTimeSeries.get(i).color);
            }
        }
    }

    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);

    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    Utils.adjustChebyshev(dataset, rangeAxis);
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    if (chartType == Graph.TYPE_STACKED_AREA) {
        StackedAreaRenderer ar = new StackedAreaRenderer2() {

            @Override
            public Paint getItemPaint(int row, int column) {
                if (row == 2) {
                    return ColorPalette.BLUE;
                }
                if (row == 1) {
                    return ColorPalette.YELLOW;
                }
                if (row == 0) {
                    return ColorPalette.RED;
                }
                ChartLabel key = (ChartLabel) dataset.getColumnKey(column);
                return key.getColor(row, column);
            }

            @Override
            public String generateURL(CategoryDataset dataset, int row, int column) {
                ChartLabel label = (ChartLabel) dataset.getColumnKey(column);
                return label.getLink(row, column);
            }

            @Override
            public String generateToolTip(CategoryDataset dataset, int row, int column) {
                ChartLabel label = (ChartLabel) dataset.getColumnKey(column);
                return label.getToolTip(row, column);
            }
        };
        plot.setRenderer(ar);
        ar.setSeriesPaint(0, ColorPalette.RED); // Failures.
        ar.setSeriesPaint(1, ColorPalette.YELLOW); // Skips.
        ar.setSeriesPaint(2, ColorPalette.BLUE); // Total.
    }

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

    return jFreeChart;
}

From source file:com.mentor.questa.vrm.jenkins.QuestaVrmHostAction.java

private JFreeChart createChart(StaplerRequest req, CategoryDataset dataset) {

    final JFreeChart chart = ChartFactory.createStackedAreaChart(null, // chart title
            "Relative time", // unused
            "count", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, // tooltips
            false // urls
    );/*from www  .  jav a  2  s.  c  o m*/

    chart.setBackgroundPaint(Color.white);

    final 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);

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

    StackedAreaRenderer ar = new StackedAreaRenderer2() {
        private long getTime(CategoryDataset dataset, int column) {
            Long offset = (Long) dataset.getColumnKey(column);
            return getRegressionResult().getRegressionBegin().getTime() + offset * 1000;

        }

        @Override
        public String generateURL(CategoryDataset dataset, int row, int column) {
            return "javascript:getSummary(" + getTime(dataset, column) + ");";
        }

        @Override
        public String generateToolTip(CategoryDataset dataset, int row, int column) {
            String host = (String) dataset.getRowKey(row);
            Date date = new Date(getTime(dataset, column));
            int value = (Integer) dataset.getValue(row, column);
            return value + " on " + host + "@" + date.toString();
        }
    };
    plot.setRenderer(ar);

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

    return chart;
}

From source file:gov.nih.nci.cma.web.graphing.GEPlot.java

public String generateGeometricMeanIntensityChart(String xAxisLabel, String yAxisLabel, HttpSession session,
        PrintWriter pw) {//from  w ww  .  ja v  a2  s.c  o  m
    String gmfilename = "";

    JFreeChart gmChart = null;
    try {

        gmChart = ChartFactory.createBarChart(null, xAxisLabel, // domain axis label
                yAxisLabel, gmDataset, // data
                PlotOrientation.VERTICAL, // orientation
                true, // include legend
                true, // tooltips?
                false // URLs?
        );
        gmChart.setBackgroundPaint(java.awt.Color.white);
        // lets start some customization to retro fit w/jcharts lookand feel
        CategoryPlot plot = gmChart.getCategoryPlot();
        CategoryAxis axis = plot.getDomainAxis();
        axis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45);
        axis.setLowerMargin(0.02); // two percent
        axis.setCategoryMargin(0.20); // 20 percent
        axis.setUpperMargin(0.02); // two percent
        //StatisticalBarRenderer renderer = new StatisticalBarRenderer();
        BarRenderer renderer = (BarRenderer) plot.getRenderer();
        // BarRenderer renderer = (BarRenderer) plot.getRenderer();
        renderer.setItemMargin(0.01); // one percent
        renderer.setDrawBarOutline(true);
        renderer.setOutlinePaint(Color.BLACK);
        renderer.setBaseToolTipGenerator(new CategoryToolTipGenerator() {

            public String generateToolTip(CategoryDataset dataset, int series, int item) {
                String stdDev = (String) stdDevMap
                        .get(dataset.getRowKey(series) + "::" + dataset.getColumnKey(item));

                return "Probeset : " + dataset.getRowKey(series) + "<br/>Intensity : "
                        + new DecimalFormat("0.0000").format(dataset.getValue(series, item)) + "<br/>"
                        + "<br/>Std. Dev.: " + stdDev + "<br/>";
            }

        });

        plot.setRenderer(renderer);

        gmChart.removeLegend();
        ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
        //gmfilename = ServletUtilities.saveChartAsPNG(gmChart, imgW, 400, info, session);
        gmfilename = ServletUtilities.saveChartAsPNG(gmChart, imgW, 400, info, session);
        ChartUtilities.writeImageMap(pw, gmfilename, info, new CustomOverlibToolTipTagFragmentGenerator(),
                new StandardURLTagFragmentGenerator());

    } catch (Exception e) {
        System.out.println("Exception - " + e.toString());
        e.printStackTrace(System.out);
    }
    return gmfilename;
}

From source file:org.optaplanner.benchmark.impl.report.BenchmarkReport.java

private CategoryPlot createBarChartPlot(DefaultCategoryDataset dataset, String yAxisLabel,
        NumberFormat yAxisNumberFormat) {
    CategoryAxis xAxis = new CategoryAxis("Data");
    xAxis.setCategoryMargin(0.40);
    NumberAxis yAxis = new NumberAxis(yAxisLabel);
    yAxis.setNumberFormatOverride(yAxisNumberFormat);
    BarRenderer renderer = createBarChartRenderer(yAxisNumberFormat);
    CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);
    plot.setOrientation(PlotOrientation.VERTICAL);
    return plot;/*from  w ww .  j  ava 2  s.c o m*/
}