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:org.jfree.chart.demo.AnnotationDemo2.java

private static JFreeChart createChart() {
    XYDataset xydataset = createDataset1();
    JFreeChart jfreechart = ChartFactory.createXYLineChart("Annotation Demo 2", "Date", "Price Per Unit",
            xydataset, PlotOrientation.VERTICAL, false, true, false);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis();
    numberaxis.setAutoRangeIncludesZero(false);
    NumberAxis numberaxis1 = new NumberAxis("Secondary");
    numberaxis1.setAutoRangeIncludesZero(false);
    xyplot.setRangeAxis(1, numberaxis1);
    xyplot.setDataset(1, createDataset2());
    xyplot.mapDatasetToRangeAxis(1, 1);//from  w  w  w  . ja  va 2s.c  o  m
    XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyplot.getRenderer();
    xylineandshaperenderer.setBaseToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());
    xylineandshaperenderer.setBaseShapesVisible(true);
    xylineandshaperenderer.setBaseShapesFilled(true);
    XYPointerAnnotation xypointerannotation = new XYPointerAnnotation("Annotation 1 (2.0, 167.3)", 2D,
            167.30000000000001D, -0.78539816339744828D);
    xypointerannotation.setTextAnchor(TextAnchor.BOTTOM_LEFT);
    xypointerannotation.setPaint(Color.red);
    xypointerannotation.setArrowPaint(Color.red);
    xylineandshaperenderer.addAnnotation(xypointerannotation);
    XYLineAndShapeRenderer xylineandshaperenderer1 = new XYLineAndShapeRenderer(true, true);
    xylineandshaperenderer1.setSeriesPaint(0, Color.black);
    xylineandshaperenderer.setBaseToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());
    XYPointerAnnotation xypointerannotation1 = new XYPointerAnnotation("Annotation 2 (15.0, 613.2)", 15D,
            613.20000000000005D, 1.5707963267948966D);
    xypointerannotation1.setTextAnchor(TextAnchor.TOP_CENTER);
    xylineandshaperenderer1.addAnnotation(xypointerannotation1);
    xyplot.setRenderer(1, xylineandshaperenderer1);
    LegendTitle legendtitle = new LegendTitle(xylineandshaperenderer);
    LegendTitle legendtitle1 = new LegendTitle(xylineandshaperenderer1);
    BlockContainer blockcontainer = new BlockContainer(new BorderArrangement());
    blockcontainer.add(legendtitle, RectangleEdge.LEFT);
    blockcontainer.add(legendtitle1, RectangleEdge.RIGHT);
    blockcontainer.add(new EmptyBlock(2000D, 0.0D));
    CompositeTitle compositetitle = new CompositeTitle(blockcontainer);
    compositetitle.setPosition(RectangleEdge.BOTTOM);
    jfreechart.addSubtitle(compositetitle);
    return jfreechart;
}

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

private static JFreeChart createChart() {
    XYDataset xydataset = createDataset(1, 1.0D);
    JFreeChart jfreechart = ChartFactory.createXYLineChart("XYLineAndShapeRenderer Demo 2", "X", "Y", xydataset,
            PlotOrientation.VERTICAL, true, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    TextTitle texttitle = new TextTitle(
            "This chart shows various combinations of the useFillPaint and useOutlinePaint flags.");
    texttitle.setFont(new Font("Dialog", 0, 10));
    jfreechart.addSubtitle(texttitle);/*from  w  w  w.  jav  a 2 s. c  om*/
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setRangeGridlinePaint(Color.white);
    NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis();
    numberaxis.setAutoRangeIncludesZero(false);
    java.awt.geom.Ellipse2D.Double double1 = new java.awt.geom.Ellipse2D.Double(-4D, -4D, 8D, 8D);
    XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyplot.getRenderer();
    xylineandshaperenderer.setBaseShapesVisible(true);
    xylineandshaperenderer.setSeriesShape(0, double1);
    xylineandshaperenderer.setSeriesPaint(0, Color.red);
    xylineandshaperenderer.setSeriesFillPaint(0, Color.yellow);
    xylineandshaperenderer.setSeriesOutlinePaint(0, Color.gray);
    XYDataset xydataset1 = createDataset(2, 2D);
    XYLineAndShapeRenderer xylineandshaperenderer1 = new XYLineAndShapeRenderer();
    xyplot.setDataset(1, xydataset1);
    xyplot.setRenderer(1, xylineandshaperenderer1);
    xylineandshaperenderer1.setSeriesShape(0, double1);
    xylineandshaperenderer1.setSeriesPaint(0, Color.red);
    xylineandshaperenderer1.setSeriesFillPaint(0, Color.yellow);
    xylineandshaperenderer1.setSeriesOutlinePaint(0, Color.gray);
    xylineandshaperenderer1.setUseFillPaint(true);
    XYDataset xydataset2 = createDataset(3, 3D);
    XYLineAndShapeRenderer xylineandshaperenderer2 = new XYLineAndShapeRenderer();
    xyplot.setDataset(2, xydataset2);
    xyplot.setRenderer(2, xylineandshaperenderer2);
    xylineandshaperenderer2.setSeriesShape(0, double1);
    xylineandshaperenderer2.setSeriesPaint(0, Color.red);
    xylineandshaperenderer2.setSeriesFillPaint(0, Color.yellow);
    xylineandshaperenderer2.setSeriesOutlinePaint(0, Color.gray);
    xylineandshaperenderer2.setUseOutlinePaint(true);
    XYDataset xydataset3 = createDataset(4, 4D);
    XYLineAndShapeRenderer xylineandshaperenderer3 = new XYLineAndShapeRenderer();
    xyplot.setDataset(3, xydataset3);
    xyplot.setRenderer(3, xylineandshaperenderer3);
    xylineandshaperenderer3.setSeriesShape(0, double1);
    xylineandshaperenderer3.setSeriesPaint(0, Color.red);
    xylineandshaperenderer3.setSeriesFillPaint(0, Color.yellow);
    xylineandshaperenderer3.setSeriesOutlinePaint(0, Color.gray);
    xylineandshaperenderer3.setUseOutlinePaint(true);
    xylineandshaperenderer3.setUseFillPaint(true);
    XYDataset xydataset4 = createDataset(5, 5D);
    XYLineAndShapeRenderer xylineandshaperenderer4 = new XYLineAndShapeRenderer();
    xyplot.setDataset(4, xydataset4);
    xyplot.setRenderer(4, xylineandshaperenderer4);
    xylineandshaperenderer4.setSeriesShape(0, double1);
    xylineandshaperenderer4.setSeriesPaint(0, Color.red);
    xylineandshaperenderer4.setSeriesFillPaint(0, Color.yellow);
    xylineandshaperenderer4.setSeriesOutlinePaint(0, Color.gray);
    xylineandshaperenderer4.setUseOutlinePaint(true);
    xylineandshaperenderer4.setUseFillPaint(true);
    xylineandshaperenderer4.setDrawOutlines(false);
    return jfreechart;
}

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

private static JFreeChart createChart(CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createLineChart("Statistical Bar Chart Demo 1", "Type", "Value",
            categorydataset, PlotOrientation.VERTICAL, true, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setBackgroundPaint(Color.lightGray);
    categoryplot.setRangeGridlinePaint(Color.white);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    numberaxis.setAutoRangeIncludesZero(false);
    StatisticalBarRenderer statisticalbarrenderer = new StatisticalBarRenderer();
    statisticalbarrenderer.setErrorIndicatorPaint(Color.black);
    statisticalbarrenderer.setIncludeBaseInRange(false);
    categoryplot.setRenderer(statisticalbarrenderer);
    statisticalbarrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    statisticalbarrenderer.setBaseItemLabelsVisible(true);
    statisticalbarrenderer.setBasePositiveItemLabelPosition(
            new ItemLabelPosition(ItemLabelAnchor.INSIDE6, TextAnchor.BOTTOM_CENTER));
    return jfreechart;
}

From source file:graph.jfreecharts.GraphFunction.java

/**
 * A custom xyerror renderer because jfreecharts does not
 * have it supported in the api.//from w w w .j a  va2 s .c  o m
 * @param title the graph title
 * @param xAxisLabel the xaxis title
 * @param yAxisLabel the yaxis title
 * @param dataset the xydataset
 * @param orientation the plot orientation
 * @param legend true to turn on legend
 * @param tooltips true to turn on tooltips (the pop up when right click)
 * @param urls // no idea what this is for
 * @return
 */
private static JFreeChart createXYIntervalChart(String title, String xAxisLabel, String yAxisLabel,
        XYDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) {

    if (orientation == null) {
        throw new IllegalArgumentException("Null 'orientation' argument.");
    }
    NumberAxis xAxis = new NumberAxis(xAxisLabel);
    xAxis.setAutoRangeIncludesZero(false);
    NumberAxis yAxis = new NumberAxis(yAxisLabel);
    XYErrorRenderer renderer = new XYErrorRenderer();

    renderer.setDrawXError(true);
    renderer.setDrawYError(true);

    xAxis.setNumberFormatOverride(new DecimalFormat("0.######E0"));
    yAxis.setNumberFormatOverride(new DecimalFormat("0.######E0"));

    xAxis.setAutoRangeIncludesZero(false);
    yAxis.setAutoRangeIncludesZero(false);

    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setOrientation(orientation);
    if (tooltips) {
        renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    }
    if (urls) {
        renderer.setURLGenerator(new StandardXYURLGenerator());
    }

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

}

From source file:com.leonarduk.finance.analysis.CashFlowToChart.java

/**
 * Adds the cash flow axis to the plot./*www  .  j  ava 2 s .c  o  m*/
 *
 * @param plot
 *            the plot
 * @param dataset
 *            the cash flow dataset
 */
private static void addCashFlowAxis(final XYPlot plot, final TimeSeriesCollection dataset) {
    final NumberAxis cashAxis = new NumberAxis("Cash Flow Ratio");
    cashAxis.setAutoRangeIncludesZero(false);
    plot.setRangeAxis(1, cashAxis);
    plot.setDataset(1, dataset);
    plot.mapDatasetToRangeAxis(1, 1);
    final StandardXYItemRenderer cashFlowRenderer = new StandardXYItemRenderer();
    cashFlowRenderer.setSeriesPaint(0, Color.blue);
    plot.setRenderer(1, cashFlowRenderer);
}

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

private static JFreeChart createChart(IntervalXYDataset intervalxydataset) {
    JFreeChart jfreechart = ChartFactory.createXYLineChart("YIntervalChartDemo2", "Date", "Value",
            intervalxydataset, PlotOrientation.VERTICAL, true, true, false);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setDomainPannable(true);/*from   ww w .  j  a va  2 s. c  o m*/
    xyplot.setRangePannable(true);
    xyplot.setDomainAxis(new DateAxis("Date"));
    NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    numberaxis.setAutoRangeIncludesZero(false);
    XYErrorRenderer xyerrorrenderer = new XYErrorRenderer();
    xyerrorrenderer.setBaseLinesVisible(true);
    xyerrorrenderer.setUseFillPaint(true);
    xyerrorrenderer.setBaseFillPaint(Color.white);
    xyplot.setRenderer(xyerrorrenderer);
    ChartUtilities.applyCurrentTheme(jfreechart);
    return jfreechart;
}

From source file:wsattacker.plugin.intelligentdos.ui.helper.ChartHelper.java

public static JFreeChart createDumyChart() {
    final BoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset();

    final CategoryAxis xAxis = new CategoryAxis("Type");
    final NumberAxis yAxis = new NumberAxis("Value");
    yAxis.setAutoRangeIncludesZero(false);
    final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setFillBox(true);/*from   ww w. j a  v  a  2  s  . co m*/
    renderer.setMeanVisible(false);
    renderer.setMedianVisible(false);
    // renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator());
    final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);

    return new JFreeChart(plot);
}

From source file:com.spotify.heroic.http.render.RenderUtils.java

private static JFreeChart buildChart(final String title, final XYDataset lineAndShape, final XYDataset interval,
        final XYItemRenderer lineAndShapeRenderer, final XYItemRenderer intervalRenderer) {
    final ValueAxis timeAxis = new DateAxis();
    timeAxis.setLowerMargin(0.02);/*from w  w w .  ja va  2  s . c o m*/
    timeAxis.setUpperMargin(0.02);

    final NumberAxis valueAxis = new NumberAxis();
    valueAxis.setAutoRangeIncludesZero(false);

    final XYPlot plot = new XYPlot();

    plot.setDomainAxis(0, timeAxis);
    plot.setRangeAxis(0, valueAxis);

    plot.setDataset(0, lineAndShape);
    plot.setRenderer(0, lineAndShapeRenderer);

    plot.setDomainAxis(1, timeAxis);
    plot.setRangeAxis(1, valueAxis);

    plot.setDataset(1, interval);
    plot.setRenderer(1, intervalRenderer);

    return new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, false);
}

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

private static JFreeChart createChart(XYDataset xydataset) {
    JFreeChart jfreechart = ChartFactory.createXYLineChart(null, "Age in Months", "Weight (kg)", xydataset,
            PlotOrientation.VERTICAL, true, true, false);
    TextTitle texttitle = new TextTitle("Growth Charts: United States", new Font("SansSerif", 1, 14));
    TextTitle texttitle1 = new TextTitle("Weight-for-age percentiles: boys, birth to 36 months",
            new Font("SansSerif", 0, 11));
    jfreechart.addSubtitle(texttitle);//from ww  w  .  java  2s  . co m
    jfreechart.addSubtitle(texttitle1);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    NumberAxis numberaxis = (NumberAxis) xyplot.getDomainAxis();
    numberaxis.setUpperMargin(0.12D);
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    NumberAxis numberaxis1 = (NumberAxis) xyplot.getRangeAxis();
    numberaxis1.setAutoRangeIncludesZero(false);
    XYTextAnnotation xytextannotation = null;
    Font font = new Font("SansSerif", 0, 9);
    xytextannotation = new XYTextAnnotation("3rd", 36.5D, 11.76D);
    xytextannotation.setFont(font);
    xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT);
    xyplot.addAnnotation(xytextannotation);
    xytextannotation = new XYTextAnnotation("5th", 36.5D, 12.039999999999999D);
    xytextannotation.setFont(font);
    xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT);
    xyplot.addAnnotation(xytextannotation);
    xytextannotation = new XYTextAnnotation("10th", 36.5D, 12.493D);
    xytextannotation.setFont(font);
    xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT);
    xyplot.addAnnotation(xytextannotation);
    xytextannotation = new XYTextAnnotation("25th", 36.5D, 13.313000000000001D);
    xytextannotation.setFont(font);
    xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT);
    xyplot.addAnnotation(xytextannotation);
    xytextannotation = new XYTextAnnotation("50th", 36.5D, 14.33D);
    xytextannotation.setFont(font);
    xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT);
    xyplot.addAnnotation(xytextannotation);
    xytextannotation = new XYTextAnnotation("75th", 36.5D, 15.478D);
    xytextannotation.setFont(font);
    xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT);
    xyplot.addAnnotation(xytextannotation);
    xytextannotation = new XYTextAnnotation("90th", 36.5D, 16.641999999999999D);
    xytextannotation.setFont(font);
    xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT);
    xyplot.addAnnotation(xytextannotation);
    xytextannotation = new XYTextAnnotation("95th", 36.5D, 17.408000000000001D);
    xytextannotation.setFont(font);
    xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT);
    xyplot.addAnnotation(xytextannotation);
    xytextannotation = new XYTextAnnotation("97th", 36.5D, 17.936D);
    xytextannotation.setFont(font);
    xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT);
    xyplot.addAnnotation(xytextannotation);
    return jfreechart;
}

From source file:jgnash.ui.report.compiled.SecurityHighLowChart.java

private static JFreeChart createHighLowChart(String title, String timeAxisLabel, String valueAxisLabel,
        AbstractXYDataset data, boolean legend) {

    ValueAxis timeAxis = new DateAxis(timeAxisLabel);
    NumberAxis valueAxis = new NumberAxis(valueAxisLabel);
    valueAxis.setAutoRangeIncludesZero(false);

    HighLowRenderer renderer = new HighLowRenderer();
    renderer.setBaseToolTipGenerator(new HighLowItemLabelGenerator());

    XYPlot plot = new XYPlot(data, timeAxis, valueAxis, renderer);

    return new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
}