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:com.ewcms.plugin.report.generate.service.chart.ChartGenerationService.java

/**
 * ?/*from w w w .ja va 2 s. c om*/
 *
 * @param title 
 * @param titleFont 
 * @param categoryAxisLabel 
 * @param valueAxisLabel 
 * @param data ??
 * @param orientation ?
 * @param legend 
 * @param tooltips ????
 * @param urls ??URL
 * @param urlGenerator
 *
 * @return ?
 */
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());
        renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    }
    if (urls) {
        //            renderer.setItemURLGenerator(urlGenerator);
        renderer.setBaseItemURLGenerator(urlGenerator);
    }
    CategoryPlot plot = new CategoryPlot(data, categoryAxis, valueAxis, renderer);
    plot.setOrientation(orientation);
    JFreeChart chart = new JFreeChart(title, titleFont, plot, legend);

    return chart;

}

From source file:org.tap4j.plugin.util.GraphHelper.java

public static JFreeChart createChart(StaplerRequest req, CategoryDataset dataset) {

    final JFreeChart chart = ChartFactory.createStackedAreaChart("TAP Tests", // chart title
            null, // unused
            "TAP Tests Count", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
    );// ww  w .  ja  va2 s. co m

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    final LegendTitle legend = chart.getLegend();
    legend.setPosition(RectangleEdge.RIGHT);

    chart.setBackgroundPaint(Color.white);

    final CategoryPlot plot = chart.getCategoryPlot();
    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();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

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

        @Override
        public String generateURL(CategoryDataset dataset, int row, int column) {
            NumberOnlyBuildLabel label = (NumberOnlyBuildLabel) dataset.getColumnKey(column);
            return label.build.getNumber() + "/" + AbstractTapProjectAction.URL_NAME + "/";
        }

        @Override
        public String generateToolTip(CategoryDataset dataset, int row, int column) {
            NumberOnlyBuildLabel label = (NumberOnlyBuildLabel) dataset.getColumnKey(column);
            TapBuildAction build = label.build.getAction(TapBuildAction.class);
            TapResult report = build.getResult();
            report.tally();

            switch (row) {
            case 0:
                return String.valueOf(report.getFailed()) + " Failure(s)";
            case 1:
                return String.valueOf(report.getPassed()) + " Pass";
            case 2:
                return String.valueOf(report.getSkipped()) + " Skip(s)";
            default:
                return "";
            }
        }

    };

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

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

    return chart;
}

From source file:org.tap4j.plugin.util.GraphHelper.java

/**
 * Creates the graph displayed on Method results page to compare execution
 * duration and status of a test method across builds.
 * //from   w ww .j a  v  a2s . c  o  m
 * At max, 9 older builds are displayed.
 * 
 * @param req
 *            request
 * @param dataset
 *            data set to be displayed on the graph
 * @param statusMap
 *            a map with build as key and the test methods execution status
 *            (result) as the value
 * @param methodUrl
 *            URL to get to the method from a build test result page
 * @return the chart
 */
public static JFreeChart createMethodChart(StaplerRequest req, final CategoryDataset dataset,
        final Map<NumberOnlyBuildLabel, String> statusMap, final String methodUrl) {

    final JFreeChart chart = ChartFactory.createBarChart(null, // chart
            // title
            null, // unused
            " Duration (secs)", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            true // urls
    );

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

    final CategoryPlot plot = chart.getCategoryPlot();
    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();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    BarRenderer br = new BarRenderer() {

        private static final long serialVersionUID = 961671076462240008L;
        Map<String, Paint> statusPaintMap = new HashMap<String, Paint>();

        {
            statusPaintMap.put("PASS", ColorPalette.BLUE);
            statusPaintMap.put("SKIP", ColorPalette.YELLOW);
            statusPaintMap.put("FAIL", ColorPalette.RED);
        }

        /**
         * Returns the paint for an item. Overrides the default behavior
         * inherited from AbstractSeriesRenderer.
         * 
         * @param row
         *            the series.
         * @param column
         *            the category.
         * 
         * @return The item color.
         */
        public Paint getItemPaint(final int row, final int column) {
            NumberOnlyBuildLabel label = (NumberOnlyBuildLabel) dataset.getColumnKey(column);
            Paint paint = statusPaintMap.get(statusMap.get(label));
            // when the status of test method is unknown, use gray color
            return paint == null ? Color.gray : paint;
        }
    };

    br.setBaseToolTipGenerator(new CategoryToolTipGenerator() {
        public String generateToolTip(CategoryDataset dataset, int row, int column) {
            NumberOnlyBuildLabel label = (NumberOnlyBuildLabel) dataset.getColumnKey(column);
            if ("UNKNOWN".equals(statusMap.get(label))) {
                return "unknown";
            }
            // values are in seconds
            return dataset.getValue(row, column) + " secs";
        }
    });

    br.setBaseItemURLGenerator(new CategoryURLGenerator() {
        public String generateURL(CategoryDataset dataset, int series, int category) {
            NumberOnlyBuildLabel label = (NumberOnlyBuildLabel) dataset.getColumnKey(category);
            if ("UNKNOWN".equals(statusMap.get(label))) {
                // no link when method result doesn't exist
                return null;
            }
            // return label.build.getUpUrl() + label.build.getNumber() + "/" + PluginImpl.URL + "/" + methodUrl;
            return label.build.getUpUrl() + label.build.getNumber() + "/tap/" + methodUrl;
        }
    });

    br.setItemMargin(0.0);
    br.setMinimumBarLength(5);
    // set the base to be 1/100th of the maximum value displayed in the
    // graph
    br.setBase(br.findRangeBounds(dataset).getUpperBound() / 100);
    plot.setRenderer(br);

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

From source file:hudson.plugins.codecover.portlet.chart.CodeCoverBuilderTrendChart.java

/**
 * Creates a graph for CodeCover Coverage results.
 *
 * @param summaries/*from   w ww. ja v a 2s .co  m*/
 *          HashMap(key = run date and value = Instrumentation tests
 *          results)
 * @param widthParam
 *          the chart width
 * @param heightParam
 *          the chart height
 * @return Graph (JFreeChart)
 */
private static Graph createTrendChart(final Map<LocalDate, CodeCoverCoverageResultSummary> summaries,
        int widthParam, int heightParam) {

    return new Graph(-1, widthParam, heightParam) {

        @Override
        protected JFreeChart createGraph() {

            // Show empty chart
            if (summaries == null) {
                JFreeChart chart = ChartFactory.createStackedAreaChart(null, Constants.AXIS_LABEL,
                        Constants.AXIS_LABEL_VALUE, null, PlotOrientation.VERTICAL, true, false, false);

                return chart;
            }

            int lineNumber = 0;

            JFreeChart chart = ChartFactory.createLineChart("", Constants.AXIS_LABEL,
                    Constants.AXIS_LABEL_VALUE, buildDataSet(summaries), PlotOrientation.VERTICAL, true, false,
                    false);

            chart.setBackgroundPaint(Color.white);

            CategoryPlot plot = chart.getCategoryPlot();

            // Line thickness
            CategoryItemRenderer renderer = plot.getRenderer();
            BasicStroke stroke = new BasicStroke(Constants.LINE_THICKNESS, BasicStroke.CAP_ROUND,
                    BasicStroke.JOIN_ROUND);
            renderer.setSeriesStroke(lineNumber++, stroke);
            renderer.setSeriesStroke(lineNumber++, stroke);
            renderer.setSeriesStroke(lineNumber++, stroke);
            renderer.setSeriesStroke(lineNumber, stroke);

            plot.setBackgroundPaint(Color.WHITE);
            plot.setOutlinePaint(null);
            plot.setForegroundAlpha(Constants.FOREGROUND_ALPHA);
            plot.setRangeGridlinesVisible(true);
            plot.setRangeGridlinePaint(Color.black);

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

            NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
            rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
            rangeAxis.setUpperBound(Constants.UPPER_BOUND);
            rangeAxis.setLowerBound(Constants.LOWER_BOUND);

            return chart;

        }
    };
}

From source file:hudson.plugins.karma.portlet.chart.KarmaBuilderTrendChart.java

/**
 * Creates a graph for Karma Coverage results.
 *
 * @param summaries/*from  www  . j  a  v a2 s . c  o m*/
 *          HashMap(key = run date and value = Instrumentation tests
 *          results)
 * @param widthParam
 *          the chart width
 * @param heightParam
 *          the chart height
 * @return Graph (JFreeChart)
 */
private static Graph createTrendChart(final Map<LocalDate, KarmaCoverageResultSummary> summaries,
        int widthParam, int heightParam) {

    return new Graph(-1, widthParam, heightParam) {

        @Override
        protected JFreeChart createGraph() {

            // Show empty chart
            if (summaries == null) {
                JFreeChart chart = ChartFactory.createStackedAreaChart(null, Constants.AXIS_LABEL,
                        Constants.AXIS_LABEL_VALUE, null, PlotOrientation.VERTICAL, true, false, false);

                return chart;
            }

            int lineNumber = 0;

            JFreeChart chart = ChartFactory.createLineChart("", Constants.AXIS_LABEL,
                    Constants.AXIS_LABEL_VALUE, buildDataSet(summaries), PlotOrientation.VERTICAL, true, false,
                    false);

            chart.setBackgroundPaint(Color.white);

            CategoryPlot plot = chart.getCategoryPlot();

            // Line thickness
            CategoryItemRenderer renderer = plot.getRenderer();
            BasicStroke stroke = new BasicStroke(Constants.LINE_THICKNESS, BasicStroke.CAP_ROUND,
                    BasicStroke.JOIN_ROUND);
            renderer.setSeriesStroke(lineNumber++, stroke);
            renderer.setSeriesStroke(lineNumber++, stroke);
            renderer.setSeriesStroke(lineNumber++, stroke);
            renderer.setSeriesStroke(lineNumber, stroke);

            plot.setBackgroundPaint(Color.WHITE);
            plot.setOutlinePaint(null);
            plot.setForegroundAlpha(Constants.FOREGROUND_ALPHA);
            plot.setRangeGridlinesVisible(true);
            plot.setRangeGridlinePaint(Color.black);

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

            NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
            rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
            rangeAxis.setUpperBound(Constants.UPPER_BOUND);
            rangeAxis.setLowerBound(Constants.LOWER_BOUND);

            return chart;

        }
    };
}

From source file:hudson.plugins.emma.portlet.chart.EmmaBuilderTrendChart.java

/**
 * Creates a graph for Emma Coverage results.
 *
 * @param summaries/*from  w  ww.ja v  a  2 s.co  m*/
 *          HashMap(key = run date and value = Instrumentation tests
 *          results)
 * @param widthParam
 *          the chart width
 * @param heightParam
 *          the chart height
 * @return Graph (JFreeChart)
 */
private static Graph createTrendChart(final Map<LocalDate, EmmaCoverageResultSummary> summaries, int widthParam,
        int heightParam) {

    return new Graph(-1, widthParam, heightParam) {

        @Override
        protected JFreeChart createGraph() {

            // Show empty chart
            if (summaries == null) {
                JFreeChart chart = ChartFactory.createStackedAreaChart(null, Constants.AXIS_LABEL,
                        Constants.AXIS_LABEL_VALUE, null, PlotOrientation.VERTICAL, true, false, false);

                return chart;
            }

            int lineNumber = 0;

            JFreeChart chart = ChartFactory.createLineChart("", Constants.AXIS_LABEL,
                    Constants.AXIS_LABEL_VALUE, buildDataSet(summaries), PlotOrientation.VERTICAL, true, false,
                    false);

            chart.setBackgroundPaint(Color.white);

            CategoryPlot plot = chart.getCategoryPlot();

            // Line thickness
            CategoryItemRenderer renderer = plot.getRenderer();
            BasicStroke stroke = new BasicStroke(Constants.LINE_THICKNESS, BasicStroke.CAP_ROUND,
                    BasicStroke.JOIN_ROUND);
            renderer.setSeriesStroke(lineNumber++, stroke);
            renderer.setSeriesStroke(lineNumber++, stroke);
            renderer.setSeriesStroke(lineNumber++, stroke);
            renderer.setSeriesStroke(lineNumber, stroke);

            plot.setBackgroundPaint(Color.WHITE);
            plot.setOutlinePaint(null);
            plot.setForegroundAlpha(Constants.FOREGROUND_ALPHA);
            plot.setRangeGridlinesVisible(true);
            plot.setRangeGridlinePaint(Color.black);

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

            NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
            rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
            rangeAxis.setUpperBound(Constants.UPPER_BOUND);
            rangeAxis.setLowerBound(Constants.LOWER_BOUND);

            return chart;

        }
    };
}

From source file:hudson.plugins.jacoco.portlet.chart.JacocoBuilderTrendChart.java

/**
 * Creates a graph for JaCoCo Coverage results.
 *
 * @param summaries/*  w w  w.  j a  va  2  s.  com*/
 *          HashMap(key = run date and value = Instrumentation tests
 *          results)
 * @param widthParam
 *          the chart width
 * @param heightParam
 *          the chart height
 * @return Graph (JFreeChart)
 */
private static Graph createTrendChart(final Map<LocalDate, JacocoCoverageResultSummary> summaries,
        int widthParam, int heightParam) {

    return new Graph(-1, widthParam, heightParam) {

        @Override
        protected JFreeChart createGraph() {

            // Show empty chart
            if (summaries == null) {
                JFreeChart chart = ChartFactory.createStackedAreaChart(null, Constants.AXIS_LABEL,
                        Constants.AXIS_LABEL_VALUE, null, PlotOrientation.VERTICAL, true, false, false);

                return chart;
            }

            int lineNumber = 0;

            JFreeChart chart = ChartFactory.createLineChart("", Constants.AXIS_LABEL,
                    Constants.AXIS_LABEL_VALUE, buildDataSet(summaries), PlotOrientation.VERTICAL, true, false,
                    false);

            chart.setBackgroundPaint(Color.white);

            CategoryPlot plot = chart.getCategoryPlot();

            // Line thickness
            CategoryItemRenderer renderer = plot.getRenderer();
            BasicStroke stroke = new BasicStroke(Constants.LINE_THICKNESS, BasicStroke.CAP_ROUND,
                    BasicStroke.JOIN_ROUND);
            renderer.setSeriesStroke(lineNumber++, stroke);
            renderer.setSeriesStroke(lineNumber++, stroke);
            renderer.setSeriesStroke(lineNumber++, stroke);
            renderer.setSeriesStroke(lineNumber, stroke);

            plot.setBackgroundPaint(Color.WHITE);
            plot.setOutlinePaint(null);
            plot.setForegroundAlpha(Constants.FOREGROUND_ALPHA);
            plot.setRangeGridlinesVisible(true);
            plot.setRangeGridlinePaint(Color.black);

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

            NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
            rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
            //rangeAxis.setUpperBound(Constants.UPPER_BOUND);
            rangeAxis.setLowerBound(Constants.LOWER_BOUND);

            return chart;

        }
    };
}

From source file:org.hxzon.demo.jfreechart.CategoryDatasetDemo2.java

private static JFreeChart createAreaChart(CategoryDataset dataset) {

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

    ValueAxis valueAxis = new NumberAxis(valueAxisLabel);

    AreaRenderer renderer = new AreaRenderer();
    if (tooltips) {
        renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    }/*from www  .j  a va  2  s .co m*/
    if (urls) {
        renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator());
    }

    CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer);
    plot.setOrientation(orientation);
    JFreeChart chart = new JFreeChart("Area Chart Demo 1", JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    chart.setBackgroundPaint(Color.white);

    renderer.setEndType(AreaRendererEndType.LEVEL);

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

    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    return chart;

}

From source file:com.xpn.xwiki.plugin.charts.ChartCustomizer.java

public static void customizeCategoryAxis(CategoryAxis axis, ChartParams params, String prefix) {
    customizeAxis(axis, params, prefix);

    if (params.get(prefix + ChartParams.CATEGORY_AXIS_CATEGORY_MARGIN_SUFFIX) != null) {
        axis.setCategoryMargin(
                params.getDouble(prefix + ChartParams.CATEGORY_AXIS_CATEGORY_MARGIN_SUFFIX).doubleValue());
    }//from w  w  w  .  j  a  va 2  s  .co m
    if (params.get(prefix + ChartParams.CATEGORY_AXIS_LABEL_POSITIONS_SUFFIX) != null) {
        axis.setCategoryLabelPositions(
                params.getCategoryLabelPositions(prefix + ChartParams.CATEGORY_AXIS_LABEL_POSITIONS_SUFFIX));
    }
    if (params.get(prefix + ChartParams.CATEGORY_AXIS_LABEL_POSITION_OFFSET_SUFFIX) != null) {
        axis.setCategoryLabelPositionOffset(
                params.getInteger(prefix + ChartParams.CATEGORY_AXIS_LABEL_POSITION_OFFSET_SUFFIX).intValue());
    }
    if (params.get(prefix + ChartParams.CATEGORY_AXIS_MAXIMUM_LABEL_LINES_SUFFIX) != null) {
        axis.setMaximumCategoryLabelLines(
                params.getInteger(prefix + ChartParams.CATEGORY_AXIS_MAXIMUM_LABEL_LINES_SUFFIX).intValue());
    }
    if (params.get(prefix + ChartParams.CATEGORY_AXIS_MAXIMUM_LABEL_WIDTH_RATIO_SUFFIX) != null) {
        axis.setMaximumCategoryLabelWidthRatio(params
                .getFloat(prefix + ChartParams.CATEGORY_AXIS_MAXIMUM_LABEL_WIDTH_RATIO_SUFFIX).floatValue());
    }
}

From source file:org.hxzon.demo.jfreechart.CategoryDatasetDemo2.java

private static JFreeChart createStackedAreaChart(CategoryDataset dataset) {

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

    StackedAreaRenderer renderer = new StackedAreaRenderer();
    if (tooltips) {
        renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    }/*from  w ww . ja v  a 2  s. c o  m*/
    if (urls) {
        renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator());
    }

    CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer);
    plot.setOrientation(orientation);
    JFreeChart chart = new JFreeChart("StackedArea Chart Demo 1", JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    chart.setBackgroundPaint(Color.white);

    valueAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    //        renderer.setRenderAsPercentages(true);

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

    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    return chart;

}