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.ow2.clif.jenkins.chart.MovingStatChart.java

@Override
protected JFreeChart createChart() {
    XYSeriesCollection coreDataset = new XYSeriesCollection();
    coreDataset.addSeries(this.eventSerie);

    long periodMs = this.chartConfiguration.getStatisticalPeriod() * 1000L;

    XYSeriesCollection movingDataset = calculateMovingDataset(coreDataset, periodMs);
    XYSeriesCollection throughputDataset = calculateThroughputDataset(coreDataset, periodMs);

    JFreeChart chart;/*  w  ww .j  ava2  s . c om*/
    chart = ChartFactory
            .createXYLineChart(
                    getBasicTitle() + " "
                            + Messages.MovingChart_StatisticalPeriod(
                                    this.chartConfiguration.getStatisticalPeriod()),
                    // chart title
                    Messages.MovingChart_Time(), // x axis label
                    Messages.MovingChart_ResponseTime(), // y axis label
                    movingDataset, // data
                    PlotOrientation.VERTICAL, true, // include legend
                    true, // tooltips
                    false // urls
    );

    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    XYPlot plot = (XYPlot) chart.getPlot();
    configureBasicPlotProperties(plot);

    // Force the 0 on vertical axis
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setAutoRangeIncludesZero(true);
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // Force the 0 on horizontal axis
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setAutoRangeIncludesZero(true);

    attachThroughputDatasetToDedicatedAxis(throughputDataset, plot);

    // Global renderer for moving stats
    plot.setRenderer(getGlobalRenderer());

    // Dedicated Throughput renderer
    plot.setRenderer(1, getThroughputRenderer());

    return chart;
}

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

private CharSequence writeGraphStatistic(File solverStatisticFilesDirectory, String baseName) {
    XYSeriesCollection seriesCollection = new XYSeriesCollection();
    for (Map.Entry<String, BestScoreStatisticListener> listenerEntry : bestScoreStatisticListenerMap
            .entrySet()) {/*from   w w  w .j a v a  2 s.co m*/
        String configName = listenerEntry.getKey();
        XYSeries configSeries = new XYSeries(configName);
        List<BestScoreStatisticPoint> statisticPointList = listenerEntry.getValue()
                .getBestScoreStatisticPointList();
        for (BestScoreStatisticPoint statisticPoint : statisticPointList) {
            long timeMillisSpend = statisticPoint.getTimeMillisSpend();
            Score score = statisticPoint.getScore();
            Double scoreGraphValue = scoreDefinition.translateScoreToGraphValue(score);
            if (scoreGraphValue != null) {
                configSeries.add(timeMillisSpend, scoreGraphValue);
            }
        }
        seriesCollection.addSeries(configSeries);
    }
    NumberAxis xAxis = new NumberAxis("Time millis spend");
    xAxis.setNumberFormatOverride(new MillisecondsSpendNumberFormat());
    NumberAxis yAxis = new NumberAxis("Score");
    yAxis.setAutoRangeIncludesZero(false);
    XYItemRenderer renderer = new XYStepRenderer();
    XYPlot plot = new XYPlot(seriesCollection, xAxis, yAxis, renderer);
    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 + "Statistic.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:uk.co.petertribble.jkstat.gui.KstatBaseChart.java

/**
 * Set up the X and Y axes./*from www.  j  a  va 2  s  .  com*/
 */
public void setAxes() {
    XYPlot xyplot = chart.getXYPlot();

    String ylabel = showdelta ? KstatResources.getString("CHART.RATE")
            : KstatResources.getString("CHART.VALUE");
    NumberAxis loadaxis = new NumberAxis(ylabel);
    loadaxis.setAutoRange(true);
    loadaxis.setAutoRangeIncludesZero(true);
    xyplot.setRangeAxis(loadaxis);

    DateAxis daxis = new DateAxis(KstatResources.getString("CHART.TIME"));
    daxis.setAutoRange(true);
    // let a sequnce show its full date range
    if (!(jkstat instanceof SequencedJKstat)) {
        daxis.setFixedAutoRange(maxage);
    }
    xyplot.setDomainAxis(daxis);
}

From source file:org.drugis.addis.gui.ConvergencePlotsDialog.java

private JFreeChart createRhatChart(final XYDataset dataset) {
    final JFreeChart RhatChart = ChartFactory.createXYLineChart("Iterative PSRF Plot", "Iteration No.",
            "R-Hat(p)", dataset, PlotOrientation.VERTICAL, false, true, false);

    RhatChart.setBackgroundPaint(Color.white);
    final XYPlot RhatPlot = RhatChart.getXYPlot();
    RhatPlot.setDomainGridlinePaint(Color.white);
    RhatPlot.setRangeGridlinePaint(Color.white);

    final NumberAxis rangeAxis = (NumberAxis) RhatPlot.getRangeAxis();
    rangeAxis.setAutoRange(true);/*from  w w w .j a va 2  s.  co m*/
    rangeAxis.setAutoRangeIncludesZero(false);

    return RhatChart;
}

From source file:arduinoserialread.SerialRead.java

private void initGUI() {

    // init the frame
    frame.setTitle("Arduino Serial Read");
    frame.setBounds(100, 100, 600, 500);
    frame.setMinimumSize(new Dimension(600, 500));
    frame.setLocationRelativeTo(null);// w  w  w  . j a  v  a 2  s  . c o m
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // init control panel
    JPanel ctrlPanel = new JPanel();
    ctrlPanel.setLayout(new FlowLayout());

    // init the serial connection panel
    serialCOM = new SerialConnectionPanel();
    ctrlPanel.add(serialCOM);
    frame.getContentPane().add(ctrlPanel, BorderLayout.SOUTH);

    // init the connection status
    ConnectionStatus connectionStatus = new ConnectionStatus();
    ctrlPanel.add(connectionStatus);

    // init connect and disconnect button
    connect = new JButton("connect");
    ctrlPanel.add(connect);
    disconnect = new JButton("disconnect");
    ctrlPanel.add(disconnect);

    // init real time chart
    TimeSeries series = new TimeSeries("DATA");
    DateAxis timeAxis = new DateAxis("Time");
    dataset = new TimeSeriesCollection(series);
    NumberAxis rangeAxis = new NumberAxis("Data");
    rangeAxis.setAutoRangeIncludesZero(false);
    rangeAxis.setAutoRange(true);
    XYPlot plot = new XYPlot(dataset, timeAxis, rangeAxis, new StandardXYItemRenderer());
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.getRenderer().setSeriesPaint(0, new Color(0, 142, 192));
    ValueAxis domainAxis = plot.getDomainAxis();
    domainAxis.setAutoRange(true);
    domainAxis.setFixedAutoRange(30000.0); // 30 seconds
    // init the JFreeChart
    JFreeChart chart = new JFreeChart("Real-Time Data Chart", plot);
    chart.setBorderPaint(Color.lightGray);
    chart.setBorderVisible(true);
    chart.setBackgroundPaint(Color.white);
    chart.removeLegend();
    // add real time chart to the frame
    ChartPanel chartPanel = new ChartPanel(chart);
    frame.getContentPane().add(chartPanel, BorderLayout.CENTER);

}

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

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

    // create the chart...
    JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, //"Normal 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);    // very confusing   
    return chart;

}

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

/**
 * Creates a sample chart.//from  w ww.j  av a2s. c  o m
 * 
 * @param dataset  a dataset.
 * 
 * @return The chart.
 */
protected JFreeChart createChart(CategoryDataset dataset) {

    // create the chart...
    JFreeChart chart = ChartFactory.createLineChart(chartTitle, // chart title
            domainLabel, // domain axis label
            rangeLabel, // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            !legendPanelOn, // include legend
            true, // tooltips
            false // urls
    );

    chart.setBackgroundPaint(Color.white);

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

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

    // customise the renderer...
    StatisticalBarRenderer renderer = new StatisticalBarRenderer();
    renderer.setErrorIndicatorPaint(Color.black);
    //   renderer.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator());
    plot.setRenderer(renderer);

    // OPTIONAL CUSTOMISATION COMPLETED.
    return chart;
}

From source file:org.optaplanner.benchmark.impl.statistic.scorecalculationspeed.ScoreCalculationSpeedProblemStatistic.java

@Override
public void writeGraphFiles(BenchmarkReport benchmarkReport) {
    Locale locale = benchmarkReport.getLocale();
    NumberAxis xAxis = new NumberAxis("Time spent");
    xAxis.setNumberFormatOverride(new MillisecondsSpentNumberFormat(locale));
    NumberAxis yAxis = new NumberAxis("Score calculation speed per second");
    yAxis.setNumberFormatOverride(NumberFormat.getInstance(locale));
    yAxis.setAutoRangeIncludesZero(false);
    XYPlot plot = new XYPlot(null, xAxis, yAxis, null);
    plot.setOrientation(PlotOrientation.VERTICAL);
    int seriesIndex = 0;
    for (SingleBenchmarkResult singleBenchmarkResult : problemBenchmarkResult.getSingleBenchmarkResultList()) {
        XYSeries series = new XYSeries(
                singleBenchmarkResult.getSolverBenchmarkResult().getNameWithFavoriteSuffix());
        XYItemRenderer renderer = new XYLineAndShapeRenderer();
        if (singleBenchmarkResult.hasAllSuccess()) {
            ScoreCalculationSpeedSubSingleStatistic subSingleStatistic = (ScoreCalculationSpeedSubSingleStatistic) singleBenchmarkResult
                    .getSubSingleStatistic(problemStatisticType);
            List<ScoreCalculationSpeedStatisticPoint> points = subSingleStatistic.getPointList();
            for (ScoreCalculationSpeedStatisticPoint point : points) {
                long timeMillisSpent = point.getTimeMillisSpent();
                long scoreCalculationSpeed = point.getScoreCalculationSpeed();
                series.add(timeMillisSpent, scoreCalculationSpeed);
            }//from  w  ww.  j a  v a2  s  .co  m
        }
        plot.setDataset(seriesIndex, new XYSeriesCollection(series));

        if (singleBenchmarkResult.getSolverBenchmarkResult().isFavorite()) {
            // Make the favorite more obvious
            renderer.setSeriesStroke(0, new BasicStroke(2.0f));
        }
        plot.setRenderer(seriesIndex, renderer);
        seriesIndex++;
    }
    JFreeChart chart = new JFreeChart(problemBenchmarkResult.getName() + " score calculation speed statistic",
            JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    graphFile = writeChartToImageFile(chart,
            problemBenchmarkResult.getName() + "ScoreCalculationSpeedStatistic");
}

From source file:org.drools.planner.benchmark.statistic.calculatecount.CalculateCountStatistic.java

private CharSequence writeGraphStatistic(File solverStatisticFilesDirectory, String baseName) {
    XYSeriesCollection seriesCollection = new XYSeriesCollection();
    for (Map.Entry<String, CalculateCountStatisticListener> listenerEntry : statisticListenerMap.entrySet()) {
        String configName = listenerEntry.getKey();
        XYSeries series = new XYSeries(configName);
        List<CalculateCountStatisticPoint> statisticPointList = listenerEntry.getValue()
                .getStatisticPointList();
        for (CalculateCountStatisticPoint statisticPoint : statisticPointList) {
            long timeMillisSpend = statisticPoint.getTimeMillisSpend();
            long calculateCountPerSecond = statisticPoint.getCalculateCountPerSecond();
            series.add(timeMillisSpend, calculateCountPerSecond);
        }//from ww  w. ja va  2s . c o  m
        seriesCollection.addSeries(series);
    }
    NumberAxis xAxis = new NumberAxis("Time millis spend");
    xAxis.setNumberFormatOverride(new MillisecondsSpendNumberFormat());
    NumberAxis yAxis = new NumberAxis("Calculate count per second");
    yAxis.setAutoRangeIncludesZero(false);
    XYItemRenderer renderer = new XYLineAndShapeRenderer();
    XYPlot plot = new XYPlot(seriesCollection, xAxis, yAxis, renderer);
    plot.setOrientation(PlotOrientation.VERTICAL);
    JFreeChart chart = new JFreeChart(baseName + " calculate count statistic", JFreeChart.DEFAULT_TITLE_FONT,
            plot, true);
    BufferedImage chartImage = chart.createBufferedImage(1024, 768);
    File graphStatisticFile = new File(solverStatisticFilesDirectory, baseName + "CalculateCountStatistic.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.encog.workbench.dialogs.training.ChartPane.java

/**
 * Create the initial chart./* w w  w  .  java2s  .  co m*/
 * @return The chart.
 */
private JFreeChart createChart() {

    this.chart = ChartFactory.createXYLineChart(null, "Iteration", "Current Error", this.dataset1,
            PlotOrientation.VERTICAL, true, true, false);

    final XYPlot plot = (XYPlot) this.chart.getPlot();
    plot.setOrientation(PlotOrientation.VERTICAL);

    plot.getRangeAxis().setFixedDimension(15.0);

    // AXIS 2
    final NumberAxis axis2 = new NumberAxis("Error Improvement");
    axis2.setFixedDimension(10.0);
    axis2.setAutoRangeIncludesZero(false);
    axis2.setLabelPaint(Color.red);
    axis2.setTickLabelPaint(Color.red);
    plot.setRangeAxis(1, axis2);
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);

    plot.setDataset(1, this.dataset2);
    plot.mapDatasetToRangeAxis(1, 1);
    final XYItemRenderer renderer2 = new StandardXYItemRenderer();
    renderer2.setSeriesPaint(0, Color.red);
    plot.setRenderer(1, renderer2);

    ChartUtilities.applyCurrentTheme(this.chart);

    return this.chart;
}