Example usage for org.jfree.chart.axis NumberAxis NumberAxis

List of usage examples for org.jfree.chart.axis NumberAxis NumberAxis

Introduction

In this page you can find the example usage for org.jfree.chart.axis NumberAxis NumberAxis.

Prototype

public NumberAxis(String label) 

Source Link

Document

Constructs a number axis, using default values where necessary.

Usage

From source file:org.optaplanner.benchmark.impl.statistic.memoryuse.MemoryUseProblemStatistic.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("Memory");
    yAxis.setNumberFormatOverride(NumberFormat.getInstance(locale));
    XYPlot plot = new XYPlot(null, xAxis, yAxis, null);
    plot.setOrientation(PlotOrientation.VERTICAL);
    int seriesIndex = 0;
    for (SingleBenchmarkResult singleBenchmarkResult : problemBenchmarkResult.getSingleBenchmarkResultList()) {
        XYSeries usedSeries = new XYSeries(
                singleBenchmarkResult.getSolverBenchmarkResult().getNameWithFavoriteSuffix() + " used");
        // TODO enable max memory, but in the same color as used memory, but with a dotted line instead
        //            XYSeries maxSeries = new XYSeries(
        //                    singleBenchmarkResult.getSolverBenchmarkResult().getNameWithFavoriteSuffix() + " max");
        XYItemRenderer renderer = new XYLineAndShapeRenderer();
        if (singleBenchmarkResult.isSuccess()) {
            MemoryUseSingleStatistic singleStatistic = (MemoryUseSingleStatistic) singleBenchmarkResult
                    .getSingleStatistic(problemStatisticType);
            for (MemoryUseStatisticPoint point : singleStatistic.getPointList()) {
                long timeMillisSpent = point.getTimeMillisSpent();
                MemoryUseMeasurement memoryUseMeasurement = point.getMemoryUseMeasurement();
                usedSeries.add(timeMillisSpent, memoryUseMeasurement.getUsedMemory());
                //                    maxSeries.add(timeMillisSpent, memoryUseMeasurement.getMaxMemory());
            }/*from   w  w  w .j  a v  a 2 s  .  co m*/
        }
        XYSeriesCollection seriesCollection = new XYSeriesCollection();
        seriesCollection.addSeries(usedSeries);
        //            seriesCollection.addSeries(maxSeries);
        plot.setDataset(seriesIndex, seriesCollection);

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

From source file:playground.anhorni.PLOC.analysis.RunsEnsembleBoxPlot.java

public JFreeChart createChart() {
    String title = chartTitle;//from   w w w  .  j a va2 s .c  o  m

    final CategoryAxis xAxis = new CategoryAxis("Hour");
    xAxis.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 10));
    xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);

    final NumberAxis yAxis = new NumberAxis("AverageDays_Expenditures");
    yAxis.setAutoRangeIncludesZero(true);

    final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setFillBox(false);
    renderer.setSeriesPaint(0, Color.blue);
    CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);

    this.chart_ = new JFreeChart(title, new Font("SansSerif", Font.BOLD, 14), plot, false);
    return this.chart_;
}

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);
            }/*w  w  w.j  a v  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:playground.yu.utils.charts.XYScatterLineChart.java

private JFreeChart createChart(final String title, final String categoryAxisLabel, final String valueAxisLabel,
        final XYSeriesCollection dataset) {
    // return ChartFactory.createScatterPlot(title, categoryAxisLabel,
    // valueAxisLabel, dataset, PlotOrientation.VERTICAL, true, // legend?
    // false, // tooltips?
    // false // URLs?
    // );//ww  w .  ja  v  a 2  s. c  o m
    NumberAxis xAxis = new NumberAxis(categoryAxisLabel);
    xAxis.setAutoRangeIncludesZero(false);
    xAxis.setRange(0, 24);
    NumberAxis yAxis = new NumberAxis(valueAxisLabel);
    yAxis.setAutoRangeIncludesZero(true);
    yAxis.setRange(0, 100);

    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null);

    XYItemRenderer renderer = new XYLineAndShapeRenderer(true, true);
    renderer.setBaseToolTipGenerator(null/* XYToolTipGenerator */);
    renderer.setURLGenerator(null/* urlGenerator */);
    plot.setRenderer(renderer);
    plot.setOrientation(PlotOrientation.VERTICAL);

    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true/* legend */);
    return chart;
}

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  a v a  2 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() + " best solution mutation statistic",
            JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    graphFile = writeChartToImageFile(chart,
            problemBenchmarkResult.getName() + "BestSolutionMutationStatistic");
}

From source file:playground.anhorni.PLOC.analysis.MultipleEnsemblesBoxPlot.java

public JFreeChart createChart() {
    String title = chartTitle;/*from  w w  w. j av a  2 s . c  om*/

    final CategoryAxis xAxis = new CategoryAxis("Runs ensemble size");
    xAxis.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 10));
    xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);

    final NumberAxis yAxis = new NumberAxis("AvgDaysRuns_OfEnsembleAverageOfTotalExpenditures");
    yAxis.setAutoRangeIncludesZero(true);

    final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setFillBox(false);
    renderer.setSeriesPaint(0, Color.blue);
    CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);

    this.chart_ = new JFreeChart(title, new Font("SansSerif", Font.BOLD, 14), plot, false);
    return this.chart_;
}

From source file:pwm.visualizer.MDPPolicyPanel.java

private JFreeChart createChart() {
    NumberAxis nutritionAxis = new NumberAxis("Calories/Day");
    nutritionAxis.setLowerBound(0);/*from  w w  w  .j a v a  2 s .co m*/
    nutritionAxis.setUpperBound(5000);
    nutritionAxis.setAutoRange(false);
    //      
    CategoryPlot categoryplot = new CategoryPlot(nutritionDataSet, new CategoryAxis("Weight(KG)"),
            nutritionAxis, new BarRenderer());
    CategoryAxis xaxis = categoryplot.getDomainAxis();
    xaxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);

    LegendItemCollection legend = new LegendItemCollection();
    LegendItem nutritionLegend = new LegendItem("Calories/Day");
    LegendItem exerciseLegend = new LegendItem("Physical Activity Level");
    nutritionLegend.setFillPaint(Color.BLUE);
    exerciseLegend.setFillPaint(Color.RED);

    legend.add(nutritionLegend);
    legend.add(exerciseLegend);

    categoryplot.setFixedLegendItems(legend);
    JFreeChart jfreechart = new JFreeChart("Policy Visualizer", categoryplot);
    categoryplot.setDataset(1, exerciseDataSet);
    categoryplot.mapDatasetToRangeAxis(1, 1);

    NumberAxis exerciseAxis = new NumberAxis("Physical Activity Level");
    exerciseAxis.setLowerBound(0);
    exerciseAxis.setUpperBound(3.0);
    exerciseAxis.setAutoRange(false);

    categoryplot.setRangeAxis(1, exerciseAxis);
    BarRenderer barrenderer1 = new BarRenderer();
    categoryplot.setRenderer(1, barrenderer1);

    //        BarRenderer stackedbarrenderer = (BarRenderer)categoryplot.getRenderer();
    //        stackedbarrenderer.setDrawBarOutline(true);
    //        stackedbarrenderer.setBaseItemLabelsVisible(false);
    //        stackedbarrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());

    ChartUtilities.applyCurrentTheme(jfreechart);

    return jfreechart;

}

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

/**
 * A demonstration application showing how to....
 *
 * @param title  the frame title.//from ww w .  j a va 2s. co  m
 */
public TimePeriodValuesDemo2(final String title) {

    super(title);

    final XYDataset data1 = createDataset();
    final XYItemRenderer renderer1 = new XYBarRenderer();

    final DateAxis domainAxis = new DateAxis("Date");
    final ValueAxis rangeAxis = new NumberAxis("Value");

    final XYPlot plot = new XYPlot(data1, domainAxis, rangeAxis, renderer1);

    final JFreeChart chart = new JFreeChart("Time Period Values Demo", plot);
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    chartPanel.setMouseZoomable(true, false);
    setContentPane(chartPanel);

}

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

/**
 * Runs the test./*from   w ww .jav  a 2 s .  c  om*/
 */
public void run() {

    this.finished = false;

    // create a dataset...
    populateData();

    // create a fast scatter chart...
    final Plot plot = new FastScatterPlot(this.data, new NumberAxis("X"), new NumberAxis("Y"));
    final JFreeChart chart = new JFreeChart("Fast Scatter Plot Timing", JFreeChart.DEFAULT_TITLE_FONT, plot,
            true);

    final BufferedImage image = new BufferedImage(400, 300, BufferedImage.TYPE_INT_RGB);
    final Graphics2D g2 = image.createGraphics();
    final Rectangle2D chartArea = new Rectangle2D.Double(0, 0, 400, 300);

    // set up the timer...
    final Timer timer = new Timer(10000, this);
    timer.setRepeats(false);
    int count = 0;
    timer.start();
    while (!this.finished) {
        chart.draw(g2, chartArea, null, null);
        System.out.println("Charts drawn..." + count);
        if (!this.finished) {
            count++;
        }
    }
    System.out.println("DONE");

}

From source file:com.insa.tp3g1.esbsimulator.view.OverlaidBarChart.java

/**
 * Default constructor.//from   ww w  .  jav  a  2  s .c om
 *
 * @param title  the frame title.
 * @param result
 */
public OverlaidBarChart(final String title, Result result) {

    super(title);

    // create the first dataset...
    DefaultCategoryDataset dataset1 = new DefaultCategoryDataset();
    LinkConsumerProvider[] linkConsProv = result.getLinksConsumerProvider();
    for (LinkConsumerProvider linkConsProv1 : linkConsProv) {
        dataset1.addValue(Integer.parseInt(linkConsProv1.getAverageResponseTime()), average,
                link + linkConsProv1.getConsumerId());
    }

    // create the first renderer...
    //      final CategoryLabelGenerator generator = new StandardCategoryLabelGenerator();
    final CategoryItemRenderer renderer = new BarRenderer();
    //    renderer.setLabelGenerator(generator);
    renderer.setItemLabelsVisible(true);

    final CategoryPlot plot = new CategoryPlot();
    plot.setDataset(dataset1);
    plot.setRenderer(renderer);

    plot.setDomainAxis(new CategoryAxis("Category"));
    plot.setRangeAxis(new NumberAxis("Value (ms)"));

    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setRangeGridlinesVisible(true);
    plot.setDomainGridlinesVisible(true);

    // now create the second dataset and renderer...
    DefaultCategoryDataset dataset2 = new DefaultCategoryDataset();

    for (LinkConsumerProvider linkConsProv1 : linkConsProv) {
        dataset2.addValue(Integer.parseInt(result.getTotalResult().getResponseTime().getMinResponseTime()), min,
                link + linkConsProv1.getConsumerId());
    }

    final CategoryItemRenderer renderer2 = new LineAndShapeRenderer();
    plot.setDataset(1, dataset2);
    plot.setRenderer(1, renderer2);

    // create the third dataset and renderer... 
    final ValueAxis rangeAxis2 = new NumberAxis("value (ms)");
    plot.setRangeAxis(1, rangeAxis2);

    DefaultCategoryDataset dataset3 = new DefaultCategoryDataset();

    for (LinkConsumerProvider linkConsProv1 : linkConsProv) {
        dataset3.addValue(Integer.parseInt(result.getTotalResult().getResponseTime().getMaxResponseTime()), max,
                link + linkConsProv1.getConsumerId());
    }

    plot.setDataset(2, dataset3);
    final CategoryItemRenderer renderer3 = new LineAndShapeRenderer();
    plot.setRenderer(2, renderer3);
    plot.mapDatasetToRangeAxis(2, 1);
    // change the rendering order so the primary dataset appears "behind" the 
    // other datasets...
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    final JFreeChart chart = new JFreeChart(plot);
    chart.setTitle("Response Time Chart");
    //  chart.setLegend(new StandardLegend());

    // add the chart to a panel...
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(chartPanel);

}