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

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

Introduction

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

Prototype

public void setAutoRangeIncludesZero(boolean flag) 

Source Link

Document

Sets the flag that indicates whether or not the axis range, if automatically calculated, is forced to include zero.

Usage

From source file:lu.lippmann.cdb.common.gui.ts.TimeSeriesChartUtil.java

private static void fillWithMultipleAxis(final Instances dataSet, final int dateIdx,
        final TimeSeriesCollection tsDataset, final JFreeChart tsChart) {
    final int numInstances = dataSet.numInstances();

    int axisNumber = 0;
    final Calendar cal = Calendar.getInstance();
    for (final Integer i : WekaDataStatsUtil.getNumericAttributesIndexes(dataSet)) {
        final TimeSeries ts = new TimeSeries(dataSet.attribute(i).name());
        for (int k = 0; k < numInstances; k++) {
            final long timeInMilliSec = (long) dataSet.instance(k).value(dateIdx);
            cal.setTimeInMillis(timeInMilliSec);
            if (dataSet.instance(k).isMissing(i)) {
                ts.addOrUpdate(new Millisecond(cal.getTime()), null);
            } else {
                ts.addOrUpdate(new Millisecond(cal.getTime()), dataSet.instance(k).value(i));
            }/*from  w w  w  . j  av a 2  s  . c  o  m*/
        }
        if (!ts.isEmpty()) {
            if (axisNumber == 0) {
                tsDataset.addSeries(ts);
            } else {
                final XYPlot plot = tsChart.getXYPlot();
                final NumberAxis axisToAdd = new NumberAxis(dataSet.attribute(i).name());
                axisToAdd.setAutoRangeIncludesZero(false);
                plot.setRangeAxis(axisNumber, axisToAdd);
                final TimeSeriesCollection t = new TimeSeriesCollection();
                t.addSeries(ts);
                plot.setDataset(axisNumber, t);
                plot.mapDatasetToRangeAxis(axisNumber, axisNumber);
                final StandardXYItemRenderer renderer2 = new StandardXYItemRenderer();
                renderer2.setSeriesPaint(0, ColorHelper.getColorForAString(dataSet.attribute(i).name()));
                plot.setRenderer(axisNumber, renderer2);
            }
            axisNumber++;
        }
    }
}

From source file:OAT.ui.util.UiUtil.java

/**
 * Returns a chart object./*from  ww  w  .j ava 2  s .  c o  m*/
 *
 * @param title
 * @param timeAxisLabel
 * @param valueAxisLabel
 * @param dataSet
 * @param timeline
 * @param theme
 * @param legend
 * @return
 */
public static Chart createTimeBasedChart(String title, String timeAxisLabel, String valueAxisLabel,
        ChartDataset dataSet, Timeline timeline, DefaultTheme theme, boolean legend) {

    //x-axis
    DateAxis timeAxis = new DateAxis(timeAxisLabel);
    timeAxis.setTimeline(timeline);
    //timeAxis.setTimeZone(dataSet.getTimeline().timeZone);

    if (dataSet instanceof TickChart || dataSet instanceof ContractChart) {
        timeAxis.setStandardTickUnits(createSimpleTimeTickUnits());
        //timeAxis.setTickUnit(new DateTickUnit(DateTickUnitType.MINUTE, 30,
        //        new SimpleDateFormat("HH:mm")),
        //       false, true);
    }

    //y-axis
    NumberAxis valueAxis = new NumberAxis(valueAxisLabel);
    valueAxis.setAutoRangeStickyZero(false);
    valueAxis.setAutoRangeIncludesZero(false);

    //renderer
    OHLCRenderer renderer = new OHLCRenderer();
    renderer.setBaseToolTipGenerator(new HighLowItemLabelGenerator());

    //Primary plot
    XYPlot plot = new XYPlot(dataSet, timeAxis, valueAxis, renderer);
    plot.setRangeAxisLocation(AxisLocation.TOP_OR_RIGHT, false);

    Chart chart = new Chart(title, Chart.DEFAULT_TITLE_FONT, plot, legend);

    theme.apply(chart);

    return chart;
}

From source file:org.esa.beam.visat.toolviews.diag.TileCacheMonitor.java

private static TimeSeriesCollection addSubPlot(CombinedDomainXYPlot plot, String label) {
    final TimeSeriesCollection seriesCollection = new TimeSeriesCollection(
            new TimeSeries(label, Millisecond.class));
    NumberAxis rangeAxis = new NumberAxis();
    rangeAxis.setAutoRangeIncludesZero(false);
    XYPlot subplot = new XYPlot(seriesCollection, null, rangeAxis, new StandardXYItemRenderer());
    subplot.setBackgroundPaint(Color.lightGray);
    subplot.setDomainGridlinePaint(Color.white);
    subplot.setRangeGridlinePaint(Color.white);
    plot.add(subplot);//from  ww w.j a va2  s.  co m
    return seriesCollection;
}

From source file:org.gephi.ui.utils.ChartsUtils.java

/**
 * Build a new box-plot from an array of numbers using a default title and yLabel.
 * String dataName will be used for xLabel.
 * @param numbers Numbers for building box-plot
 * @param dataName Name of the numbers data
 * @return Prepared box-plot/*from ww  w . j  av  a2 s.c  o  m*/
 */
public static JFreeChart buildBoxPlot(final Number[] numbers, final String dataName) {
    if (numbers == null || numbers.length == 0) {
        return null;
    }
    DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset();
    final ArrayList<Number> list = new ArrayList<Number>();
    list.addAll(Arrays.asList(numbers));

    final String valuesString = getMessage("ChartsUtils.report.box-plot.values");
    dataset.add(list, valuesString, "");

    final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setMeanVisible(false);
    renderer.setFillBox(false);
    renderer.setMaximumBarWidth(0.5);

    final CategoryAxis xAxis = new CategoryAxis(dataName);
    final NumberAxis yAxis = new NumberAxis(getMessage("ChartsUtils.report.box-plot.values-range"));
    yAxis.setAutoRangeIncludesZero(false);
    renderer.setBaseToolTipGenerator(new BoxAndWhiskerToolTipGenerator());
    final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);
    plot.setRenderer(renderer);

    JFreeChart boxPlot = new JFreeChart(getMessage("ChartsUtils.report.box-plot.title"), plot);
    return boxPlot;
}

From source file:grisu.frontend.view.swing.files.preview.fileViewers.JobStatusGridFileViewer.java

private static ChartPanel createChart(String title, String y_axis, XYDataset dataset, boolean createLegend) {

    final JFreeChart chart = ChartFactory.createTimeSeriesChart(title, // title
            "Date", // x-axis label
            y_axis, // y-axis label
            dataset, // data
            createLegend, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );/*w w w .j  a v  a  2s.com*/

    chart.setBackgroundPaint(Color.white);

    final 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));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setAutoRangeIncludesZero(true);

    final XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        final XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
        renderer.setDrawSeriesLineAsPath(true);
    }

    final DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("dd.MM. HH:mm"));

    return new ChartPanel(chart);

}

From source file:com.tonbeller.jpivot.chart.ChartFactory.java

/**
 * Creates and returns a time series chart.
 * <P>//from www . j av  a2s  . c  o  m
 * A time series chart is an XYPlot with a date axis (horizontal) and a number axis (vertical),
 * and each data item is connected with a line.
 * <P>
 * Note that you can supply a TimeSeriesCollection to this method, as it implements the
 * XYDataset interface.
 *
 * @param title  the chart title.
 * @param timeAxisLabel  a label for the time axis.
 * @param valueAxisLabel  a label for the value axis.
 * @param data  the dataset for the chart.
 * @param legend  a flag specifying whether or not a legend is required.
 * @param tooltips  configure chart to generate tool tips?
 * @param urls  configure chart to generate URLs?
 *
 * @return a time series chart.
 */
public static JFreeChart createTimeSeriesChart(String title, java.awt.Font titleFont, String timeAxisLabel,
        String valueAxisLabel, XYDataset data, boolean legend, boolean tooltips, boolean urls) {

    ValueAxis timeAxis = new DateAxis(timeAxisLabel);
    timeAxis.setLowerMargin(0.02); // reduce the default margins on the time axis
    timeAxis.setUpperMargin(0.02);
    NumberAxis valueAxis = new NumberAxis(valueAxisLabel);
    valueAxis.setAutoRangeIncludesZero(false); // override default
    XYPlot plot = new XYPlot(data, timeAxis, valueAxis, null);

    XYToolTipGenerator tooltipGenerator = null;
    if (tooltips) {
        tooltipGenerator = StandardXYToolTipGenerator.getTimeSeriesInstance();
        //new StandardXYToolTipGenerator(DateFormat.getDateInstance());                                                
    }

    XYURLGenerator urlGenerator = null;
    if (urls) {
        urlGenerator = new StandardXYURLGenerator();
    }

    plot.setRenderer(new StandardXYItemRenderer(StandardXYItemRenderer.LINES, tooltipGenerator, urlGenerator));

    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);

    return chart;

}

From source file:org.gwaspi.reports.PlinkReportLoader.java

private static void appendToCombinedRangePlot(CombinedRangeXYPlot combinedPlot, String chromosome,
        XYSeriesCollection seriesCol) {/*from w  ww  . java 2s.c  o  m*/
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(false, true);
    renderer.setSeriesPaint(0, Color.blue);

    JFreeChart subchart = ChartFactory.createScatterPlot("", "Chr " + chromosome, "", seriesCol,
            PlotOrientation.VERTICAL, true, false, false);

    XYPlot subplot = (XYPlot) subchart.getPlot();
    subplot.setRenderer(renderer);
    subplot.setBackgroundPaint(null);

    subplot.setDomainGridlineStroke(new BasicStroke(0.0f));
    subplot.setDomainMinorGridlineStroke(new BasicStroke(0.0f));
    subplot.setDomainGridlinePaint(Color.blue);
    subplot.setRangeGridlineStroke(new BasicStroke(0.0f));
    subplot.setRangeMinorGridlineStroke(new BasicStroke(0.0f));
    subplot.setRangeGridlinePaint(Color.blue);

    NumberAxis chrAxis = (NumberAxis) subplot.getDomainAxis();
    chrAxis.setAxisLineVisible(true);
    chrAxis.setTickLabelsVisible(true);
    chrAxis.setTickMarksVisible(true);
    chrAxis.setTickUnit(new NumberTickUnit(10000));
    chrAxis.setAutoRangeIncludesZero(false);

    NumberAxis log10Axis = (NumberAxis) subplot.getRangeAxis();
    log10Axis.setTickMarkInsideLength(2.0f);
    log10Axis.setTickMarkOutsideLength(2.0f);
    log10Axis.setMinorTickCount(2);
    log10Axis.setMinorTickMarksVisible(true);
    log10Axis.setAxisLineVisible(true);
    log10Axis.setAutoRangeIncludesZero(false);

    XYItemRenderer lblRenderer = subplot.getRenderer();
    MySeriesItemLabelGenerator lblGenerator = new MySeriesItemLabelGenerator(4.0d, chromosome);

    lblRenderer.setSeriesItemLabelGenerator(0, lblGenerator);
    lblRenderer.setSeriesItemLabelGenerator(1, lblGenerator);
    lblRenderer.setSeriesItemLabelFont(0, new Font("Serif", Font.PLAIN, 12));
    lblRenderer.setSeriesItemLabelFont(1, new Font("Serif", Font.PLAIN, 12));
    lblRenderer.setSeriesPositiveItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.CENTER,
            TextAnchor.BOTTOM_LEFT, TextAnchor.TOP_LEFT, -Math.PI / 4.0));
    lblRenderer.setSeriesPositiveItemLabelPosition(1, new ItemLabelPosition(ItemLabelAnchor.CENTER,
            TextAnchor.BOTTOM_LEFT, TextAnchor.TOP_LEFT, -Math.PI / 4.0));
    lblRenderer.setSeriesItemLabelsVisible(0, true);
    lblRenderer.setSeriesItemLabelsVisible(1, true);

    combinedPlot.add(subplot, 1);
}

From source file:com.ewcms.plugin.report.generate.service.chart.ChartGenerationService.java

/**
 * ?//  w  ww.  j a  v a2  s  . c om
 * <P>
 * ?XYPlot? ???
 * <P>
 * ?:???TimeSeriesCollection?XYDataset?
 *
 * @param title 
 * @param titleFont 
 * @param timeAxisLabel 
 * @param valueAxisLabel 
 * @param data ??
 * @param legend 
 * @param tooltips ????
 * @param urls ??URL
 *
 * @return ?
 */
public static JFreeChart createTimeSeriesChart(String title, java.awt.Font titleFont, String timeAxisLabel,
        String valueAxisLabel, XYDataset data, boolean legend, boolean tooltips, boolean urls) {
    ValueAxis timeAxis = new DateAxis(timeAxisLabel);
    timeAxis.setLowerMargin(0.02);

    timeAxis.setUpperMargin(0.02);
    NumberAxis valueAxis = new NumberAxis(valueAxisLabel);
    valueAxis.setAutoRangeIncludesZero(false);
    XYPlot plot = new XYPlot(data, timeAxis, valueAxis, null);

    XYToolTipGenerator tooltipGenerator = null;
    if (tooltips) {
        tooltipGenerator = StandardXYToolTipGenerator.getTimeSeriesInstance();
        // new StandardXYToolTipGenerator(DateFormat.getDateInstance());
    }

    XYURLGenerator urlGenerator = null;
    if (urls) {
        urlGenerator = new StandardXYURLGenerator();
    }

    plot.setRenderer(new StandardXYItemRenderer(StandardXYItemRenderer.LINES, tooltipGenerator, urlGenerator));

    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);

    return chart;

}

From source file:tools.descartes.bungee.chart.ChartGenerator.java

public static XYPlot createDemandPlot(final List<ArrivalRateTuple> intensities,
        final IntensityDemandMapping mapping) {
    final TimeSeriesCollection dataset = new TimeSeriesCollection();
    final TimeSeries series = new TimeSeries("resource demand");
    for (ArrivalRateTuple intensity : intensities) {
        long milliseconds = (referenceDate.getTime() / 1000 + (long) Math.floor(intensity.getTimeStamp()))
                * 1000;//w w w  . j a  v  a  2 s .  c  o m
        series.add(new FixedMillisecond(milliseconds), mapping.getResourceDemand(intensity.getArrivalRate()));
    }
    dataset.addSeries(series);

    XYStepRenderer renderer = new XYStepRenderer();
    renderer.setSeriesPaint(0, Color.RED);
    renderer.setSeriesStroke(0, new BasicStroke(STROKE_WIDTH));
    final NumberAxis rangeAxis = new NumberAxis("Resource Amount");
    rangeAxis.setAutoRangeIncludesZero(true);
    //rangeAxis.setRange(0,2.2);
    rangeAxis.setTickUnit(new NumberTickUnit(2));
    final XYPlot amountPlot = new XYPlot(dataset, null, rangeAxis, renderer);
    return amountPlot;
}

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

private static JFreeChart createXYLineChart(XYDataset dataset) {

    NumberAxis xAxis = new NumberAxis(xAxisLabel);
    xAxis.setAutoRangeIncludesZero(false);
    NumberAxis yAxis = new NumberAxis(yAxisLabel);
    XYItemRenderer renderer = new XYLineAndShapeRenderer(true, false);
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setOrientation(orientation);// w  w  w . j  a va  2 s  .  c o  m
    if (tooltips) {
        renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    }
    if (urls) {
        renderer.setURLGenerator(new StandardXYURLGenerator());
    }

    JFreeChart chart = new JFreeChart("XYLine Chart Demo", JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    chart.setBackgroundPaint(Color.white);

    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    yAxis.setNumberFormatOverride(MyNumberFormat.getMyNumberFormat());

    return chart;
}