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:net.nosleep.superanalyzer.analysis.views.YearView.java

private void createChart() {

    NumberAxis xAxis = new NumberAxis(Misc.getString("RELEASE_YEAR"));
    xAxis.setAutoRangeIncludesZero(false);

    NumberAxis yAxis = new NumberAxis(Misc.getString("SONG_COUNT"));
    yAxis.setAutoRangeIncludesZero(true);

    xAxis.setNumberFormatOverride(new DecimalFormat("0"));

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    XYPlot plot = new XYPlot(_dataset, xAxis, yAxis, renderer);

    // create and return the chart panel...
    _chart = new JFreeChart(Misc.getString("RELEASE_YEAR"), JFreeChart.DEFAULT_TITLE_FONT, plot, true);

    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);

    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(false);
    plot.setAxisOffset(new RectangleInsets(4, 4, 4, 4));

    LegendTitle legend = _chart.getLegend();
    legend.setFrame(BlockBorder.NONE);//from  w  w w.j a v a 2s  .c  o  m

    _chart.addSubtitle(HomePanel.createSubtitle(Misc.getString("RELEASE_YEAR_TOOLTIP")));

    XYToolTipGenerator generator = new StandardXYToolTipGenerator("{2}", new DecimalFormat("0.00"),
            new DecimalFormat("0.00"));
    renderer.setToolTipGenerator(generator);

    ChartUtilities.applyCurrentTheme(_chart);

    // format the lines after applying the theme
    renderer.setBaseShapesVisible(true);
    renderer.setDrawOutlines(true);
    renderer.setUseFillPaint(true);
    renderer.setBaseFillPaint(Color.white);
    renderer.setSeriesStroke(0, new BasicStroke(3.0f));
    renderer.setSeriesOutlineStroke(0, new BasicStroke(2.0f));
    renderer.setSeriesShape(0, new Ellipse2D.Double(-4.0, -4.0, 8.0, 8.0));

    renderer.setSeriesStroke(1, new BasicStroke(3.0f));
    renderer.setSeriesOutlineStroke(1, new BasicStroke(2.0f));
    renderer.setSeriesShape(1, new Rectangle2D.Double(-3.0, -3.0, 6.0, 6.0));

    _chart.setPadding(new RectangleInsets(10, 10, 10, 10));

    Misc.formatChart(plot);
}

From source file:org.optaplanner.benchmark.impl.statistic.single.constraintmatchtotalbestscore.ConstraintMatchTotalBestScoreSingleStatistic.java

private XYPlot createPlot(BenchmarkReport benchmarkReport, int scoreLevelIndex) {
    Locale locale = benchmarkReport.getLocale();
    NumberAxis xAxis = new NumberAxis("Time spent");
    xAxis.setNumberFormatOverride(new MillisecondsSpentNumberFormat(locale));
    NumberAxis yAxis = new NumberAxis("Constraint match total weight level " + scoreLevelIndex);
    yAxis.setNumberFormatOverride(NumberFormat.getInstance(locale));
    yAxis.setAutoRangeIncludesZero(false);
    XYPlot plot = new XYPlot(null, xAxis, yAxis, null);
    plot.setOrientation(PlotOrientation.VERTICAL);
    return plot;/*from w  w w.  ja v  a2s . co  m*/
}

From source file:edu.umn.ecology.populus.plot.BasicPlotCanvas.java

private void jbInit() throws Exception {
    /*/*from   ww w .j  a v  a  2  s.  c o m*/
    if( info != null ) {
       mainCaption = new HTMLLabel( info.getMainCaption() );
       xCaption = new HTMLLabel( info.getXCaptions()[0] );
       yCaption = new HTMLLabel( info.getYCaptions()[0] );
       yCaption.setDirection( HTMLLabel.DOWN_TO_UP );
    } else {
       mainCaption = new HTMLLabel( "Main Caption" );
       xCaption = new HTMLLabel( "X Caption" );
       yCaption = new HTMLLabel( "Y Caption" );
    }
     */
    //*
    if (info != null) {
        mainCaption = new HTMLMultiLabel(info.getMainCaption());
        xCaption = new HTMLMultiLabel(info.getXCaptions());
        yCaption = new HTMLMultiLabel(info.getYCaptions());
        yCaption.setDirection(HTMLLabel.DOWN_TO_UP);
    } else {
        mainCaption = new HTMLMultiLabel("Main Caption");
        xCaption = new HTMLMultiLabel("X Caption");
        yCaption = new HTMLMultiLabel("Y Caption");
        yCaption.setDirection(HTMLLabel.DOWN_TO_UP);
    }
    setLayout(borderLayout1);
    if (PopPreferencesStorage.isUseJFreeClass()) {
        NumberAxis yAxis = new NumberAxis(null);
        NumberAxis xAxis = new NumberAxis(null);
        xAxis.setAutoRangeIncludesZero(false);

        AbstractXYItemRenderer renderer = null;
        if (info.isBarChart) {
            renderer = new XYBarRenderer();
        } else {
            renderer = new XYLineAndShapeRenderer(true, false);
        }

        XYPlot plot = new XYPlot(null, xAxis, yAxis, renderer);
        plot.setOrientation(PlotOrientation.VERTICAL);

        JFreeChart jfchart = new JFreeChart(null, null, plot, false);
        jfchartpanel = new ChartPanel(jfchart);
        plot.setBackgroundPaint(ColorScheme.bG);

        info.styleJFree(jfchart);
        add(jfchartpanel, MacroLayout.CENTER);
    } else {
        chart = new JCChart(JCChart.PLOT);
        info.styleJC(chart);
        chart.setBackground(ColorScheme.bG);
        chart.setAllowUserChanges(true);
        chart.setTrigger(0, new EventTrigger(InputEvent.SHIFT_MASK, EventTrigger.CUSTOMIZE));
        chart.setTrigger(1, new EventTrigger(InputEvent.BUTTON1_MASK, EventTrigger.ZOOM));
        chart.setResetKey('r');
        chart.addMouseListener(new java.awt.event.MouseAdapter() {

            public void mouseClicked(java.awt.event.MouseEvent e) {
                if ((e.getModifiers() & InputEvent.META_MASK) != 0) {
                    info.setAxis(chart);
                    chart.reset();
                }
            }
        });
        chart.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
        chart.setWarningDialog(false);
        add(chart, MacroLayout.CENTER);
    }
    setBGColor();
    add(mainCaption, MacroLayout.NORTH);
    add(xCaption, MacroLayout.SOUTH);
    add(yCaption, MacroLayout.WEST);
}

From source file:org.bench4Q.console.ui.section.R_RealSessionShowSection.java

private JPanel printPic() throws IOException {
    double[][] value = new double[2][testduring];
    for (int i = 0; i < value[0].length; ++i) {
        value[0][i] = i;//  w w  w.j  a  v a2  s .  c om
        value[1][i] = loadStart[i];
    }

    // calculate the avrg load start every second.
    int avrgLoad = 0;
    for (int i = 0; i < loadStart.length; i++) {
        avrgLoad += loadStart[i];
    }
    avrgLoad /= testduring;

    DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset();
    String series1 = "real";

    for (int i = 0; i < value[0].length; ++i) {
        defaultcategorydataset.addValue(value[1][i], series1, new Integer((int) value[0][i]));
    }

    JFreeChart chart = ChartFactory.createLineChart("REAL LOAD:" + avrgLoad, "time", "load",
            defaultcategorydataset, PlotOrientation.VERTICAL, true, true, false);
    chart.setBackgroundPaint(Color.white);
    CategoryPlot categoryplot = (CategoryPlot) chart.getPlot();
    categoryplot.setBackgroundPaint(Color.WHITE);
    categoryplot.setRangeGridlinePaint(Color.white);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    numberaxis.setAutoRangeIncludesZero(true);
    LineAndShapeRenderer lineandshaperenderer = (LineAndShapeRenderer) categoryplot.getRenderer();
    lineandshaperenderer.setShapesVisible(false);
    lineandshaperenderer.setSeriesStroke(0, new BasicStroke(2.0F, 1, 1, 1.0F, new float[] { 1F, 1F }, 0.0F));
    return new ChartPanel(chart);
}

From source file:unalcol.termites.boxplots.RoundNumberGlobal.java

/**
 * Creates a new demo./*w  w  w . j  a va 2 s.co  m*/
 *
 * @param title the frame title.
 * @param pf
 */
public RoundNumberGlobal(final String title, ArrayList<Double> pf) {

    super(title);

    final BoxAndWhiskerCategoryDataset dataset = createSampleDataset(pf);

    final CategoryAxis xAxis = new CategoryAxis("");
    //final NumberAxis yAxis = new NumberAxis("Round number");
    final NumberAxis yAxis = new NumberAxis("");
    yAxis.setAutoRangeIncludesZero(false);
    final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setFillBox(false);
    renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator());
    final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);

    Font font = new Font("Dialog", Font.PLAIN, 16);
    xAxis.setTickLabelFont(font);
    yAxis.setTickLabelFont(font);
    yAxis.setLabelFont(font);

    final JFreeChart chart = new JFreeChart("Round Number" + getTitle(pf), new Font("SansSerif", Font.BOLD, 18),
            plot, true);

    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(650, 370));
    setContentPane(chartPanel);

    TextTitle legendText = null;
    if (pf.size() == 1) {
        legendText = new TextTitle("Population Size");
    } else {
        legendText = new TextTitle("Population Size - Probability of Failure");
    }

    legendText.setFont(font);
    legendText.setPosition(RectangleEdge.BOTTOM);
    chart.addSubtitle(legendText);
    chart.getLegend().setItemFont(font);

    FileOutputStream output;
    try {
        output = new FileOutputStream("roundGlobalNumber" + pf + ".jpg");
        ChartUtilities.writeChartAsJPEG(output, 1.0f, chart, 400, 400, null);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(RoundNumberGlobal.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(RoundNumberGlobal.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:smarthouse_server.LineChart.java

/**
 * Creates a sample chart./*from   w  w  w  .j a  va  2  s .  co m*/
 * 
 * @param dataset  a dataset.
 * 
 * @return The chart.
 */
private JFreeChart createChart(CategoryDataset dataset) {

    // create the chart...
    chart = ChartFactory.createLineChart("Room Monitor #", // chart title
            "Time", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    //        StandardLegend legend = (StandardLegend) chart.getLegend();
    //      legend.setDisplaySeriesShapes(true);
    //    legend.setShapeScaleX(1.5);
    //  legend.setShapeScaleY(1.5);
    //legend.setDisplaySeriesLines(true);

    chart.setBackgroundPaint(Color.white);

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.white);
    plot.getDomainAxis().setVisible(false);
    // customise the range axis...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setAutoRangeIncludesZero(true);

    // ****************************************************************************
    // * 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.             *
    // ****************************************************************************

    // customise the renderer...
    LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    //        renderer.setDrawShapes(true);

    renderer.setSeriesStroke(0, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f,
            new float[] { 10.0f, 6.0f }, 0.0f));
    renderer.setSeriesStroke(1, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f,
            new float[] { 6.0f, 6.0f }, 0.0f));
    /*        renderer.setSeriesStroke(
    2, new BasicStroke(
        2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
        1.0f, new float[] {2.0f, 6.0f}, 0.0f
    )
            );*/
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;
}

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

/**
 * Creates a chart./*from   w  w  w.  ja v a 2 s .  c  om*/
 * 
 * @param dataset  the data for the chart.
 * 
 * @return a chart.
 */
protected JFreeChart createChart(XYDataset dataset) {

    //   create the chart...
    JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, // 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.setSeriesShape(0, java.awt.Shape.round);
    renderer.setBaseShapesVisible(false);
    renderer.setBaseShapesFilled(false);
    renderer.setBaseLinesVisible(true);

    renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator());

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

    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    domainAxis.setAutoRangeIncludesZero(false);
    //  domainAxis.setTickLabelsVisible(false);
    // domainAxis.setTickMarksVisible(false);      
    domainAxis.setUpperMargin(0.05);
    domainAxis.setLowerMargin(0.05);

    // OPTIONAL CUSTOMISATION COMPLETED.
    setYSummary(dataset);

    return chart;
}

From source file:unalcol.termites.boxplots.ECALMessages.java

/**
 * Creates a new demo./*  w ww  .jav a 2s.  c o  m*/
 *
 * @param title the frame title.
 * @param pf
 */
public ECALMessages(final String title, ArrayList<Double> pf) {

    super(title);

    final CategoryAxis xAxis = new CategoryAxis("");
    //final NumberAxis yAxis = new NumberAxis("Messages Sent");
    final NumberAxis yAxis = new NumberAxis("");

    yAxis.setAutoRangeIncludesZero(false);
    final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    final BoxAndWhiskerCategoryDataset dataset = createSampleDataset(pf, renderer);
    renderer.setFillBox(false);
    renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator());
    final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);

    Font font = new Font("Dialog", Font.PLAIN, 13);
    xAxis.setTickLabelFont(font);
    yAxis.setTickLabelFont(font);
    yAxis.setLabelFont(font);

    final JFreeChart chart = new JFreeChart("Messages Sent " + getTitle(pf),
            new Font("SansSerif", Font.BOLD, 18), plot, true);

    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(650, 370));
    setContentPane(chartPanel);
    TextTitle legendText = null;
    if (pf.size() == 1) {
        legendText = new TextTitle("Population Size");
    } else {
        legendText = new TextTitle("Population Size - Probability of Failure");
    }
    legendText.setPosition(RectangleEdge.BOTTOM);
    chart.addSubtitle(legendText);

    LegendTitle legend = chart.getLegend();
    legend.setPadding(new RectangleInsets(UnitType.RELATIVE, 0, 0.1, 0, 0));

    FileOutputStream output;
    try {
        output = new FileOutputStream("messagesECAL" + pf + ".jpg");
        ChartUtilities.writeChartAsJPEG(output, 1.0f, chart, 670, 250, null);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(ECALMessages.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(ECALMessages.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.sami.chart.util.LineChartDemo1.java

/**
 * Creates a sample chart.// w  w w .  j  ava 2  s .  co  m
 * 
 * @param dataset  a dataset.
 * 
 * @return The chart.
 */
private JFreeChart createChart(final CategoryDataset dataset) {

    // create the chart...
    final JFreeChart chart = ChartFactory.createLineChart("Line Chart Demo 1", // chart title
            "Type", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    //        final StandardLegend legend = (StandardLegend) chart.getLegend();
    //      legend.setDisplaySeriesShapes(true);
    //    legend.setShapeScaleX(1.5);
    //  legend.setShapeScaleY(1.5);
    //legend.setDisplaySeriesLines(true);

    chart.setBackgroundPaint(Color.white);

    final CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.white);

    // customise the range axis...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setAutoRangeIncludesZero(true);

    // ****************************************************************************
    // * 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.             *
    // ****************************************************************************

    // customise the renderer...
    final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    //        renderer.setDrawShapes(true);

    renderer.setSeriesStroke(0, new BasicStroke(0.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f,
            new float[] { 10.0f, 6.0f }, 0.0f));
    renderer.setSeriesStroke(1, new BasicStroke(0.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f,
            new float[] { 6.0f, 6.0f }, 0.0f));
    renderer.setSeriesStroke(2, new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f,
            new float[] { 2.0f, 6.0f }, 0.0f));
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;
}

From source file:unalcol.termites.boxplots.MessagesSent2.java

/**
 * Creates a new demo.//  w w  w  .  j av  a2s  .c om
 *
 * @param title the frame title.
 * @param pf
 */
public MessagesSent2(final String title, ArrayList<Double> pf) {

    super(title);

    final CategoryAxis xAxis = new CategoryAxis("");
    //final NumberAxis yAxis = new NumberAxis("Messages Sent");
    final NumberAxis yAxis = new NumberAxis("");

    yAxis.setAutoRangeIncludesZero(false);
    final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    final BoxAndWhiskerCategoryDataset dataset = createSampleDataset(pf, renderer);
    renderer.setFillBox(false);
    renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator());
    final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);

    Font font = new Font("Dialog", Font.PLAIN, 13);
    xAxis.setTickLabelFont(font);
    yAxis.setTickLabelFont(font);
    yAxis.setLabelFont(font);

    final JFreeChart chart = new JFreeChart("Messages Sent " + getTitle(pf),
            new Font("SansSerif", Font.BOLD, 18), plot, true);

    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(650, 370));
    setContentPane(chartPanel);
    TextTitle legendText = null;
    if (pf.size() == 1) {
        legendText = new TextTitle("Population Size");
    } else {
        legendText = new TextTitle("Population Size - Probability of Failure");
    }
    legendText.setPosition(RectangleEdge.BOTTOM);
    chart.addSubtitle(legendText);

    LegendTitle legend = chart.getLegend();
    legend.setPadding(new RectangleInsets(UnitType.RELATIVE, 0, 0.1, 0, 0));

    FileOutputStream output;
    try {
        output = new FileOutputStream("messagesnumber2" + pf + ".jpg");
        ChartUtilities.writeChartAsJPEG(output, 1.0f, chart, 670, 250, null);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(MessagesSent2.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(MessagesSent2.class.getName()).log(Level.SEVERE, null, ex);
    }
}