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.optaplanner.benchmark.impl.statistic.calculatecount.CalculateCountProblemStatistic.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("Calculate count 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.isSuccess()) {
            CalculateCountSingleStatistic singleStatistic = (CalculateCountSingleStatistic) singleBenchmarkResult
                    .getSingleStatistic(problemStatisticType);
            for (CalculateCountStatisticPoint point : singleStatistic.getPointList()) {
                long timeMillisSpent = point.getTimeMillisSpent();
                long calculateCountPerSecond = point.getCalculateCountPerSecond();
                series.add(timeMillisSpent, calculateCountPerSecond);
            }/*from ww w  . jav a  2 s . c o  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() + " calculate count statistic",
            JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    graphFile = writeChartToImageFile(chart, problemBenchmarkResult.getName() + "CalculateCountStatistic");
}

From source file:guineu.modules.filter.report.intensitiesReport.ReportTask.java

/**
 * Create the chart and save it into a png file.
 * @param dataset//from  ww  w.ja  v a 2s  .  com
 * @param lipidName
 */
private void createChart(CategoryDataset dataset, String lipidName) {
    try {
        String fieldY;
        if (this.useArea) {
            fieldY = "Area";
        } else {
            fieldY = "Heights";
        }

        JFreeChart chart = ChartFactory.createLineChart("Intensities", "Samples", fieldY, dataset,
                PlotOrientation.VERTICAL, false, false, false);

        // Chart characteristics
        CategoryPlot plot = (CategoryPlot) chart.getPlot();
        final NumberAxis axis = (NumberAxis) plot.getRangeAxis();
        axis.setAutoRangeIncludesZero(false);
        LineAndShapeRenderer categoryRenderer = new LineAndShapeRenderer();
        categoryRenderer.setSeriesLinesVisible(0, false);
        categoryRenderer.setSeriesShapesVisible(0, true);
        plot.setRenderer(categoryRenderer);

        // Save all the charts in the folder choosen by the user
        ChartUtilities.saveChartAsPNG(new File(this.reportFileName + "/" + fieldY + ":" + lipidName + ".png"),
                chart, 1000, 500);
    } catch (IOException ex) {
        Logger.getLogger(ReportTask.class.getName()).log(Level.SEVERE, null, ex);
    }

}

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

/**
 * Creates the demo chart./*from ww  w.  j a  v a 2  s .com*/
 * 
 * @return The chart.
 */
private JFreeChart createChart() {

    final XYDataset dataset1 = createDataset("Series 1", 100.0, new Minute(), 200);

    final JFreeChart chart = ChartFactory.createTimeSeriesChart("Multiple Axis Demo 1", "Time of Day",
            "Primary Range Axis", dataset1, true, true, false);

    chart.setBackgroundPaint(Color.white);
    chart.addSubtitle(new TextTitle("Four datasets and four range axes."));
    final XYPlot plot = chart.getXYPlot();
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    //        plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));

    final StandardXYItemRenderer renderer = (StandardXYItemRenderer) plot.getRenderer();
    renderer.setPaint(Color.black);

    // AXIS 2
    final NumberAxis axis2 = new NumberAxis("Range Axis 2");
    axis2.setAutoRangeIncludesZero(false);
    axis2.setLabelPaint(Color.red);
    axis2.setTickLabelPaint(Color.red);
    plot.setRangeAxis(1, axis2);
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_LEFT);

    final XYDataset dataset2 = createDataset("Series 2", 1000.0, new Minute(), 170);
    plot.setDataset(1, dataset2);
    plot.mapDatasetToRangeAxis(1, 1);
    XYItemRenderer renderer2 = new StandardXYItemRenderer();
    renderer2.setSeriesPaint(0, Color.red);
    plot.setRenderer(1, renderer2);

    // AXIS 3
    final NumberAxis axis3 = new NumberAxis("Range Axis 3");
    axis3.setLabelPaint(Color.blue);
    axis3.setTickLabelPaint(Color.blue);
    plot.setRangeAxis(2, axis3);

    final XYDataset dataset3 = createDataset("Series 3", 10000.0, new Minute(), 170);
    plot.setDataset(2, dataset3);
    plot.mapDatasetToRangeAxis(2, 2);
    XYItemRenderer renderer3 = new StandardXYItemRenderer();
    renderer3.setSeriesPaint(0, Color.blue);
    plot.setRenderer(2, renderer3);

    // AXIS 4        
    final NumberAxis axis4 = new NumberAxis("Range Axis 4");
    axis4.setLabelPaint(Color.green);
    axis4.setTickLabelPaint(Color.green);
    plot.setRangeAxis(3, axis4);

    final XYDataset dataset4 = createDataset("Series 4", 25.0, new Minute(), 200);
    plot.setDataset(3, dataset4);
    plot.mapDatasetToRangeAxis(3, 3);

    XYItemRenderer renderer4 = new StandardXYItemRenderer();
    renderer4.setSeriesPaint(0, Color.green);
    plot.setRenderer(3, renderer4);

    return chart;
}

From source file:org.drools.planner.benchmark.statistic.memoryuse.MemoryUseStatistic.java

private CharSequence writeGraphStatistic(File solverStatisticFilesDirectory, String baseName) {
    XYSeriesCollection seriesCollection = new XYSeriesCollection();
    for (Map.Entry<String, MemoryUseStatisticListener> listenerEntry : statisticListenerMap.entrySet()) {
        String configName = listenerEntry.getKey();
        XYSeries usedSeries = new XYSeries(configName + " used");
        XYSeries maxSeries = new XYSeries(configName + " max");
        List<MemoryUseStatisticPoint> statisticPointList = listenerEntry.getValue().getStatisticPointList();
        for (MemoryUseStatisticPoint statisticPoint : statisticPointList) {
            long timeMillisSpend = statisticPoint.getTimeMillisSpend();
            MemoryUseMeasurement memoryUseMeasurement = statisticPoint.getMemoryUseMeasurement();
            usedSeries.add(timeMillisSpend, memoryUseMeasurement.getUsedMemory());
            maxSeries.add(timeMillisSpend, memoryUseMeasurement.getMaxMemory());
        }//  w w  w  .ja v a  2 s  . c  o m
        seriesCollection.addSeries(usedSeries);
        seriesCollection.addSeries(maxSeries);
    }
    NumberAxis xAxis = new NumberAxis("Time millis spend");
    xAxis.setNumberFormatOverride(new MillisecondsSpendNumberFormat());
    NumberAxis yAxis = new NumberAxis("Memory");
    yAxis.setAutoRangeIncludesZero(false);
    XYItemRenderer renderer = new XYAreaRenderer2();
    XYPlot plot = new XYPlot(seriesCollection, xAxis, yAxis, renderer);
    plot.setOrientation(PlotOrientation.VERTICAL);
    JFreeChart chart = new JFreeChart(baseName + " memory use statistic", JFreeChart.DEFAULT_TITLE_FONT, plot,
            true);
    BufferedImage chartImage = chart.createBufferedImage(1024, 768);
    File graphStatisticFile = new File(solverStatisticFilesDirectory, baseName + "MemoryUseStatistic.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.optaplanner.benchmark.impl.statistic.bestsolutionmutation.BestSolutionMutationProblemStatistic.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("Best solution mutation count");
    yAxis.setNumberFormatOverride(NumberFormat.getInstance(locale));
    yAxis.setAutoRangeIncludesZero(true);
    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.isSuccess()) {
            BestSolutionMutationSingleStatistic singleStatistic = (BestSolutionMutationSingleStatistic) singleBenchmarkResult
                    .getSingleStatistic(problemStatisticType);
            for (BestSolutionMutationStatisticPoint point : singleStatistic.getPointList()) {
                long timeMillisSpent = point.getTimeMillisSpent();
                long mutationCount = point.getMutationCount();
                series.add(timeMillisSpent, mutationCount);
            }/*from w w  w  .  j av  a  2 s.  c om*/
        }
        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() + " best solution mutation statistic",
            JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    graphFile = writeChartToImageFile(chart,
            problemBenchmarkResult.getName() + "BestSolutionMutationStatistic");
}

From source file:org.jreserve.gui.calculations.factor.editor.DevelopmentFactorPlot.java

private Component createPlotComponent() {

    boolean legend = true;
    boolean tooltips = false;
    boolean urls = false;
    chart = ChartFactory.createLineChart(null, null, null, dataSet, PlotOrientation.VERTICAL, legend, tooltips,
            urls);/*w  ww. ja  v a2s. c  om*/

    CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.GRAY);
    plot.setRangeGridlinesVisible(true);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.WHITE);
    plot.setDomainGridlinePaint(Color.WHITE);

    NumberAxis axis = (NumberAxis) plot.getRangeAxis();
    axis.setAutoRangeIncludesZero(false);
    axis.setAutoRangeStickyZero(true);

    renderer = plot.getRenderer();
    if (renderer instanceof LineAndShapeRenderer) {
        LineAndShapeRenderer lasr = (LineAndShapeRenderer) renderer;
        lasr.setBaseShapesVisible(true);
        lasr.setDrawOutlines(true);
        lasr.setUseFillPaint(true);
        lasr.setBaseStroke(new BasicStroke(2));

        int r = 3;
        Shape circle = new Ellipse2D.Float(-r, -r, 2 * r, 2 * r);
        int count = dataSet.getRowCount();
        for (int i = 0; i < count; i++) {
            PlotLabel label = (PlotLabel) dataSet.getRowKey(i);
            boolean isLr = label.getId() >= developments;

            Color color = isLr ? LINK_RATIO : FACTOR;
            lasr.setSeriesPaint(i, color);
            lasr.setSeriesFillPaint(i, color);
            lasr.setSeriesShape(i, circle);

            lasr.setSeriesShapesVisible(i, !isLr);
            lasr.setSeriesLinesVisible(i, isLr);
        }
    }

    return new ChartPanel(chart);
}

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

/**
 * Creates a combined chart./*from  w w  w .  j av a2 s.c o  m*/
 *
 * @return The combined chart.
 */
private JFreeChart createCombinedChart() {

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

    // add secondary axis
    subplot1.setDataset(1, createDataset2());
    final NumberAxis axis2 = new NumberAxis("Range Axis 2");
    axis2.setAutoRangeIncludesZero(false);
    subplot1.setRangeAxis(1, axis2);
    subplot1.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);
    subplot1.setRenderer(1, new StandardXYItemRenderer());
    subplot1.mapDatasetToRangeAxis(1, 1);

    final XYTextAnnotation annotation = new XYTextAnnotation("Hello!", 50.0, 10000.0);
    annotation.setFont(new Font("SansSerif", Font.PLAIN, 9));
    annotation.setRotationAngle(Math.PI / 4.0);
    subplot1.addAnnotation(annotation);

    // create subplot 2...
    final XYDataset data2 = createDataset2();
    final XYItemRenderer renderer2 = new StandardXYItemRenderer();
    final NumberAxis rangeAxis2 = new NumberAxis("Range 2");
    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("Domain"));
    plot.setGap(10.0);

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

    // return a new chart containing the overlaid plot...
    return new JFreeChart("CombinedDomainXYPlot Demo", JFreeChart.DEFAULT_TITLE_FONT, plot, true);

}

From source file:org.optaplanner.benchmark.impl.statistic.stepscore.StepScoreProblemStatistic.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("Step score 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  .  j ava2s  .c o m*/
}

From source file:com.intel.stl.ui.monitor.view.TrafficChartsCreator.java

protected JFreeChart getPacketsRateChart(Dataset dataset) {
    JFreeChart chart = ComponentFactory.createXYAreaChart(STLConstants.K0035_TIME.getValue(),
            STLConstants.K0750_PPS.getValue(), (XYDataset) dataset, false);

    NumberAxis rangeAxis = (NumberAxis) chart.getXYPlot().getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setAutoRangeIncludesZero(false);
    return chart;
}

From source file:com.intel.stl.ui.monitor.view.TrafficChartsCreator.java

protected JFreeChart getDataRateChart(Dataset dataset) {
    JFreeChart chart = ComponentFactory.createXYAreaChart(STLConstants.K0035_TIME.getValue(),
            STLConstants.K0703_MB_PER_SEC.getValue(), (XYDataset) dataset, false);

    NumberAxis rangeAxis = (NumberAxis) chart.getXYPlot().getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setAutoRangeIncludesZero(false);
    return chart;
}