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

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

Introduction

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

Prototype

public void setUpperMargin(double margin) 

Source Link

Document

Sets the upper margin for the axis and sends an AxisChangeEvent to all registered listeners.

Usage

From source file:it.eng.spagobi.engines.chart.bo.charttypes.others.CumulativeCurveChart.java

public JFreeChart createChart(DatasetMap datasetMap) {
    CategoryDataset datasetValue = (CategoryDataset) datasetMap.getDatasets().get("1");
    CategoryDataset datasetCumulative = (CategoryDataset) datasetMap.getDatasets().get("2");

    JFreeChart chart = ChartFactory.createBarChart(name, // chart title
            xLabel, // domain axis label
            yLabel, // range axis label
            datasetValue, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, false);//from w  ww  .  ja va2s  . c  o m

    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.white);
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setLowerMargin(0.02);
    domainAxis.setUpperMargin(0.02);
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    // set the range axis to display integers only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    LineAndShapeRenderer renderer2 = new LineAndShapeRenderer();

    NumberAxis axis2 = new NumberAxis("Percent");
    axis2.setNumberFormatOverride(NumberFormat.getPercentInstance());
    plot.setRangeAxis(1, axis2);
    plot.setDataset(1, datasetCumulative);
    plot.setRenderer(1, renderer2);
    plot.mapDatasetToRangeAxis(1, 1);

    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    return chart;
}

From source file:com.mergano.core.AreaChart.java

private JFreeChart createChart(final CategoryDataset dataset) {

    final JFreeChart chart = ChartFactory.createAreaChart("Order statistic", // chart title
            "Days", // domain axis label
            "Order Average", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            false, // tooltips
            false // urls
    );// ww w .j av a 2  s  .c o m

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    // set the background color for the chart...
    //        final StandardLegend legend = (StandardLegend) chart.getLegend();
    //      legend.setAnchor(StandardLegend.SOUTH);
    chart.setBackgroundPaint(Color.white);
    chart.setAntiAlias(true);

    CategoryPlot plot = chart.getCategoryPlot();
    plot.getRenderer().setSeriesPaint(0, new Color(0, 191, 165));
    plot.setForegroundAlpha(0.75f);
    plot.setBackgroundPaint(Color.white);

    plot.setDomainCrosshairVisible(false);
    plot.setRangeCrosshairVisible(false);
    // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); // disable this
    plot.setDomainGridlinesVisible(false);
    plot.setDomainGridlinePaint(new Color(240, 240, 240));
    plot.setRangeGridlinesVisible(false);
    plot.setRangeGridlinePaint(new Color(240, 240, 240));
    plot.setDomainCrosshairPaint(Color.MAGENTA);
    plot.setRangeCrosshairPaint(Color.CYAN);

    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);
    domainAxis.addCategoryLabelToolTip("Type 1", "The first type.");
    domainAxis.addCategoryLabelToolTip("Type 2", "The second type.");
    domainAxis.addCategoryLabelToolTip("Type 3", "The third type.");

    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setLabelAngle(0 * Math.PI / 2.0);
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}

From source file:org.codehaus.mojo.dashboard.report.plugin.chart.BarChartRenderer.java

public void createChart() {
    CategoryDataset categorydataset = (CategoryDataset) this.datasetStrategy.getDataset();
    report = ChartFactory.createBarChart(this.datasetStrategy.getTitle(), this.datasetStrategy.getYAxisLabel(),
            this.datasetStrategy.getXAxisLabel(), categorydataset, PlotOrientation.HORIZONTAL, true, true,
            false);//from w  ww  .  ja va  2s .  co m
    // report.setBackgroundPaint( Color.lightGray );
    report.setPadding(new RectangleInsets(5.0d, 5.0d, 5.0d, 5.0d));
    CategoryPlot categoryplot = (CategoryPlot) report.getPlot();
    categoryplot.setBackgroundPaint(Color.white);
    categoryplot.setRangeGridlinePaint(Color.lightGray);
    categoryplot.setDomainGridlinePaint(Color.lightGray);
    categoryplot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    if (datasetStrategy instanceof CoberturaBarChartStrategy
            || datasetStrategy instanceof CloverBarChartStrategy
            || datasetStrategy instanceof MultiCloverBarChartStrategy) {
        numberaxis.setRange(0.0D, BarChartRenderer.NUMBER_AXIS_RANGE);
        numberaxis.setNumberFormatOverride(NumberFormat.getPercentInstance());
    } else {
        numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    }
    numberaxis.setLowerMargin(0.0D);
    CategoryAxis axis = categoryplot.getDomainAxis();
    axis.setLowerMargin(0.02); // two percent
    axis.setCategoryMargin(0.10); // ten percent
    axis.setUpperMargin(0.02); // two percent
    BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer();
    barrenderer.setItemMargin(0.10);
    barrenderer.setDrawBarOutline(false);
    barrenderer.setBaseItemLabelsVisible(true);
    if (datasetStrategy instanceof CoberturaBarChartStrategy
            || datasetStrategy instanceof CloverBarChartStrategy
            || datasetStrategy instanceof MultiCloverBarChartStrategy) {
        barrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}",
                NumberFormat.getPercentInstance(Locale.getDefault())));
    } else {
        barrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    }

    int height = (categorydataset.getColumnCount() * ChartUtils.STANDARD_BARCHART_ENTRY_HEIGHT
            * categorydataset.getRowCount());
    if (height > ChartUtils.MINIMUM_HEIGHT) {
        super.setHeight(height);
    } else {
        super.setHeight(ChartUtils.MINIMUM_HEIGHT);
    }

    Paint[] paints = this.datasetStrategy.getPaintColor();

    for (int i = 0; i < categorydataset.getRowCount() && i < paints.length; i++) {
        barrenderer.setSeriesPaint(i, paints[i]);
    }

}

From source file:org.evosuite.jenkins.plot.Plot.java

@Override
protected JFreeChart createGraph() {
    final JFreeChart chart = ChartFactory.createLineChart(null, "Build Number #", this.yLabel, this.dataset,
            PlotOrientation.VERTICAL, true, true, true);
    chart.setBackgroundPaint(Color.WHITE);

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

    CategoryAxis domainAxis = new CategoryAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    domainAxis.setLowerMargin(0.0);/*from  w  w w.  j  a v a 2  s .c  o  m*/
    domainAxis.setUpperMargin(0.0);
    domainAxis.setCategoryMargin(0.0);

    plot.setDomainAxis(domainAxis);
    plot.setBackgroundPaint(Color.WHITE);

    ValueAxis yAxis = plot.getRangeAxis();
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    //yAxis.setRange(0.0, 100.0);

    URLAndTooltipRenderer urlRenderer = new URLAndTooltipRenderer(this.project.getProject());
    ColorPalette.apply(urlRenderer);
    plot.setRenderer(urlRenderer);

    return chart;
}

From source file:gov.nih.nci.caintegrator.application.geneexpression.GeneExpressionPlotServiceImpl.java

private void customizeAxisMargin(JFreeChart chart) {
    CategoryAxis axis = chart.getCategoryPlot().getDomainAxis();
    axis.setLowerMargin(LOWER_MARGIN);//from ww  w  .j  a  va 2s  .  c o  m
    axis.setCategoryMargin(CATEGORY_MARGIN);
    axis.setUpperMargin(UPPER_MARGIN);
}

From source file:com.choicemaker.cm.modelmaker.gui.panels.StatisticsHistogramPanel.java

private void buildPanel() {
    final PlotOrientation orientation = PlotOrientation.VERTICAL;
    data = new HistoCategoryDataset(SERIES, getNumBins());
    histogram = ChartFactory.createBarChart(
            ChoiceMakerCoreMessages.m.formatMessage("train.gui.modelmaker.panel.histogram.cm.accuracy"),
            ChoiceMakerCoreMessages.m.formatMessage("train.gui.modelmaker.panel.histogram.cm.matchprob"),
            ChoiceMakerCoreMessages.m.formatMessage("train.gui.modelmaker.panel.histogram.cm.numpairs"), data,
            orientation, true, true, true);
    histogram.setBackgroundPaint(getBackground());
    CategoryPlot plot = (CategoryPlot) histogram.getPlot();
    plot.setForegroundAlpha(0.9f);//from  ww  w.  j  av a 2s .  c  om
    //      HorizontalCategoryAxis axis = (HorizontalCategoryAxis) plot.getDomainAxis();
    CategoryAxis axis = plot.getDomainAxis();
    axis.setLowerMargin(0.02);
    axis.setUpperMargin(0.02);
    axis.setCategoryMargin(0.2);
    //      axis.setVerticalCategoryLabels(true);
    CategoryItemRenderer renderer = plot.getRenderer();
    whSeriesPaint = new Paint[3];
    for (int i = 0; i < whSeriesPaint.length; ++i) {
        //         whSeriesPaint[i] = renderer.getSeriesPaint(0, i);
        whSeriesPaint[i] = renderer.getSeriesPaint(i);
    }
    wohSeriesPaint = new Paint[2];
    wohSeriesPaint[0] = whSeriesPaint[0];
    wohSeriesPaint[1] = whSeriesPaint[2];
    //   plot.setRangeAxis(new VerticalLogarithmicAxis());
    histoPanel = new HistoChartPanel(histogram, false, false, false, true, true, parent.getModelMaker());
    //   histoPanel.setEnabled(false);

    binWidthLabel = new JLabel(
            ChoiceMakerCoreMessages.m.formatMessage("train.gui.modelmaker.panel.histogram.binwidth"));
    binWidthField = new JTextField(Float.toString(binWidth), 4);
    binWidthField.setMinimumSize(new Dimension(50, 20));
}

From source file:com.intel.stl.ui.common.view.ComponentFactory.java

public static JFreeChart createBarChart(String xAxisLabel, String yAxisLabel, CategoryDataset dataset) {
    if (dataset == null) {
        throw new IllegalArgumentException("No dataset.");
    }// w  w w  . j a  v a 2s  . c  o m

    JFreeChart jfreechart = ChartFactory.createBarChart(null, xAxisLabel, yAxisLabel, dataset,
            PlotOrientation.VERTICAL, false, true, false);
    CategoryPlot categoryplot = jfreechart.getCategoryPlot();
    categoryplot.setBackgroundPaint(null);
    categoryplot.setOutlinePaint(null);
    categoryplot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    categoryplot.setRangePannable(true);
    categoryplot.setRangeGridlinePaint(UIConstants.INTEL_DARK_GRAY);
    categoryplot.getRangeAxis().setLabelFont(UIConstants.H5_FONT);
    categoryplot.getDomainAxis().setLabelFont(UIConstants.H5_FONT);

    BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer();
    barrenderer.setBarPainter(new StandardBarPainter());
    barrenderer.setBaseItemLabelsVisible(true);
    barrenderer.setShadowVisible(false);
    barrenderer.setSeriesPaint(0, UIConstants.INTEL_BLUE);

    CategoryAxis categoryaxis = categoryplot.getDomainAxis();
    categoryaxis.setCategoryMargin(0.02D);
    categoryaxis.setUpperMargin(0.01D);
    categoryaxis.setLowerMargin(0.01D);
    // categoryaxis.setAxisLineVisible(false);
    categoryaxis.setMaximumCategoryLabelWidthRatio(0.95F);

    NumberAxis axis = (NumberAxis) categoryplot.getRangeAxis();
    axis.setRangeType(RangeType.POSITIVE);

    return jfreechart;
}

From source file:com.intel.stl.ui.common.view.ComponentFactory.java

public static JFreeChart createTopNBarChart(String yAxisLabel, CategoryDataset dataset) {
    JFreeChart jfreechart = ChartFactory.createBarChart(null, null, yAxisLabel, dataset,
            PlotOrientation.HORIZONTAL, true, true, false);
    CategoryPlot categoryplot = jfreechart.getCategoryPlot();
    categoryplot.setBackgroundPaint(null);
    categoryplot.setOutlinePaint(null);// w w  w  .  j  a va  2s .c  o  m
    categoryplot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    categoryplot.setRangePannable(true);
    categoryplot.setRangeGridlinesVisible(true);
    categoryplot.setRangeGridlinePaint(UIConstants.INTEL_DARK_GRAY);

    BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer();
    barrenderer.setBarPainter(new StandardBarPainter());
    barrenderer.setShadowVisible(false);
    barrenderer.setItemMargin(0.015);
    barrenderer.setSeriesPaint(0, UIConstants.INTEL_BLUE);
    barrenderer.setSeriesPaint(1, UIConstants.INTEL_LIGHT_BLUE);

    CategoryAxis categoryaxis = categoryplot.getDomainAxis();
    categoryaxis.setCategoryMargin(0.15D);
    categoryaxis.setUpperMargin(0.02D);
    categoryaxis.setLowerMargin(0.02D);
    categoryaxis.setMaximumCategoryLabelWidthRatio(0.5F);

    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setRangeType(RangeType.POSITIVE);
    numberaxis.setStandardTickUnits(createLargeNumberTickUnits());
    numberaxis.setUpperMargin(0.20000000000000001D);
    numberaxis.setLabelFont(UIConstants.H5_FONT);
    numberaxis.setLabelInsets(new RectangleInsets(0, 0, 0, 0));
    numberaxis.setTickMarksVisible(true);
    numberaxis.setTickLabelsVisible(true);

    LegendTitle legend = jfreechart.getLegend();
    legend.setFrame(BlockBorder.NONE);
    legend.setItemFont(barrenderer.getBaseItemLabelFont().deriveFont(10.0f));

    return jfreechart;
}

From source file:com.thalesgroup.hudson.plugins.klocwork.graph.KloTrendGraph.java

@Override
protected JFreeChart createGraph() {
    final JFreeChart chart = ChartFactory.createLineChart(null, // chart title
            null, // unused
            yLabel, // range axis label
            categoryDataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
    );//from w w w .  j a  v  a 2s.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.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setBackgroundPaint(Color.WHITE);
    plot.setOutlinePaint(null);
    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());
    rangeAxis.setLowerBound(0);
    rangeAxis.setAutoRange(true);

    final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    renderer.setBaseStroke(new BasicStroke(2.0f));
    ColorPalette.apply(renderer);

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

    return chart;
}

From source file:com.seniorproject.augmentedreality.test.AreaChartDemo.java

/**
 * Creates a chart.//from  w  w w .  j  ava  2s .c om
 * 
 * @param dataset  the dataset.
 * 
 * @return The chart.
 */
private JFreeChart createChart(final CategoryDataset dataset) {

    final JFreeChart chart = ChartFactory.createAreaChart("Area Chart", // 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...
    //        final StandardLegend legend = (StandardLegend) chart.getLegend();
    //      legend.setAnchor(StandardLegend.SOUTH);

    chart.setBackgroundPaint(Color.white);
    final TextTitle subtitle = 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.");
    subtitle.setFont(new Font("SansSerif", Font.PLAIN, 12));
    subtitle.setPosition(RectangleEdge.TOP);
    //        subtitle.setSpacer(new Spacer(Spacer.RELATIVE, 0.05, 0.05, 0.05, 0.05));
    subtitle.setVerticalAlignment(VerticalAlignment.BOTTOM);
    chart.addSubtitle(subtitle);

    final 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);
    plot.setDomainGridlinesVisible(true);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);

    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);
    domainAxis.addCategoryLabelToolTip("Type 1", "The first type.");
    domainAxis.addCategoryLabelToolTip("Type 2", "The second type.");
    domainAxis.addCategoryLabelToolTip("Type 3", "The third type.");

    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setLabelAngle(0 * Math.PI / 2.0);
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}