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

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

Introduction

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

Prototype

public void setCategoryLabelPositions(CategoryLabelPositions positions) 

Source Link

Document

Sets the category label position specification for the axis and sends an AxisChangeEvent to all registered listeners.

Usage

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

/**
 * Creates a graph for Emma Coverage results.
 *
 * @param summaries//ww w  .j  a v a  2  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, 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//from w ww  .  j  a  va  2 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, 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.amanzi.splash.chart.Charts.java

/**
 * This method creates a chart./*  w w  w  .  jav a 2 s . co m*/
 * 
 * @param dataset. dataset provides the data to be displayed in the chart. The parameter is
 *        provided by the 'createDataset()' method.
 * @return A chart.
 */
public static JFreeChart createBarChart(DefaultCategoryDataset dataset) {

    // create the chart...
    JFreeChart chart = ChartFactory.createBarChart("", // chart title
            "", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );

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

    // set the range axis to display integers only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // disable bar outlines...
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);

    // 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));
    renderer.setSeriesPaint(0, gp0);

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));
    return chart;
}

From source file:org.amanzi.splash.chart.Charts.java

/**
 * Creates a bar chart//  w  w  w  . java 2 s  .c  om
 *
 * @param reportChart chart model
 * @return a JFreeChart
 */
public static JFreeChart createBarChart(Chart reportChart) {

    // create the chart...
    JFreeChart chart = ChartFactory.createBarChart(reportChart.getTitle(), // chart title
            reportChart.getDomainAxisLabel(), // domain axis label
            reportChart.getRangeAxisLabel(), // range axis label
            ((CategoryPlot) reportChart.getPlot()).getDataset(), // data
            reportChart.getOrientation(), // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );

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

    // set the range axis to display integers only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // disable bar outlines...
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);

    // 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));
    renderer.setSeriesPaint(0, gp0);

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.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.
 * /* ww  w. ja  v  a 2  s. c om*/
 * 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:barChart1.BarChartDemo.java

/**
 * Creates a sample chart./*  w  w w  .  ja  va  2  s  .  com*/
 * 
 * @param dataset  the dataset.
 * 
 * @return The chart.
 */
private static JFreeChart createChart(CategoryDataset dataset) {

    // create the chart...
    JFreeChart chart = ChartFactory.createBarChart("Belgium vs Italy vs Ireland ", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );

    // 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 = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);

    // set the range axis to display integers only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // disable bar outlines...
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);

    // set up gradient paints for series...
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(0, 0, 64));
    GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 64, 0));
    GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(64, 0, 0));

    GradientPaint gp3 = new GradientPaint(0.0f, 0.0f, Color.yellow, 0.0f, 0.0f, new Color(64, 0, 0));
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    renderer.setSeriesPaint(2, gp2);
    renderer.setSeriesPaint(3, gp2);

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}

From source file:eu.cassandra.training.utils.ChartUtils.java

/**
 * This function is used for the visualization of two Area Diagrams.
 * //from w  w w .  j a  v  a  2s .  c  om
 * @param title
 *          The title of the chart.
 * @param x
 *          The unit on the X axis of the chart.
 * @param y
 *          The unit on the Y axis of the chart.
 * @param doubles
 *          The array of values of the first array.
 * @param doubles2
 *          The array of values of the second array.
 * @return a chart panel with the graphical representation.
 */
public static ChartPanel createArea(String title, String x, String y, Double[] doubles, Double[] doubles2) {
    JFreeChart chart = null;
    if (doubles.length != doubles2.length) {
        System.out.println("ERROR with lengths.");
    } else {
        Double[][] data = new Double[2][doubles.length];

        data[0] = doubles;
        data[1] = doubles2;

        final CategoryDataset dataset = DatasetUtilities.createCategoryDataset("Power ", "", data);

        chart = ChartFactory.createAreaChart(title, x, y, dataset, PlotOrientation.VERTICAL, true, true, false);

        chart.setBackgroundPaint(Color.white);

        CategoryPlot plot = chart.getCategoryPlot();
        plot.setForegroundAlpha(0.5f);

        // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
        plot.setBackgroundPaint(Color.lightGray);

        CategoryAxis domainAxis = plot.getDomainAxis();
        domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
        // domainAxis.setTickUnit(new NumberTickUnit(10));
        NumberAxis numberaxis = (NumberAxis) plot.getRangeAxis();
        numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    }
    return new ChartPanel(chart);
}

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

private static JFreeChart createBarChart(CategoryDataset dataset) {

    JFreeChart chart = ChartFactory.createBarChart("Bar Chart Demo 1", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.HORIZONTAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );/* w ww .  j a va 2s .c o m*/

    chart.setBackgroundPaint(Color.white);

    CategoryPlot plot = (CategoryPlot) chart.getPlot();

    // set the range axis to display integers only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // disable bar outlines...
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);

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

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

    return chart;

}

From source file:weka.core.ChartUtils.java

/**
 * Render a histogram chart from summary data (i.e. a list of bin labels and
 * corresponding frequencies) to a buffered image
 * //from w  ww.j a  v  a 2s  . co m
 * @param width the width of the resulting image
 * @param height the height of the resulting image
 * @param bins the list of bin labels
 * @param freqs the corresponding bin frequencies
 * @param additionalArgs optional arguments to the renderer (may be null)
 * @return a histogram as a buffered image
 * @throws Exception if a problem occurs
 */
public static BufferedImage renderHistogramFromSummaryData(int width, int height, List<String> bins,
        List<Double> freqs, List<String> additionalArgs) throws Exception {

    JFreeChart chart = getHistogramFromSummaryDataChart(bins, freqs, additionalArgs);
    CategoryAxis axis = chart.getCategoryPlot().getDomainAxis();
    axis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    Font newFont = new Font("SansSerif", Font.PLAIN, 11);
    axis.setTickLabelFont(newFont);
    BufferedImage image = chart.createBufferedImage(width, height);
    return image;
}

From source file:net.sf.jsfcomp.chartcreator.utils.ChartAxisUtils.java

public static void createCategorySeriesAxis(JFreeChart chart, ChartAxisData chartAxisData, int axisIndex) {
    CategoryPlot plot = chart.getCategoryPlot();
    if (chartAxisData.isDomain()) {
        CategoryAxis axis = new CategoryAxis(chartAxisData.getLabel());
        axis.setTickLabelsVisible(chartAxisData.isTickLabels());
        axis.setTickMarksVisible(chartAxisData.isTickMarks());

        if (chartAxisData.getTickLabelFontSize() > 0) {
            Font tickFont = CategoryAxis.DEFAULT_TICK_LABEL_FONT
                    .deriveFont(chartAxisData.getTickLabelFontSize());
            axis.setTickLabelFont(tickFont);
        }/*from   w w w  .  ja  va 2s  .  co  m*/
        if (chartAxisData.isVerticalTickLabels()) {
            axis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
        }
        plot.setDomainAxis(plot.getDomainAxisCount() - 1, axis);
    } else {
        ValueAxis axis = createNumberAxis(chart, chartAxisData);
        axis.setTickLabelsVisible(chartAxisData.isTickLabels());
        axis.setTickMarksVisible(chartAxisData.isTickMarks());

        if (chartAxisData.getTickLabelFontSize() > 0) {
            Font tickFont = CategoryAxis.DEFAULT_TICK_LABEL_FONT
                    .deriveFont(chartAxisData.getTickLabelFontSize());
            axis.setTickLabelFont(tickFont);
        }
        plot.setRangeAxis(axis);
    }
}