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:no.uio.medicine.virsurveillance.charts.BoxAndWhiskerChart_AWT.java

public BoxAndWhiskerChart_AWT(String applicationTitle, String chartTitle, String xTitle, String yTitle,
        ArrayList<ArrayList<Float>> singleSerieDataPoints, ArrayList<String> singleSerieCategories,
        String singleSerieTitle) {

    super(applicationTitle);

    this.chartTitle = chartTitle;
    this.xAxisTitle = xTitle;
    this.yAxisTitle = yTitle;
    this.Title = applicationTitle;

    this.dataPoints = new ArrayList<>();
    this.dataPoints.add(singleSerieDataPoints);
    this.categories = new ArrayList<>();
    this.categories.add(singleSerieCategories);
    this.seriesTitles = new ArrayList<>();
    this.seriesTitles.add(singleSerieTitle);

    BoxAndWhiskerCategoryDataset dataset = (BoxAndWhiskerCategoryDataset) createDataset(this.dataPoints,
            this.categories, this.seriesTitles);

    final CategoryAxis xAxis = new CategoryAxis(xTitle);
    final NumberAxis yAxis = new NumberAxis(yTitle);
    yAxis.setAutoRangeIncludesZero(false);
    this.renderer = new BoxAndWhiskerRenderer();
    this.renderer.setFillBox(false);

    this.renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator());
    this.plot = new CategoryPlot(dataset, xAxis, yAxis, this.renderer);

    final JFreeChart chart = new JFreeChart(chartTitle, new Font("SansSerif", Font.BOLD, 14), this.plot, true);
    chart.setBackgroundPaint(Color.white);
    this.chartPanel = new ChartPanel(chart);
    this.chartPanel.setBackground(Color.white);
    this.chartPanel.setPreferredSize(new java.awt.Dimension(1200, 500));
    setContentPane(chartPanel);/*from   w  w w.j  a v a 2  s .  c  o m*/
    this.setDefaultCloseOperation(HIDE_ON_CLOSE);

}

From source file:com.yahoo.egads.utilities.GUIUtils.java

/**
 * Creates a combined chart.//w ww.  j av  a 2  s  . c  om
 *
 * @return The combined chart.
 */
private JFreeChart createCombinedChart(DataSequence tsOne, DataSequence tsTwo, ArrayList<Anomaly> anomalyList) {

    // create subplot 1.
    final XYDataset data1 = createDataset(tsOne, "Original");
    final XYItemRenderer renderer1 = new StandardXYItemRenderer();
    final NumberAxis rangeAxis1 = new NumberAxis("Original Value");
    XYPlot subplot1 = new XYPlot(data1, null, rangeAxis1, renderer1);
    subplot1.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    // plot anomalies on subplot 1.
    addAnomalies(subplot1, anomalyList);

    // create subplot 2.
    final XYDataset data2 = createDataset(tsTwo, "Forecast");
    final XYItemRenderer renderer2 = new StandardXYItemRenderer();
    final NumberAxis rangeAxis2 = new NumberAxis("Forecast Value");
    rangeAxis2.setAutoRangeIncludesZero(false);
    final XYPlot subplot2 = new XYPlot(data2, null, rangeAxis2, renderer2);
    subplot2.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT);

    // parent plot.
    final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new NumberAxis("Time"));
    plot.setGap(10.0);

    // add the subplots.
    plot.add(subplot1, 1);
    plot.add(subplot2, 1);

    // Add anomaly score time-series.
    addAnomalyTS(plot, tsOne, tsTwo);

    plot.setOrientation(PlotOrientation.VERTICAL);

    // return a new chart containing the overlaid plot.
    return new JFreeChart("EGADS GUI", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
}

From source file:visualizer.projection.distance.view.DistanceHistogram.java

private JFreeChart createChart(IntervalXYDataset intervalxydataset) {
    JFreeChart chart = ChartFactory.createHistogram("Distance Histogram", "Distances Values", "Occurences",
            intervalxydataset, PlotOrientation.VERTICAL, true, true, false);

    //        JFreeChart chart = ChartFactory.createHistogram("Histograma das Distncias",
    //                "Valores", "Ocorrncias", intervalxydataset,
    //                PlotOrientation.VERTICAL, true, true, false);

    chart.setBackgroundPaint(Color.WHITE);

    XYPlot xyplot = (XYPlot) chart.getPlot();

    NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis();
    numberaxis.setAutoRangeIncludesZero(false);

    xyplot.setDomainGridlinePaint(Color.BLACK);
    xyplot.setRangeGridlinePaint(Color.BLACK);

    xyplot.setOutlinePaint(Color.BLACK);
    xyplot.setOutlineStroke(new BasicStroke(1.0f));
    xyplot.setBackgroundPaint(Color.white);
    xyplot.setDomainCrosshairVisible(true);
    xyplot.setRangeCrosshairVisible(true);

    XYBarRenderer xybarrenderer = (XYBarRenderer) xyplot.getRenderer();
    xybarrenderer.setDrawBarOutline(false);

    return chart;
}

From source file:osh.comdriver.simulation.cruisecontrol.AbstractDrawer.java

/**
 * Creates a chart./*w w  w.  j a v  a  2 s .  c o m*/
 *
 * @param dataset1  a dataset.
 *
 * @return A chart.
 */
private JFreeChart createChart(XYDataset dataset, long lastentry) {

    JFreeChart chart = ChartFactory.createTimeSeriesChart(name, // title
            "time", // x-axis label
            "temperature", // y-axis label
            dataset, // data
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = (XYPlot) chart.getPlot();

    NumberAxis axis1 = new NumberAxis(getAxisName());
    axis1.setAutoRangeIncludesZero(isIncludeZero());
    plot.setRangeAxis(0, axis1);

    plot.setDataset(0, dataset);
    plot.mapDatasetToRangeAxis(1, 0);

    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);
    //TODO: SHADOWS OFF

    final StandardXYItemRenderer r1 = new StandardXYItemRenderer();
    plot.setRenderer(0, r1);
    r1.setSeriesPaint(0, Color.BLUE);
    r1.setSeriesPaint(1, Color.RED);
    r1.setSeriesPaint(2, Color.GREEN);

    //plot.setDomainAxis(new NumberAxis("time"));
    plot.setDomainAxis(new DateAxis());
    plot.getDomainAxis().setAutoRange(false);

    long begin = getRangeBegin(lastentry);
    long end = getRangeEnd(lastentry);

    plot.getDomainAxis().setRange(begin, end);

    return chart;
}

From source file:org.drools.planner.benchmark.statistic.bestscore.BestScoreStatistic.java

private CharSequence writeGraphStatistic(File solverStatisticFilesDirectory, String baseName) {
    NumberAxis xAxis = new NumberAxis("Time millis spend");
    xAxis.setNumberFormatOverride(new MillisecondsSpendNumberFormat());
    NumberAxis yAxis = new NumberAxis("Score");
    yAxis.setAutoRangeIncludesZero(false);
    XYPlot plot = new XYPlot(null, xAxis, yAxis, null);
    int seriesIndex = 0;
    for (Map.Entry<String, BestScoreStatisticListener> listenerEntry : bestScoreStatisticListenerMap
            .entrySet()) {//from  w  w w .ja  v  a  2s  . co m
        String configName = listenerEntry.getKey();
        XYSeries series = new XYSeries(configName);
        List<BestScoreStatisticPoint> statisticPointList = listenerEntry.getValue().getStatisticPointList();
        for (BestScoreStatisticPoint statisticPoint : statisticPointList) {
            long timeMillisSpend = statisticPoint.getTimeMillisSpend();
            Score score = statisticPoint.getScore();
            Double scoreGraphValue = scoreDefinition.translateScoreToGraphValue(score);
            if (scoreGraphValue != null) {
                series.add(timeMillisSpend, scoreGraphValue);
            }
        }
        XYSeriesCollection seriesCollection = new XYSeriesCollection();
        seriesCollection.addSeries(series);
        plot.setDataset(seriesIndex, seriesCollection);
        XYItemRenderer renderer;
        // No direct lines between 2 points
        renderer = new XYStepRenderer();
        if (statisticPointList.size() <= 1) {
            // Workaround for https://sourceforge.net/tracker/?func=detail&aid=3387330&group_id=15494&atid=115494
            renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES);
        }
        plot.setRenderer(seriesIndex, renderer);
        seriesIndex++;
    }
    plot.setOrientation(PlotOrientation.VERTICAL);
    JFreeChart chart = new JFreeChart(baseName + " best score statistic", JFreeChart.DEFAULT_TITLE_FONT, plot,
            true);
    BufferedImage chartImage = chart.createBufferedImage(1024, 768);
    File graphStatisticFile = new File(solverStatisticFilesDirectory, baseName + "BestScoreStatistic.png");
    OutputStream out = null;
    try {
        out = new FileOutputStream(graphStatisticFile);
        ImageIO.write(chartImage, "png", out);
    } catch (IOException e) {
        throw new IllegalArgumentException("Problem writing graphStatisticFile: " + graphStatisticFile, e);
    } finally {
        IOUtils.closeQuietly(out);
    }
    return "  <img src=\"" + graphStatisticFile.getName() + "\"/>\n";
}

From source file:org.vast.stt.renderer.JFreeChart.XYPlotBuilder.java

public void createPlot(ChartScene scene) {
    this.scene = scene; //  scene contains the axis info, so passing it in here for now

    datasetCount = 0;/*from   w w w  .j  av  a 2  s .c  om*/
    rangeAxisCount = 0;
    currentItem = null;
    axisTable.clear();
    plot = new XYPlot();

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

    String axisName = "Time (s)";
    NumberAxis domainAxis = new NumberAxis(axisName);
    domainAxis.setAutoRangeIncludesZero(false);
    domainAxis.setAutoRange(false);
    domainAxis.setNumberFormatOverride(new DateFormat());
    domainAxis.setTickLabelInsets(new RectangleInsets(0, 30, 0, 30));
    domainAxis.setLowerBound(scene.getDomainMin());
    domainAxis.setUpperBound(scene.getDomainMax());
    plot.setDomainAxis(datasetCount, domainAxis);
}

From source file:no.uio.medicine.virsurveillance.charts.BoxAndWhiskerChart_AWT.java

/**
 * Creates a new demo./*from w ww  .j av a  2 s.co m*/
 *
 * @param applicationTitle
 * @param chartTitle
 * @param xTitle
 * @param yTitle
 * @param dataPoints
 * @param categories
 * @param seriesTitles
 */
public BoxAndWhiskerChart_AWT(String applicationTitle, String chartTitle, String xTitle, String yTitle,
        ArrayList<ArrayList<ArrayList<Float>>> dataPoints, ArrayList<ArrayList<String>> categories,
        ArrayList<String> seriesTitles) {

    super(applicationTitle);

    this.dataPoints = dataPoints;
    this.categories = categories;
    this.seriesTitles = seriesTitles;

    this.chartTitle = chartTitle;
    this.xAxisTitle = xTitle;
    this.yAxisTitle = yTitle;
    this.Title = applicationTitle;

    BoxAndWhiskerCategoryDataset dataset = (BoxAndWhiskerCategoryDataset) createDataset(this.dataPoints,
            this.categories, this.seriesTitles);

    final CategoryAxis xAxis = new CategoryAxis(this.xAxisTitle);
    final NumberAxis yAxis = new NumberAxis(this.yAxisTitle);
    yAxis.setAutoRangeIncludesZero(false);
    this.renderer = new BoxAndWhiskerRenderer();
    this.renderer.setFillBox(false);
    renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator());
    this.plot = new CategoryPlot(dataset, xAxis, yAxis, this.renderer);

    final JFreeChart chart = new JFreeChart(this.chartTitle, new Font("SansSerif", Font.BOLD, 14), this.plot,
            true);
    chart.setBackgroundPaint(Color.white);
    this.chartPanel = new ChartPanel(chart);
    this.chartPanel.setBackground(Color.white);
    this.chartPanel.setPreferredSize(new java.awt.Dimension(800, 500));
    setContentPane(this.chartPanel);

    this.setDefaultCloseOperation(HIDE_ON_CLOSE);
}

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);//from w  w  w  .  j av a 2 s.c o m
    valueAxis.setLowerMargin(0.15);
}

From source file:org.jgrasstools.gears.utils.chart.Scatter.java

public JFreeChart getChart() {
    if (chart == null) {
        chart = ChartFactory.createXYLineChart(title, // chart title
                xLabel,//from   w  w w .  j a  v a  2s.  c o m
                // domain axis label
                yLabel,
                // range axis label
                dataset,
                // data
                PlotOrientation.VERTICAL,
                // orientation
                false,
                // include legend
                true,
                // tooltips?
                false
        // URLs?
        );

        XYPlot plot = (XYPlot) chart.getPlot();
        if (xLog) {
            LogAxis xAxis = new LogAxis("");
            xAxis.setBase(10);
            plot.setDomainAxis(xAxis);
        }
        if (yLog) {
            LogAxis yAxis = new LogAxis("");
            yAxis.setBase(10);
            plot.setRangeAxis(yAxis);
        }

        ValueAxis rangeAxis = plot.getRangeAxis();
        if (rangeAxis instanceof NumberAxis) {
            NumberAxis axis = (NumberAxis) rangeAxis;
            axis.setAutoRangeIncludesZero(false);
        }

        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
        double x = 1.5;
        double w = x * 2;
        renderer.setSeriesShape(0, new Ellipse2D.Double(-x, x, w, w));
        setShapeLinesVisibility(plot);
    }
    return chart;
}

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

/**
 * Creates a chart./* www  .j  a  v  a2 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, //"Data vs Data 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);
    return chart;

}