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

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

Introduction

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

Prototype

public void setRangeWithMargins(Range range, boolean turnOffAutoRange, boolean notify) 

Source Link

Document

Sets the range for the axis after first adding the current margins to the range and, if requested, sends an AxisChangeEvent to all registered listeners.

Usage

From source file:netplot.GenericPlotPanel.java

void genericConfig(JFreeChart chart, XYPlot plot, int plotIndex) {
    if (!enableLegend) {
        chart.removeLegend();//from w  ww.  ja  va 2 s.c o m
    }

    XYItemRenderer xyItemRenderer = plot.getRenderer();
    //May also be XYBarRenderer
    if (xyItemRenderer instanceof XYLineAndShapeRenderer) {
        XYToolTipGenerator xyToolTipGenerator = xyItemRenderer.getBaseToolTipGenerator();
        //If currently an XYLineAndShapeRenderer replace it so that we inc the colour for every plotIndex
        XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(linesEnabled, shapesEnabled);
        //Ensure we don't loose the tool tips on the new renderer
        renderer.setBaseToolTipGenerator(xyToolTipGenerator);
        renderer.setBasePaint(getPlotColour(plotIndex));
        renderer.setSeriesStroke(0, new BasicStroke(lineWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL),
                true);
        plot.setRenderer(plotIndex, renderer);
    }

    //If we have a new y axis then we need a new data set
    if (yAxisName != null && yAxisName.length() > 0) {
        if (logYAxis) {
            LogAxis yAxis = new LogAxis(yAxisName);
            yAxis.setAutoRange(false);
            yAxis.setNumberFormatOverride(new LogFormat(10, "10", true));
            yAxis.setRange(minScaleValue, maxScaleValue);
            yAxis.setLowerBound(minScaleValue);
            yAxis.setUpperBound(maxScaleValue);
            plot.setRangeAxis(yAxisIndex, yAxis);
            plot.setRangeAxisLocation(yAxisIndex, AxisLocation.BOTTOM_OR_LEFT);
        } else {
            NumberAxis axis = new NumberAxis(yAxisName);
            axis.setAutoRangeIncludesZero(zeroOnYScale);
            if (autoScaleEnabled) {
                axis.setAutoRange(true);
            } else {
                Range range = new Range(minScaleValue, maxScaleValue);
                axis.setRangeWithMargins(range, true, true);
            }
            if (yAxisTickCount > 0) {
                NumberTickUnit tick = new NumberTickUnit(yAxisTickCount);
                axis.setTickUnit(tick);
            }
            plot.setRangeAxis(yAxisIndex, axis);
            plot.setRangeAxisLocation(yAxisIndex, AxisLocation.BOTTOM_OR_LEFT);
        }
        yAxisIndex++;
    }
    plot.mapDatasetToRangeAxis(plotIndex, yAxisIndex - 1);
    ValueAxis a = plot.getDomainAxis();
    if (xAxisName.length() > 0) {
        a.setLabel(xAxisName);
    }
    //We can enable/disable zero on the axis if we have a NumberAxis
    if (a instanceof NumberAxis) {
        ((NumberAxis) a).setAutoRangeIncludesZero(zeroOnXScale);
    }
}

From source file:no.met.jtimeseries.chart.ChartPlotter.java

/**
 * Add normal bars in to the chart//from www  . jav a 2  s  . c o  m
 * 
 * @param dataset
 *            The dataset to visualise
 * @param title
 * @param color
 * @param margin
 *            Define the space between two bars
 */

public void addBarChart(XYDataset dataset, String title, Color color, double margin, double maxValue) {

    if (dataset.getItemCount(0) > 0) {

        XYBarRenderer renderer = new XYBarRenderer(margin);
        renderer.setSeriesPaint(0, color);
        renderer.setShadowVisible(false);
        renderer.setBaseItemLabelsVisible(false);
        renderer.setBarPainter(new StandardXYBarPainter());
        renderer.setSeriesVisibleInLegend(0, false);
        renderer.setDrawBarOutline(true);

        plot.mapDatasetToRangeAxis(plotIndex, rangeAxisIndex);
        plot.setDataset(plotIndex, dataset);
        plot.setRenderer(plotIndex, renderer);

        if (!title.equals("")) {
            // if title is not null then show the legend and label of the
            // bar
            NumberAxis numberAxis = new NumberAxis(title);
            numberAxis.setLowerMargin(LOWER_PLOT_MARGIN);
            double maxRange = calculateRangeMax(maxValue);
            numberAxis.setRangeWithMargins(new Range(0, maxRange), true, true);
            numberAxis.setLabelPaint(color);
            numberAxis.setTickLabelPaint(color);
            plot.setRangeAxis(rangeAxisIndex, numberAxis);

        }

        plotIndex++;
        rangeAxisIndex++;
    }
}