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

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

Introduction

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

Prototype

public void setNumberFormatOverride(NumberFormat formatter) 

Source Link

Document

Sets the number format override.

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   www .  ja va  2  s.  c o 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:edu.psu.citeseerx.misc.charts.CiteChartBuilderJFree.java

protected JFreeChart buildChart(Document doc) throws SQLException {

    Long clusterid = doc.getClusterID();
    if (clusterid == null) {
        return null;
    }// w w w.jav  a  2  s  .co m

    java.util.List<ThinDoc> citingDocs = citedao.getCitingDocuments(clusterid, 0, MAX_CITING);
    XYDataset dataset = collectData(citingDocs);
    if (dataset.getItemCount(0) <= 1) {
        return null;
    }

    XYBarDataset ivl_dataset = new XYBarDataset(dataset, 15.0);
    JFreeChart chart = ChartFactory.createXYBarChart(null, "Year", true, "Citation Count", ivl_dataset,
            PlotOrientation.VERTICAL, false, false, false);
    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));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    XYItemRenderer r = plot.getRenderer();

    NumberAxis axis = (NumberAxis) plot.getDomainAxis();
    axis.setNumberFormatOverride(NumberFormat.getIntegerInstance());
    //axis.setTickUnit(new DateTickUnit(DateTickUnit.YEAR, -1));
    //axis.setDateFormatOverride(new SimpleDateFormat("yyyy"));
    return chart;

}

From source file:org.sonar.server.charts.jruby.TrendsChart.java

public void initSerie(Long serieId, String legend, boolean isPercent) {
    TimeSeries series = new TimeSeries(legend);

    int index = seriesById.size();
    seriesById.put(serieId, series);/*from   w  w w .  ja  va  2  s. co m*/

    TimeSeriesCollection timeSeriesColl = new TimeSeriesCollection();
    timeSeriesColl.addSeries(series);
    plot.setDataset(index, timeSeriesColl);

    if (isPercent) {
        if (percentAxisId == -1) {
            NumberAxis rangeAxis = new NumberAxis();
            rangeAxis.setNumberFormatOverride(new DecimalFormat("0'%'"));
            rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
            rangeAxis.setUpperBound(100.0);
            rangeAxis.setLowerBound(0.0);
            plot.setRangeAxisLocation(index, AxisLocation.TOP_OR_LEFT);
            plot.setRangeAxis(index, rangeAxis);
            plot.mapDatasetToRangeAxis(index, index);
            percentAxisId = index;

        } else {
            plot.mapDatasetToRangeAxis(index, percentAxisId);
        }
    } else {
        NumberAxis rangeAxis = new NumberAxis(displayLegend ? legend : null);
        rangeAxis.setAutoRangeIncludesZero(false);
        rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        rangeAxis.setAutoRangeMinimumSize(2.0);
        plot.setRangeAxisLocation(index, AxisLocation.TOP_OR_RIGHT);
        plot.setRangeAxis(index, rangeAxis);
        plot.mapDatasetToRangeAxis(index, index);
    }

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setBaseShapesVisible(false);
    renderer.setSeriesStroke(0, new BasicStroke(2.0f));
    renderer.setSeriesPaint(0, COLORS[index % COLORS.length]);
    plot.setRenderer(index, renderer);
}

From source file:org.optaplanner.benchmark.impl.statistic.movecountperstep.MoveCountPerStepProblemStatistic.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("Accepted/selected moves per step");
    yAxis.setNumberFormatOverride(NumberFormat.getInstance(locale));
    XYPlot plot = new XYPlot(null, xAxis, yAxis, null);
    DrawingSupplier drawingSupplier = new DefaultDrawingSupplier();
    plot.setOrientation(PlotOrientation.VERTICAL);

    int seriesIndex = 0;
    for (SingleBenchmarkResult singleBenchmarkResult : problemBenchmarkResult.getSingleBenchmarkResultList()) {
        XYSeries acceptedSeries = new XYSeries(
                singleBenchmarkResult.getSolverBenchmarkResult().getNameWithFavoriteSuffix() + " accepted");
        XYSeries selectedSeries = new XYSeries(
                singleBenchmarkResult.getSolverBenchmarkResult().getNameWithFavoriteSuffix() + " selected");
        XYItemRenderer renderer = new XYLineAndShapeRenderer(true, false);
        if (singleBenchmarkResult.isSuccess()) {
            MoveCountPerStepSingleStatistic singleStatistic = (MoveCountPerStepSingleStatistic) singleBenchmarkResult
                    .getSingleStatistic(problemStatisticType);
            for (MoveCountPerStepStatisticPoint point : singleStatistic.getPointList()) {
                long timeMillisSpent = point.getTimeMillisSpent();
                long acceptedMoveCount = point.getMoveCountPerStepMeasurement().getAcceptedMoveCount();
                long selectedMoveCount = point.getMoveCountPerStepMeasurement().getSelectedMoveCount();
                acceptedSeries.add(timeMillisSpent, acceptedMoveCount);
                selectedSeries.add(timeMillisSpent, selectedMoveCount);
            }/*from  w  w w.j a v a 2  s.co m*/
        }
        XYSeriesCollection seriesCollection = new XYSeriesCollection();
        seriesCollection.addSeries(acceptedSeries);
        seriesCollection.addSeries(selectedSeries);
        plot.setDataset(seriesIndex, seriesCollection);

        if (singleBenchmarkResult.getSolverBenchmarkResult().isFavorite()) {
            // Make the favorite more obvious
            renderer.setSeriesStroke(0, new BasicStroke(2.0f));
            // Dashed line for selected move count
            renderer.setSeriesStroke(1, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
                    1.0f, new float[] { 2.0f, 6.0f }, 0.0f));
        } else {
            // Dashed line for selected move count
            renderer.setSeriesStroke(1, new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
                    1.0f, new float[] { 2.0f, 6.0f }, 0.0f));
        }
        // Render both lines in the same color
        Paint linePaint = drawingSupplier.getNextPaint();
        renderer.setSeriesPaint(0, linePaint);
        renderer.setSeriesPaint(1, linePaint);
        plot.setRenderer(seriesIndex, renderer);
        seriesIndex++;
    }

    JFreeChart chart = new JFreeChart(problemBenchmarkResult.getName() + " move count per step statistic",
            JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    graphFile = writeChartToImageFile(chart, problemBenchmarkResult.getName() + "MoveCountPerStepStatistic");
}

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

/**
 * Creates a new demo instance./*  w  w  w.j a v  a  2 s.c o  m*/
 *
 * @param title  the frame title.
 */
public ParetoChartDemo(final String title) {

    super(title);

    final DefaultKeyedValues data = new DefaultKeyedValues();
    data.addValue("C", new Integer(4843));
    data.addValue("C++", new Integer(2098));
    data.addValue("C#", new Integer(26));
    data.addValue("Java", new Integer(1901));
    data.addValue("Perl", new Integer(2507));
    data.addValue("PHP", new Integer(1689));
    data.addValue("Python", new Integer(948));
    data.addValue("Ruby", new Integer(100));
    data.addValue("SQL", new Integer(263));
    data.addValue("Unix Shell", new Integer(485));

    data.sortByValues(SortOrder.DESCENDING);
    final KeyedValues cumulative = DataUtilities.getCumulativePercentages(data);
    final CategoryDataset dataset = DatasetUtilities.createCategoryDataset("Languages", data);

    // create the chart...
    final JFreeChart chart = ChartFactory.createBarChart("Freshmeat Software Projects", // chart title
            "Language", // domain axis label
            "Projects", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, false);

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.addSubtitle(new TextTitle("By Programming Language"));
    chart.addSubtitle(new TextTitle("As at 5 March 2003"));

    // set the background color for the chart...
    chart.setBackgroundPaint(new Color(0xBBBBDD));

    // get a reference to the plot for further customisation...
    final CategoryPlot plot = chart.getCategoryPlot();

    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setLowerMargin(0.02);
    domainAxis.setUpperMargin(0.02);

    // set the range axis to display integers only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    final LineAndShapeRenderer renderer2 = new LineAndShapeRenderer();

    final CategoryDataset dataset2 = DatasetUtilities.createCategoryDataset("Cumulative", cumulative);
    final NumberAxis axis2 = new NumberAxis("Percent");
    axis2.setNumberFormatOverride(NumberFormat.getPercentInstance());
    plot.setRangeAxis(1, axis2);
    plot.setDataset(1, dataset2);
    plot.setRenderer(1, renderer2);
    plot.mapDatasetToRangeAxis(1, 1);

    plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE);
    // OPTIONAL CUSTOMISATION COMPLETED.

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

}

From source file:it.eng.spagobi.engines.chart.bo.charttypes.others.CumulativeCurveChart.java

public JFreeChart createChart(DatasetMap datasetMap) {
    CategoryDataset datasetValue = (CategoryDataset) datasetMap.getDatasets().get("1");
    CategoryDataset datasetCumulative = (CategoryDataset) datasetMap.getDatasets().get("2");

    JFreeChart chart = ChartFactory.createBarChart(name, // chart title
            xLabel, // domain axis label
            yLabel, // range axis label
            datasetValue, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, false);/*w  w w. j a va2  s.  c o  m*/

    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.white);
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setLowerMargin(0.02);
    domainAxis.setUpperMargin(0.02);
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    // set the range axis to display integers only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    LineAndShapeRenderer renderer2 = new LineAndShapeRenderer();

    NumberAxis axis2 = new NumberAxis("Percent");
    axis2.setNumberFormatOverride(NumberFormat.getPercentInstance());
    plot.setRangeAxis(1, axis2);
    plot.setDataset(1, datasetCumulative);
    plot.setRenderer(1, renderer2);
    plot.mapDatasetToRangeAxis(1, 1);

    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    return chart;
}

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

protected void writeGraphStatistic() {
    NumberAxis xAxis = new NumberAxis("Time 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 (SingleBenchmark singleBenchmark : problemBenchmark.getSingleBenchmarkList()) {
        BestScoreSingleStatistic singleStatistic = (BestScoreSingleStatistic) singleBenchmark
                .getSingleStatistic(problemStatisticType);
        XYSeries series = new XYSeries(singleBenchmark.getSolverBenchmark().getName());
        for (BestScoreSingleStatisticPoint point : singleStatistic.getPointList()) {
            long timeMillisSpend = point.getTimeMillisSpend();
            Score score = point.getScore();
            Double scoreGraphValue = scoreDefinition.translateScoreToGraphValue(score);
            if (scoreGraphValue != null) {
                series.add(timeMillisSpend, scoreGraphValue);
            }/*ww w. java2  s. c  o m*/
        }
        XYSeriesCollection seriesCollection = new XYSeriesCollection();
        seriesCollection.addSeries(series);
        plot.setDataset(seriesIndex, seriesCollection);
        XYItemRenderer renderer;
        // No direct lines between 2 points
        renderer = new XYStepRenderer();
        if (singleStatistic.getPointList().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(problemBenchmark.getName() + " best score statistic",
            JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    BufferedImage chartImage = chart.createBufferedImage(1024, 768);
    graphStatisticFile = new File(problemBenchmark.getProblemReportDirectory(),
            problemBenchmark.getName() + "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);
    }
}

From source file:org.optaplanner.benchmark.impl.statistic.single.pickedmovetypestepscore.PickedMoveTypeStepScoreDiffSingleStatistic.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 diff level " + scoreLevelIndex);
    yAxis.setNumberFormatOverride(NumberFormat.getInstance(locale));
    yAxis.setAutoRangeIncludesZero(true);
    XYPlot plot = new XYPlot(null, xAxis, yAxis, null);
    plot.setOrientation(PlotOrientation.VERTICAL);
    return plot;/*from w  ww  . jav  a  2  s .  c  o  m*/
}

From source file:org.optaplanner.benchmark.impl.statistic.single.pickedmovetypebestscore.PickedMoveTypeBestScoreDiffSingleStatistic.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("Best score diff level " + scoreLevelIndex);
    yAxis.setNumberFormatOverride(NumberFormat.getInstance(locale));
    yAxis.setAutoRangeIncludesZero(true);
    XYPlot plot = new XYPlot(null, xAxis, yAxis, null);
    plot.setOrientation(PlotOrientation.VERTICAL);
    return plot;//from w  w w .  ja va 2s  .c  o  m
}

From source file:net.sf.mzmine.modules.peaklistmethods.dataanalysis.rtmzplots.RTMZPlot.java

public RTMZPlot(RTMZAnalyzerWindow masterFrame, AbstractXYZDataset dataset,
        InterpolatingLookupPaintScale paintScale) {
    super(null);//from  w  w  w .  jav a 2s  .co  m

    this.paintScale = paintScale;

    chart = ChartFactory.createXYAreaChart("", "Retention time", "m/z", dataset, PlotOrientation.VERTICAL,
            false, false, false);
    chart.setBackgroundPaint(Color.white);
    setChart(chart);

    // title

    TextTitle chartTitle = chart.getTitle();
    chartTitle.setMargin(5, 0, 0, 0);
    chartTitle.setFont(titleFont);
    chart.removeSubtitle(chartTitle);

    // disable maximum size (we don't want scaling)
    setMaximumDrawWidth(Integer.MAX_VALUE);
    setMaximumDrawHeight(Integer.MAX_VALUE);

    // set the plot properties
    plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));

    // set grid properties
    plot.setDomainGridlinePaint(gridColor);
    plot.setRangeGridlinePaint(gridColor);

    // set crosshair (selection) properties
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    plot.setDomainCrosshairPaint(crossHairColor);
    plot.setRangeCrosshairPaint(crossHairColor);
    plot.setDomainCrosshairStroke(crossHairStroke);
    plot.setRangeCrosshairStroke(crossHairStroke);

    NumberFormat rtFormat = MZmineCore.getConfiguration().getRTFormat();
    NumberFormat mzFormat = MZmineCore.getConfiguration().getMZFormat();

    // set the X axis (retention time) properties
    NumberAxis xAxis = (NumberAxis) plot.getDomainAxis();
    xAxis.setNumberFormatOverride(rtFormat);
    xAxis.setUpperMargin(0.001);
    xAxis.setLowerMargin(0.001);

    // set the Y axis (intensity) properties
    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setAutoRangeIncludesZero(false);
    yAxis.setNumberFormatOverride(mzFormat);

    plot.setDataset(dataset);
    spotRenderer = new RTMZRenderer(dataset, paintScale);
    plot.setRenderer(spotRenderer);
    spotRenderer.setBaseToolTipGenerator(new RTMZToolTipGenerator());

    // Add a paintScaleLegend to chart

    paintScaleAxis = new NumberAxis("Logratio");
    paintScaleAxis.setRange(paintScale.getLowerBound(), paintScale.getUpperBound());

    paintScaleLegend = new PaintScaleLegend(paintScale, paintScaleAxis);
    paintScaleLegend.setPosition(plot.getDomainAxisEdge());
    paintScaleLegend.setMargin(5, 25, 5, 25);

    chart.addSubtitle(paintScaleLegend);

}