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

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

Introduction

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

Prototype

public void setUpperMargin(double margin) 

Source Link

Document

Sets the upper margin for the axis (as a percentage of the axis range) and sends an AxisChangeEvent to all registered listeners.

Usage

From source file:org.jfree.chart.demo.WaterfallChartDemo2.java

/**
 * Returns the chart./*from w w w  .j a v a 2 s .  com*/
 *
 * @param dataset  the dataset.
 * 
 * @return The chart.
 */
private JFreeChart createChart(final CategoryDataset dataset) {

    final CategoryAxis xAxis = new CategoryAxis("Category");
    final NumberAxis yAxis = new NumberAxis("$ in Thousands");
    yAxis.setLowerMargin(0.10);
    yAxis.setUpperMargin(0.10);

    // create a custom tick unit collection...
    final DecimalFormat formatter = new DecimalFormat("##,###");
    formatter.setNegativePrefix("(");
    formatter.setNegativeSuffix(")");
    final TickUnits standardUnits = new TickUnits();
    standardUnits.add(new NumberTickUnit(200, formatter));
    standardUnits.add(new NumberTickUnit(500, formatter));
    standardUnits.add(new NumberTickUnit(1000, formatter));
    standardUnits.add(new NumberTickUnit(2000, formatter));
    standardUnits.add(new NumberTickUnit(5000, formatter));

    yAxis.setStandardTickUnits(standardUnits);

    // ****************************************************************************
    // * JFREECHART DEVELOPER GUIDE                                               *
    // * The JFreeChart Developer Guide, written by David Gilbert, is available   *
    // * to purchase from Object Refinery Limited:                                *
    // *                                                                          *
    // * http://www.object-refinery.com/jfreechart/guide.html                     *
    // *                                                                          *
    // * Sales are used to provide funding for the JFreeChart project - please    * 
    // * support us so that we can continue developing free software.             *
    // ****************************************************************************

    final DecimalFormat labelFormatter = new DecimalFormat("##,###");
    labelFormatter.setNegativePrefix("(");
    labelFormatter.setNegativeSuffix(")");

    final WaterfallBarRenderer renderer = new WaterfallBarRenderer();
    //        renderer.setLabelGenerator(
    //          new StandardCategoryLabelGenerator("{2}", labelFormatter)
    //    );
    renderer.setItemLabelsVisible(Boolean.TRUE);

    final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.white);
    plot.setRangeGridlinesVisible(true);
    final ValueMarker baseline = new ValueMarker(0.0);
    baseline.setPaint(Color.blue);
    baseline.setStroke(new BasicStroke(1.1f));
    plot.addRangeMarker(baseline, Layer.FOREGROUND);

    final JFreeChart chart = new JFreeChart("OM WaterFall Chart", JFreeChart.DEFAULT_TITLE_FONT, plot, false);
    chart.setBackgroundPaint(Color.white);
    return chart;
}

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

private JFreeChart createChart(final CategoryDataset dataset) {

    final JFreeChart chart = ChartFactory.createBarChart("Revenue", "Monthly", "Amount", dataset,
            PlotOrientation.VERTICAL, false, true, false);

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

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

    // disable bar outlines...
    final CategoryItemRenderer renderer = plot.getRenderer();
    renderer.setSeriesItemLabelsVisible(0, Boolean.TRUE);

    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90);

    return chart;

}

From source file:org.jfree.chart.demo.ItemLabelDemo2.java

/**
 * Creates a sample chart.// w  ww .  ja  v  a  2s.c  o  m
 * 
 * @param dataset
 *           the dataset.
 * @return the chart.
 */
private JFreeChart createChart(final CategoryDataset dataset) {

    // create the chart...
    final JFreeChart chart = ChartFactory.createBarChart("Item Label Demo 2", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.HORIZONTAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );

    chart.setBackgroundPaint(Color.white);

    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setUpperMargin(0.25);

    final CategoryItemRenderer renderer = plot.getRenderer();
    renderer.setItemLabelsVisible(true);

    // use one or the other of the following lines to see the different modes for
    // the label generator...
    renderer.setLabelGenerator(new LabelGenerator(null));
    // renderer.setLabelGenerator(new LabelGenerator(0));

    return chart;

}

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

/**
 * Creates a chart.//from  ww w.  ja v  a  2  s .  co m
 * 
 * @param dataset  the dataset.
 * 
 * @return a chart.
 */
protected JFreeChart createChart(XYZDataset dataset) {
    // create the chart...
    JFreeChart chart = ChartFactory.createBubbleChart(chartTitle, // chart titl                          
            rangeLabel, // y axis label
            domainLabel, // x axis label
            dataset, // data
            PlotOrientation.VERTICAL, !legendPanelOn, // include legend
            true, // tooltips
            false // urls
    );

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setForegroundAlpha(0.65f);

    XYItemRenderer renderer = plot.getRenderer();
    renderer.setSeriesPaint(0, Color.blue);
    renderer.setLegendItemLabelGenerator(new SOCRXYZSeriesLabelGenerator());

    // increase the margins to account for the fact that the auto-range 
    // doesn't take into account the bubble size...
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setLowerMargin(0.15);
    domainAxis.setUpperMargin(0.15);
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setLowerMargin(0.15);
    rangeAxis.setUpperMargin(0.15);

    return chart;
}

From source file:org.perfrepo.web.controller.reports.testgroup.TestGroupChartBean.java

public void drawChart(OutputStream out, Object data) throws IOException {
    if (data instanceof ChartData) {
        ChartData chartData = (ChartData) data;
        JFreeChart chart = ChartFactory.createBarChart(chartData.getTitle(), "Test", "%",
                processDataSet(chartData), PlotOrientation.HORIZONTAL, false, true, false);
        chart.addSubtitle(new TextTitle("Comparison", new Font("Dialog", Font.ITALIC, 10)));
        chart.setBackgroundPaint(Color.white);
        CategoryPlot plot = (CategoryPlot) chart.getPlot();
        CustomRenderer renderer = new CustomRenderer();

        plot.setBackgroundPaint(Color.white);
        plot.setRangeGridlinePaint(Color.white);
        plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
        renderer.setBaseItemLabelGenerator(
                new StandardCategoryItemLabelGenerator("{2}%", NumberFormat.getInstance()));
        renderer.setBaseItemLabelsVisible(true);
        renderer.setDrawBarOutline(false);
        renderer.setMaximumBarWidth(1d / (chartData.getTests().length + 4.0));
        plot.setRenderer(renderer);/*from w  w w  . j a v a2 s  .  co m*/

        CategoryAxis categoryAxis = plot.getDomainAxis();
        categoryAxis.setCategoryMargin(0.1);

        categoryAxis.setUpperMargin(0.1);
        categoryAxis.setLowerMargin(0.1);
        NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
        rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        rangeAxis.setUpperMargin(0.10);
        BufferedImage buffImg = chart.createBufferedImage(640, chartData.getTests().length * 100 + 100);
        ImageIO.write(buffImg, "gif", out);
    }
}

From source file:org.openmrs.module.laboratorymanagement.web.chart.EvolutionOfClientRegisteredPerDay.java

/**
 * @see org.openmrs.module.vcttrac.web.view.chart.AbstractChartView#createChart(java.util.Map,
 *      javax.servlet.http.HttpServletRequest)
 *//*from w  w w. ja va2s .  co  m*/
@Override
protected JFreeChart createChart(Map<String, Object> model, HttpServletRequest request, String patientIdstr,
        String locationIdstr, int conceptId, Date startDate, Date endDate) {

    String categoryAxisLabel = " Year";
    String valueAxisLabel = "Number of Lab tests";

    String title = "EVolution of labotory test:"
            + Context.getConceptService().getConcept(conceptId).getDisplayString();

    JFreeChart chart = ChartFactory.createLineChart(title, categoryAxisLabel, valueAxisLabel,
            createDataset(patientIdstr, locationIdstr, conceptId, startDate, endDate), // data
            PlotOrientation.VERTICAL, true, false, false);

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinesVisible(true);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);

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

    // customise the renderer...
    LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    renderer.setBaseShapesVisible(true);
    renderer.setBaseShapesFilled(true);
    renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    renderer.setItemLabelsVisible(true);

    return chart;
}

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

/**
 *
 * @return//from  ww  w  .  j a  va 2 s .com
 */
public NumberAxis getRangeAxis() {
    NumberAxis valueaxis = new NumberAxis();
    valueaxis.setLowerMargin(0.0D);
    valueaxis.setUpperMargin(0.25D);
    valueaxis.setLabel(this.getYAxisLabel());
    return valueaxis;
}

From source file:net.sf.mzmine.modules.peaklistmethods.peakpicking.adap3decompositionV1_5.EICPlot.java

public EICPlot(List<List<NavigableMap<Double, Double>>> clusters, List<Double> colors, List<List<String>> info,
        List<NavigableMap<Double, Double>> modelPeaks) {
    super(null, true);

    setBackground(Color.white);/*  w ww . ja va  2s.  c  o m*/
    setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));

    NumberAxis xAxis = new NumberAxis("Retention Time");
    xAxis.setAutoRangeIncludesZero(false);
    xAxis.setUpperMargin(0);
    xAxis.setLowerMargin(0);

    NumberAxis yAxis = new NumberAxis("Intensity");
    yAxis.setAutoRangeIncludesZero(false);
    yAxis.setUpperMargin(0);
    yAxis.setLowerMargin(0);

    xyDataset = new XYSeriesCollection();
    colorDataset = new ArrayList<>();
    toolTips = new ArrayList<>();

    int seriesID = 0;

    for (int i = 0; i < clusters.size(); ++i) {
        List<NavigableMap<Double, Double>> cluster = clusters.get(i);
        double color = colors.get(i);

        for (int j = 0; j < cluster.size(); ++j) {
            XYSeries series = new XYSeries(seriesID++);

            for (Entry<Double, Double> e : cluster.get(j).entrySet())
                series.add(e.getKey(), e.getValue());

            xyDataset.addSeries(series);
            colorDataset.add(color);
            toolTips.add(info.get(i).get(j));
        }
    }

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer() {
        @Override
        public Paint getItemPaint(int row, int col) {
            double c = colorDataset.get(row);
            return Color.getHSBColor((float) c, 1.0f, 1.0f);
        }
    };

    renderer.setDefaultShapesVisible(false);
    renderer.setDefaultToolTipGenerator(new XYToolTipGenerator() {
        @Override
        public String generateToolTip(XYDataset dataset, int series, int item) {
            try {
                return toolTips.get(series);
            } catch (NullPointerException | IndexOutOfBoundsException e) {
                return "";
            }
        }
    });

    XYPlot plot = new XYPlot(xyDataset, xAxis, yAxis, renderer);
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinesVisible(true);

    JFreeChart chart = new JFreeChart("", new Font("SansSerif", Font.BOLD, 12), plot, false);
    chart.setBackgroundPaint(Color.white);

    super.setChart(chart);
}

From source file:net.sf.mzmine.modules.peaklistmethods.dataanalysis.rtmzplots.RTMZPlot.java

public RTMZPlot(RTMZAnalyzerWindow masterFrame, AbstractXYZDataset dataset,
        InterpolatingLookupPaintScale paintScale) {
    super(null);//from  www.  j  ava 2 s  . c  o  m

    this.paintScale = paintScale;

    chart = ChartFactory.createXYAreaChart("", "Retention time", "m/z", dataset, PlotOrientation.VERTICAL,
            false, false, false);
    chart.setBackgroundPaint(Color.white);
    setChart(chart);

    // title

    TextTitle chartTitle = chart.getTitle();
    chartTitle.setMargin(5, 0, 0, 0);
    chartTitle.setFont(titleFont);
    chart.removeSubtitle(chartTitle);

    // disable maximum size (we don't want scaling)
    setMaximumDrawWidth(Integer.MAX_VALUE);
    setMaximumDrawHeight(Integer.MAX_VALUE);

    // set the plot properties
    plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));

    // set grid properties
    plot.setDomainGridlinePaint(gridColor);
    plot.setRangeGridlinePaint(gridColor);

    // set crosshair (selection) properties
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    plot.setDomainCrosshairPaint(crossHairColor);
    plot.setRangeCrosshairPaint(crossHairColor);
    plot.setDomainCrosshairStroke(crossHairStroke);
    plot.setRangeCrosshairStroke(crossHairStroke);

    NumberFormat rtFormat = MZmineCore.getConfiguration().getRTFormat();
    NumberFormat mzFormat = MZmineCore.getConfiguration().getMZFormat();

    // set the X axis (retention time) properties
    NumberAxis xAxis = (NumberAxis) plot.getDomainAxis();
    xAxis.setNumberFormatOverride(rtFormat);
    xAxis.setUpperMargin(0.001);
    xAxis.setLowerMargin(0.001);

    // set the Y axis (intensity) properties
    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setAutoRangeIncludesZero(false);
    yAxis.setNumberFormatOverride(mzFormat);

    plot.setDataset(dataset);
    spotRenderer = new RTMZRenderer(dataset, paintScale);
    plot.setRenderer(spotRenderer);
    spotRenderer.setBaseToolTipGenerator(new RTMZToolTipGenerator());

    // Add a paintScaleLegend to chart

    paintScaleAxis = new NumberAxis("Logratio");
    paintScaleAxis.setRange(paintScale.getLowerBound(), paintScale.getUpperBound());

    paintScaleLegend = new PaintScaleLegend(paintScale, paintScaleAxis);
    paintScaleLegend.setPosition(plot.getDomainAxisEdge());
    paintScaleLegend.setMargin(5, 25, 5, 25);

    chart.addSubtitle(paintScaleLegend);

}

From source file:servlet.SalesReportEventsBarChart.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*w ww . j a  v  a2  s .  c o  m*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    List<ArrayList> data = productSession.getEventSessionNo();

    final DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    for (int i = 0; i < data.size(); i++) {
        dataset.addValue(Integer.valueOf(data.get(i).get(1).toString()), "Sessions",
                data.get(i).get(0).toString());
    }

    final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());

    JFreeChart barChart = ChartFactory.createBarChart("No of Sessions", "Event", "Sessions", dataset,
            PlotOrientation.VERTICAL, true, true, false);

    CategoryPlot cplot = (CategoryPlot) barChart.getPlot();
    cplot.setBackgroundPaint(Color.WHITE);//change background color

    //set  bar chart color
    ((BarRenderer) cplot.getRenderer()).setBarPainter(new StandardBarPainter());

    BarRenderer r = (BarRenderer) barChart.getCategoryPlot().getRenderer();
    r.setSeriesPaint(0, Color.GREEN);

    r.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}", NumberFormat.getInstance()));
    r.setBaseItemLabelsVisible(true);

    CategoryAxis categoryAxis = cplot.getDomainAxis();
    categoryAxis.setUpperMargin(0.15);

    NumberAxis rangeAxis = (NumberAxis) cplot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setUpperMargin(0.15);

    int width = 550; /* Width of the image */

    int height = 450; /* Height of the image */

    response.setContentType("image/png");
    OutputStream out = response.getOutputStream();

    ChartUtilities.writeChartAsPNG(out, barChart, 400, 300, info);

}