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:slash.navigation.converter.gui.elevationview.ElevationView.java

private XYPlot createPlot(JFreeChart chart) {
    XYPlot plot = chart.getXYPlot();/*  w  w w.j  a va 2 s .c  om*/
    plot.setForegroundAlpha(0.65F);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits());
    Font font = new JLabel().getFont();
    rangeAxis.setLabelFont(font);

    NumberAxis valueAxis = (NumberAxis) plot.getDomainAxis();
    valueAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits());
    valueAxis.setLowerMargin(0.0);
    valueAxis.setUpperMargin(0.0);
    valueAxis.setLabelFont(font);

    XYItemRenderer renderer = plot.getRenderer();
    renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{2}m @ {1} Km",
            NumberFormat.getIntegerInstance(), NumberFormat.getIntegerInstance()));
    return plot;
}

From source file:net.sf.maltcms.common.charts.ui.XYChartComponentOpenAction.java

@Override
public void actionPerformed(ActionEvent e) {
    Task t = RequestProcessor.getDefault().create(new Runnable() {
        @Override//from w  w  w  .ja v a2s .  c om
        public void run() {
            final Numeric1DDataset<Point2D> dataset = createDataset();
            final XYChartBuilder builder = new XYChartBuilder();
            XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, true);
            renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
            renderer.setBaseItemLabelsVisible(true);
            renderer.setDefaultEntityRadius(50);
            NumberAxis domain = new NumberAxis("x-axis");
            domain.setLowerBound(-100);
            domain.setUpperBound(1000);
            domain.setLowerMargin(0.1);
            domain.setUpperMargin(0.1);
            domain.setPositiveArrowVisible(true);
            domain.setNegativeArrowVisible(true);
            builder.xy(dataset).renderer(renderer).domainAxis(domain).useBuffer(false).minimumDrawSize(400, 300)
                    .preferredDrawSize(800, 600).plot().chart("Sample plot").createLegend(true);
            invokeLater(new Runnable() {
                @Override
                public void run() {
                    TopComponent tc = WindowManager.getDefault().findTopComponent("navigatorTC");
                    if (tc != null) {
                        tc.open();
                    }
                }
            });
            invokeLater(new Runnable() {

                @Override
                public void run() {
                    XYChartTopComponent<Point2D> xytc = new XYChartTopComponent<>(Point2D.class, dataset,
                            builder);
                    xytc.open();
                    xytc.requestActive();
                }
            });

        }
    });
    RequestProcessor.getDefault().post(t);
}

From source file:j2se.jfreechart.barchart.BarChartDemo8.java

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

    // create the chart...
    final JFreeChart chart = ChartFactory.createBarChart("Bar Chart Demo 8", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            false, // 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...
    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.lightGray);
    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.UP_45);

    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}

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

/**
 *
 *//*from   w  ww  .  j a  va 2 s.c o m*/
public void createChart() {

    XYPlot xyplot = (XYPlot) report.getPlot();
    if (this.decoratedChart instanceof TimeChartRenderer && this.results != null && !this.results.isEmpty()) {

        Iterator iter = this.results.iterator();
        TimeSeriesCollection defaultdataset = new TimeSeriesCollection();
        TimeSeries s1 = new TimeSeries("% success", Day.class);

        while (iter.hasNext()) {
            SurefireReportBean surefire = (SurefireReportBean) iter.next();
            Date date = surefire.getDateGeneration();
            s1.addOrUpdate(new Day(TimePeriod.DAY.normalize(date)), surefire.getSucessRate() / PCENT);

        }

        defaultdataset.addSeries(s1);

        XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
        renderer.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
        renderer.setSeriesPaint(0, ChartColor.DARK_BLUE);
        renderer.setBaseShapesVisible(true);
        renderer.setDrawOutlines(true);
        StandardXYItemLabelGenerator labelgenerator = new StandardXYItemLabelGenerator(
                StandardXYItemLabelGenerator.DEFAULT_ITEM_LABEL_FORMAT, TimePeriod.DAY.getDateFormat(),
                NumberFormat.getPercentInstance(Locale.getDefault()));
        renderer.setBaseItemLabelGenerator(labelgenerator);
        renderer.setBaseItemLabelFont(new Font("SansSerif", Font.BOLD, ITEM_LABEL_FONT_SIZE));
        renderer.setBaseItemLabelsVisible(true);
        renderer.setBasePositiveItemLabelPosition(
                new ItemLabelPosition(ItemLabelAnchor.OUTSIDE10, TextAnchor.BASELINE_RIGHT));

        renderer.setBaseStroke(new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));

        LegendTitle legendtitle = new LegendTitle(xyplot.getRenderer(0));
        legendtitle.setMargin(new RectangleInsets(2D, 2D, 2D, 2D));
        legendtitle.setFrame(new BlockBorder());
        legendtitle.setBackgroundPaint(ChartColor.WHITE);

        LegendTitle legendtitle1 = new LegendTitle(renderer);
        legendtitle1.setMargin(new RectangleInsets(2D, 2D, 2D, 2D));
        legendtitle1.setFrame(new BlockBorder());
        legendtitle1.setBackgroundPaint(ChartColor.WHITE);

        BlockContainer blockcontainer = new BlockContainer(new BorderArrangement());
        blockcontainer.add(legendtitle, RectangleEdge.LEFT);
        blockcontainer.add(legendtitle1, RectangleEdge.RIGHT);
        blockcontainer.add(new EmptyBlock(BLOCK_CONTAINER_WIDTH, 0.0D));

        CompositeTitle compositetitle = new CompositeTitle(blockcontainer);
        compositetitle.setPosition(RectangleEdge.BOTTOM);

        report.clearSubtitles();
        report.addSubtitle(compositetitle);

        xyplot.setDataset(1, defaultdataset);

        NumberAxis valueaxis = new NumberAxis("% success");
        valueaxis.setLowerMargin(0.0D);
        valueaxis.setUpperMargin(AXIS_UPPER_MARGIN);
        valueaxis.setRangeWithMargins(0.0D, 1.0D);
        valueaxis.setNumberFormatOverride(NumberFormat.getPercentInstance());
        xyplot.setRangeAxis(1, valueaxis);
        xyplot.mapDatasetToRangeAxis(1, 1);
        xyplot.setRenderer(1, renderer);
    }

}

From source file:edu.ucla.stat.SOCR.chart.demo.BarChartDemo8.java

/**
 * Creates a sample chart.//from www .j  a  v  a2s.  c o  m
 * 
 * @param dataset  the dataset.
 * 
 * @return The chart.
 */
protected JFreeChart createChart(CategoryDataset dataset) {

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

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

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

    CategoryItemRenderer renderer = plot.getRenderer();
    renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    renderer.setSeriesItemLabelsVisible(0, Boolean.TRUE);

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);

    BarRenderer seriesRenderer = (BarRenderer) plot.getRenderer();
    seriesRenderer.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator());

    setCategorySummary(dataset);
    return chart;

}

From source file:edu.ucla.stat.SOCR.chart.demo.QQNormalPlotDemo.java

/**
 * Creates a chart./*from   www  . j a  va  2s . com*/
 * 
 * @param dataset  the data for the chart.
 * 
 * @return a chart.
 */
protected JFreeChart createChart(XYDataset dataset) {

    // create the chart...
    JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, //"Normal Q-Q plot",      // chart title
            domainLabel, // x axis label
            rangeLabel, // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, !legendPanelOn, // include legend
            true, // tooltips
            false // urls
    );

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

    // get a reference to the plot for further customisation...
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    // renderer.setShapesVisible(true);
    renderer.setBaseShapesFilled(true);
    //  renderer.setLinesVisible(false);
    renderer.setSeriesLinesVisible(1, true);
    renderer.setSeriesShapesVisible(1, false);
    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesShapesVisible(0, true);

    //renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator());

    // change the auto tick unit selection to integer units only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setAutoRangeIncludesZero(false);
    rangeAxis.setUpperMargin(0.02);
    rangeAxis.setLowerMargin(0.02);

    // rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setAutoRangeIncludesZero(false);
    domainAxis.setUpperMargin(0.02);
    domainAxis.setLowerMargin(0.02);

    // domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // OPTIONAL CUSTOMISATION COMPLETED.
    //setQQSummary(dataset);    // very confusing   
    return chart;

}

From source file:de.fub.maps.project.detector.model.inference.ui.charts.PrecisionRecallBarChartPanel.java

/**
 * Creates new form PrecisionRecallBarChartPanel
 *//*ww w. j a  v a  2 s . c om*/
public PrecisionRecallBarChartPanel() {
    super();
    initComponents();
    barChart = ChartFactory.createBarChart(
            NbBundle.getMessage(PrecisionRecallBarChartPanel.class, "CLT_Chart_Precision_Recall_Name"),
            NbBundle.getMessage(PrecisionRecallBarChartPanel.class, "CLT_Doman_Axis_Name"),
            NbBundle.getMessage(PrecisionRecallBarChartPanel.class, "CLT_Value_Axis_Name"), dataset,
            PlotOrientation.VERTICAL, true, true, true);

    Font font = new JLabel().getFont().deriveFont(Font.BOLD, 14);

    barChart.getTitle().setFont(font);
    barChart.getTitle().setPaint(new Color(153, 153, 153));

    plot = barChart.getCategoryPlot();
    NumberAxis preciAxis = new NumberAxis(
            NbBundle.getMessage(PrecisionRecallBarChartPanel.class, "CLT_Value_Axis_Name"));
    preciAxis.setAutoRange(true);
    preciAxis.setUpperMargin(.20);
    plot.setRangeAxis(0, preciAxis);
    plot.setRangeAxisLocation(0, AxisLocation.TOP_OR_LEFT);
    plot.setBackgroundPaint(Color.white);

    BarRenderer barRenderer = new BarRenderer();
    barRenderer.setBarPainter(new StandardBarPainter());
    barRenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    barRenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator(
            StandardCategoryItemLabelGenerator.DEFAULT_LABEL_FORMAT_STRING, new CustomNumberFormat()));
    barRenderer.setBaseItemLabelsVisible(true);
    barRenderer.setSeriesPaint(0, precColor);
    barRenderer.setSeriesPaint(1, recColor);

    plot.setRenderer(barRenderer);

    chartPanel = new ChartPanel(barChart, false);
    chartPanel.setVerticalAxisTrace(false);
    add(chartPanel, BorderLayout.CENTER);
}

From source file:com.pureinfo.srm.reports.impl.CategoryChartBuilder.java

/**
 * @see com.pureinfo.srm.reports.IChartBuilder#buildChart(java.util.List,
 *      int, java.lang.String)/*  www.  j  ava  2s.co  m*/
 */
public JFreeChart buildChart() {
    CategoryDataset dataset = createDataset();

    JFreeChart jfreechart = MyChartFactory.createBarChart3D(null, m_sXAxisName, m_sYXxisName, dataset,
            PlotOrientation.VERTICAL, false, false, false);

    CategoryPlot categoryplot = jfreechart.getCategoryPlot();
    jfreechart.setBackgroundPaint(Color.white);
    categoryplot.setDomainGridlinesVisible(false);
    categoryplot.setRangeGridlinesVisible(true);

    categoryplot.setForegroundAlpha(0.8f);
    categoryplot.setDrawingSupplier(new DefaultDrawingSupplier(MyPaintMgr.getPaints(),
            DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE));
    CategoryAxis categoryAxisX = categoryplot.getDomainAxis();
    categoryAxisX.setTickLabelsVisible(true);
    categoryAxisX.setLabel(null);
    categoryAxisX.setMaximumCategoryLabelWidthRatio(.8f);
    ValueAxis categoryAxisY = categoryplot.getRangeAxis();
    categoryAxisY.setVerticalTickLabels(false);

    //        categoryplot.setDrawSharedDomainAxis(false);
    categoryAxisX.setCategoryLabelPositions(
            CategoryLabelPositions.createUpRotationLabelPositions(0.39269908169872414D));

    BarRenderer3D barrenderer3d = (BarRenderer3D) categoryplot.getRenderer();
    barrenderer3d.setDrawBarOutline(false);
    barrenderer3d.setItemLabelsVisible(true);

    barrenderer3d.setBaseItemLabelsVisible(false);
    barrenderer3d.setSeriesVisible(Boolean.FALSE);

    //CategoryPlot categoryPlot = jfreechart.getCategoryPlot();
    //        categoryPlot.setBackgroundPaint(Color.lightGray);
    //        categoryPlot.setDomainGridlinePaint(Color.white);
    //        categoryPlot.setRangeGridlinePaint(Color.white);
    //
    //        BarRenderer barRenderer = (BarRenderer) categoryPlot.getRenderer();
    //        barRenderer.setDrawBarOutline(false);
    //        barRenderer.setMaxBarWidth(0.03);
    //        GradientPaint gradientPaint = new GradientPaint(0.0F, 0.0F,
    // Color.red, 0.0F, 0.0F, new Color(64, 0, 0));
    //        barRenderer.setSeriesPaint(0, gradientPaint);

    DecimalFormat format = null;
    if (m_dblMaxData > 1) {
        format = new DecimalFormat("#,###");
    } else {
        StringBuffer sb = new StringBuffer();
        sb.append("0.00#");
        for (double i = m_dblMaxData; i != 0 && i < 1; i *= 10f) {
            sb.append("#");
        }
        format = new DecimalFormat(sb.toString());
    }
    fillChartInfo(dataset, format);
    barrenderer3d.setMaxBarWidth(8.0 / m_ChartInfo.getChartSize().x);
    NumberAxis numberAxis = (NumberAxis) categoryplot.getRangeAxis(0);
    numberAxis.setUpperMargin(0.149999999999D);
    numberAxis.setNumberFormatOverride(format);

    categoryAxisX.setCategoryLabelPositions(CategoryLabelPositions.UP_45);

    NumberAxis dataNumberAxis = (NumberAxis) categoryplot.getRangeAxisForDataset(0);
    dataNumberAxis.setUpperMargin(0.149999999999D);
    dataNumberAxis.setNumberFormatOverride(format);

    //        CategoryItemRenderer renderer = categoryPlot.getRenderer();
    //        CategoryItemLabelGenerator generator = new StandardCategoryItemLabelGenerator("{2}", format);
    //        renderer.setItemLabelGenerator(generator);
    //        renderer.setItemLabelFont(new Font("Serif", 0, 9));
    //        renderer.setItemLabelsVisible(true);
    return jfreechart;
}

From source file:compecon.dashboard.panel.AbstractChartsPanel.java

protected void configureChart(JFreeChart chart) {
    chart.setBackgroundPaint(Color.white);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));

    DateAxis dateAxis = (DateAxis) plot.getDomainAxis();
    NumberAxis valueAxis = (NumberAxis) plot.getRangeAxis();

    dateAxis.setDateFormatOverride(new SimpleDateFormat("dd-MMM"));
    valueAxis.setAutoRangeIncludesZero(true);
    valueAxis.setUpperMargin(0.15);
    valueAxis.setLowerMargin(0.15);/*from w w w  .ja va 2s  . co  m*/
}

From source file:edu.ucla.stat.SOCR.chart.demo.BarChartDemo3.java

/**
 * Creates a sample chart./*w ww .  j  av  a2 s  .co  m*/
 * 
 * @param dataset  the dataset.
 * 
 * @return a sample chart.
 */
protected JFreeChart createChart(CategoryDataset dataset) {

    JFreeChart chart = ChartFactory.createBarChart(chartTitle, // chart title
            domainLabel, // domain axis label
            rangeLabel, // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // the plot orientation
            !legendPanelOn, // include legend
            true, false);

    chart.setBackgroundPaint(Color.lightGray);

    // get a reference to the plot for further customisation...
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setNoDataMessage("NO DATA!");

    CategoryItemRenderer renderer = new CustomBarRenderer(new Paint[] { Color.red, Color.blue, Color.green,
            Color.yellow, Color.orange, Color.cyan, Color.magenta, Color.blue });
    renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    renderer.setBaseItemLabelsVisible(true);
    ItemLabelPosition p = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER,
            45.0);
    renderer.setBasePositiveItemLabelPosition(p);
    plot.setRenderer(renderer);

    CategoryMarker marker = new CategoryMarker("Category 3");
    marker.setLabel("Special");
    marker.setPaint(new Color(0xDD, 0xFF, 0xDD, 0x80));
    marker.setAlpha(0.5f);
    marker.setLabelAnchor(RectangleAnchor.TOP_LEFT);
    marker.setLabelTextAnchor(TextAnchor.TOP_LEFT);
    marker.setLabelOffsetType(LengthAdjustmentType.CONTRACT);
    plot.addDomainMarker(marker, Layer.BACKGROUND);

    // change the margin at the top of the range axis...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setLowerMargin(0.15);
    rangeAxis.setUpperMargin(0.15);

    BarRenderer seriesRenderer = (BarRenderer) plot.getRenderer();
    seriesRenderer.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator());

    setCategorySummary(dataset);
    return chart;

}