Example usage for java.text NumberFormat getPercentInstance

List of usage examples for java.text NumberFormat getPercentInstance

Introduction

In this page you can find the example usage for java.text NumberFormat getPercentInstance.

Prototype

public static final NumberFormat getPercentInstance() 

Source Link

Document

Returns a percentage format for the current default java.util.Locale.Category#FORMAT FORMAT locale.

Usage

From source file:org.codehaus.mojo.dashboard.report.plugin.chart.time.CoberturaTimeChartStrategy.java

public NumberAxis getRangeAxis() {
    NumberAxis valueaxis = new NumberAxis();
    valueaxis.setLowerMargin(0.0D);/* w ww .j a  va2  s  . com*/
    valueaxis.setUpperMargin(0.099D);
    valueaxis.setRangeWithMargins(0.0D, 1.0D);
    valueaxis.setLabel(this.getYAxisLabel());
    valueaxis.setNumberFormatOverride(NumberFormat.getPercentInstance());
    return valueaxis;
}

From source file:org.codehaus.mojo.dashboard.report.plugin.chart.BarChartRenderer.java

public void createChart() {
    CategoryDataset categorydataset = (CategoryDataset) this.datasetStrategy.getDataset();
    report = ChartFactory.createBarChart(this.datasetStrategy.getTitle(), this.datasetStrategy.getYAxisLabel(),
            this.datasetStrategy.getXAxisLabel(), categorydataset, PlotOrientation.HORIZONTAL, true, true,
            false);/*from  w  w w  .j av  a2  s .c  om*/
    // report.setBackgroundPaint( Color.lightGray );
    report.setPadding(new RectangleInsets(5.0d, 5.0d, 5.0d, 5.0d));
    CategoryPlot categoryplot = (CategoryPlot) report.getPlot();
    categoryplot.setBackgroundPaint(Color.white);
    categoryplot.setRangeGridlinePaint(Color.lightGray);
    categoryplot.setDomainGridlinePaint(Color.lightGray);
    categoryplot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    if (datasetStrategy instanceof CoberturaBarChartStrategy
            || datasetStrategy instanceof CloverBarChartStrategy
            || datasetStrategy instanceof MultiCloverBarChartStrategy) {
        numberaxis.setRange(0.0D, BarChartRenderer.NUMBER_AXIS_RANGE);
        numberaxis.setNumberFormatOverride(NumberFormat.getPercentInstance());
    } else {
        numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    }
    numberaxis.setLowerMargin(0.0D);
    CategoryAxis axis = categoryplot.getDomainAxis();
    axis.setLowerMargin(0.02); // two percent
    axis.setCategoryMargin(0.10); // ten percent
    axis.setUpperMargin(0.02); // two percent
    BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer();
    barrenderer.setItemMargin(0.10);
    barrenderer.setDrawBarOutline(false);
    barrenderer.setBaseItemLabelsVisible(true);
    if (datasetStrategy instanceof CoberturaBarChartStrategy
            || datasetStrategy instanceof CloverBarChartStrategy
            || datasetStrategy instanceof MultiCloverBarChartStrategy) {
        barrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}",
                NumberFormat.getPercentInstance(Locale.getDefault())));
    } else {
        barrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    }

    int height = (categorydataset.getColumnCount() * ChartUtils.STANDARD_BARCHART_ENTRY_HEIGHT
            * categorydataset.getRowCount());
    if (height > ChartUtils.MINIMUM_HEIGHT) {
        super.setHeight(height);
    } else {
        super.setHeight(ChartUtils.MINIMUM_HEIGHT);
    }

    Paint[] paints = this.datasetStrategy.getPaintColor();

    for (int i = 0; i < categorydataset.getRowCount() && i < paints.length; i++) {
        barrenderer.setSeriesPaint(i, paints[i]);
    }

}

From source file:org.codehaus.mojo.dashboard.report.plugin.chart.StackedBarChartRenderer.java

/**
 * //from   w w w . j av  a 2  s.c  o m
 */
public void createChart() {

    CategoryDataset categorydataset = (CategoryDataset) this.datasetStrategy.getDataset();
    report = ChartFactory.createStackedBarChart(this.datasetStrategy.getTitle(),
            this.datasetStrategy.getYAxisLabel(), this.datasetStrategy.getXAxisLabel(), categorydataset,
            PlotOrientation.HORIZONTAL, true, true, false);
    // report.setBackgroundPaint( Color.lightGray );
    report.setAntiAlias(false);
    report.setPadding(new RectangleInsets(5.0d, 5.0d, 5.0d, 5.0d));
    CategoryPlot categoryplot = (CategoryPlot) report.getPlot();
    categoryplot.setBackgroundPaint(Color.white);
    categoryplot.setRangeGridlinePaint(Color.lightGray);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    if (datasetStrategy instanceof CloverBarChartStrategy
            || datasetStrategy instanceof MultiCloverBarChartStrategy) {
        numberaxis.setRange(0.0D, StackedBarChartRenderer.NUMBER_AXIS_RANGE);
        numberaxis.setNumberFormatOverride(NumberFormat.getPercentInstance());
    } else {
        numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    }
    numberaxis.setLowerMargin(0.0D);
    StackedBarRenderer stackedbarrenderer = (StackedBarRenderer) categoryplot.getRenderer();
    stackedbarrenderer.setDrawBarOutline(false);
    stackedbarrenderer.setBaseItemLabelsVisible(true);
    stackedbarrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    stackedbarrenderer.setBaseItemLabelFont(StackedBarRenderer.DEFAULT_VALUE_LABEL_FONT.deriveFont(Font.BOLD));
    int height = (categorydataset.getColumnCount() * ChartUtils.STANDARD_BARCHART_ENTRY_HEIGHT * 2)
            + ChartUtils.STANDARD_BARCHART_ADDITIONAL_HEIGHT + 10;
    if (height > ChartUtils.MINIMUM_HEIGHT) {
        super.setHeight(height);
    } else {
        super.setHeight(ChartUtils.MINIMUM_HEIGHT);
    }
    Paint[] paints = this.datasetStrategy.getPaintColor();

    for (int i = 0; i < categorydataset.getRowCount() && i < paints.length; i++) {
        stackedbarrenderer.setSeriesPaint(i, paints[i]);
    }

}

From source file:com.lzy.demo.okrx2.RxFileDownloadActivity.java

@Override
protected void onActivityCreate(Bundle savedInstanceState) {
    setContentView(R.layout.activity_rx_file_download);
    ButterKnife.bind(this);
    setTitle("");

    numberFormat = NumberFormat.getPercentInstance();
    numberFormat.setMinimumFractionDigits(2);

    checkSDCardPermission();//from  w  w w. jav  a 2  s  . co m
}

From source file:info.mikaelsvensson.devtools.analysis.db2eventlog.Db2EventLogReportGenerator.java

private static void printQueryData(List<QueryStatistics> data, PrintStream stream) {
    stream.format(LINE_FORMAT, "Samples", "Time", "Time", "Rows Read", "Rows Written", "Fetch Count", "Sorts",
            "Timing Details", "Query Id", "Query String");
    stream.format(LINE_FORMAT, "-------", "----", "----", "---------", "------------", "-----------", "-----",
            "--------------", "--------", "------------");
    long overallTime = 0;
    Date lastTimeStamp = null;/*from  w w w .  j  av  a2 s  .c om*/
    Date firstTimeStamp = null;
    for (QueryStatistics queryStatistics : data) {
        overallTime += queryStatistics.getAccumulatedExecutionTime();
        if (lastTimeStamp == null || queryStatistics.getLastTimeStamp().after(lastTimeStamp)) {
            lastTimeStamp = queryStatistics.getLastTimeStamp();
        }
        if (firstTimeStamp == null || queryStatistics.getFirstTimeStamp().before(firstTimeStamp)) {
            firstTimeStamp = queryStatistics.getFirstTimeStamp();
        }
    }
    int overallSamples = 0;
    for (QueryStatistics queryStatistics : data) {
        long time = queryStatistics.getAccumulatedExecutionTime();
        final int sampleCount = queryStatistics.getTotalSamples();
        final int numberOfOperations = queryStatistics.getOperationsTime().size();
        if (sampleCount % numberOfOperations != 0) {
            System.err.println(
                    "Number of samples is not divisible by the number of different operations (see the Timing Details column). Problematic query: "
                            + queryStatistics.getQuery());
        }
        final int correctedSampleCount = sampleCount / numberOfOperations;
        overallSamples += correctedSampleCount;
        stream.format(LINE_FORMAT, correctedSampleCount, toDisplayTime(time),
                NumberFormat.getPercentInstance().format(1.0 * time / overallTime),
                queryStatistics.getRowsRead(), queryStatistics.getRowsWritten(),
                queryStatistics.getFetchCount(), queryStatistics.getSorts(),
                toString(queryStatistics.getOperationsTime()), queryStatistics.getId(),
                queryStatistics.getQuery());
    }
    stream.format(LINE_FORMAT, "-------", "----", "----", "---------", "------------", "-----------", "-----",
            "--------------", "--------", "------------");
    stream.format("%10d %10s%n", overallSamples, toDisplayTime(overallTime));
    stream.println();
    stream.format("Accumulated execution time according to Elapsed Execution Time values: %s%n",
            toDisplayTime(overallTime));
    stream.format("Period of time when logging was enabled according to time stamps:      %s%n",
            toDisplayTime((lastTimeStamp.getTime() - firstTimeStamp.getTime()) * 1000));
}

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

/**
 * Default constructor./* w  ww . j  a  va  2 s. c o m*/
 *
 * @param title  the frame title.
 */
public XMLPieChartDemo(final String title) {

    super(title);

    // create a dataset...
    PieDataset dataset = null;
    final URL url = getClass().getResource("/org/jfree/chart/demo/piedata.xml");

    try {
        final InputStream in = url.openStream();
        dataset = DatasetReader.readPieDatasetFromXML(in);
    } catch (IOException ioe) {
        System.out.println(ioe.getMessage());
    }

    // create the chart...
    final JFreeChart chart = ChartFactory.createPieChart("Pie Chart Demo 1", // chart title
            dataset, // data
            true, // include legend
            true, false);

    // set the background color for the chart...
    chart.setBackgroundPaint(Color.yellow);
    final PiePlot plot = (PiePlot) chart.getPlot();
    plot.setLabelGenerator(new StandardPieItemLabelGenerator("{0} = {2}", NumberFormat.getNumberInstance(),
            NumberFormat.getPercentInstance()));
    plot.setNoDataMessage("No data available");

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

}

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

/**
 * Default constructor./*  ww w  .j a v  a 2s  .  c o  m*/
 *
 * @param title  the frame title.
 */
public PieChartDemo4(final String title) {

    super(title);
    final PieDataset dataset = createDataset(14);

    // create the chart...
    final JFreeChart chart = ChartFactory.createPieChart("Pie Chart Demo 4", // chart title
            dataset, // dataset
            false, // include legend
            true, false);

    // set the background color for the chart...
    chart.setBackgroundPaint(new Color(222, 222, 255));
    final PiePlot plot = (PiePlot) chart.getPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setCircular(true);
    plot.setLabelGenerator(new StandardPieItemLabelGenerator("{0} = {2}", NumberFormat.getNumberInstance(),
            NumberFormat.getPercentInstance()));
    plot.setNoDataMessage("No data available");

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

    final Rotator rotator = new Rotator(plot);
    rotator.start();

}

From source file:org.codehaus.mojo.dashboard.report.plugin.chart.time.CloverTimeChartStrategy.java

/**
 * /*w ww .j  a  va 2s.c o  m*/
 */
public NumberAxis getRangeAxis() {
    NumberAxis valueaxis = new NumberAxis();
    valueaxis.setLowerMargin(0.0D);
    valueaxis.setUpperMargin(0.05D);
    valueaxis.setRangeWithMargins(0.0D, 1.0D);
    valueaxis.setLabel(this.getYAxisLabel());
    valueaxis.setNumberFormatOverride(NumberFormat.getPercentInstance());
    return valueaxis;
}

From source file:cn.edu.thss.iise.bpmdemo.charts.PieChartDemo4.java

/**
 * Default constructor.//ww  w . ja  v a2s .co m
 *
 * @param title
 *            the frame title.
 */
public PieChartDemo4(final String title) {

    super(title);
    final PieDataset dataset = createDataset(14);

    // create the chart...
    final JFreeChart chart = ChartFactory.createPieChart("Pie Chart Demo 4", // chart title
            dataset, // dataset
            false, // include legend
            true, false);

    // set the background color for the chart...
    chart.setBackgroundPaint(new Color(222, 222, 255));

    final PiePlot plot = (PiePlot) chart.getPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setCircular(true);
    plot.setLabelGenerator(new StandardPieItemLabelGenerator("{0} = {2}", NumberFormat.getNumberInstance(),
            NumberFormat.getPercentInstance()));
    plot.setNoDataMessage("No data available");

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

    // add table
    Object[][] data = { { "Kathy0", new Integer(0) }, { "Kathy1", new Integer(2) },
            { "Kathy2", new Integer(5) }, { "Kathy3", new Integer(5) }, { "Kathy4", new Integer(5) },
            { "Kathy5", new Integer(5) }, { "Kathy6", new Integer(5) }, { "Kathy7", new Integer(5) },
            { "Kathy8", new Integer(5) }, { "Kathy9", new Integer(5) } };
    String[] columnNames = { "Model Name", "Reuse Number" };
    JTable table = new JTable(data, columnNames);
    final JPanel panel = new JPanel();
    panel.add(chartPanel);
    panel.add(table);
    setContentPane(panel);
    final Rotator rotator = new Rotator(plot);
    rotator.start();

}

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

private static JFreeChart createChart(CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createBarChart3D("Student Grades", "Students", "Grade",
            categorydataset, PlotOrientation.VERTICAL, false, true, false);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    CustomBarRenderer3D custombarrenderer3d = new CustomBarRenderer3D();
    custombarrenderer3d.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    custombarrenderer3d.setBaseItemLabelsVisible(true);
    custombarrenderer3d.setItemLabelAnchorOffset(10D);
    custombarrenderer3d.setBasePositiveItemLabelPosition(
            new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));
    categoryplot.setRenderer(custombarrenderer3d);
    ValueMarker valuemarker = new ValueMarker(0.69999999999999996D, new Color(200, 200, 255),
            new BasicStroke(1.0F), new Color(200, 200, 255), new BasicStroke(1.0F), 1.0F);
    categoryplot.addRangeMarker(valuemarker, Layer.BACKGROUND);
    custombarrenderer3d.setBaseItemLabelsVisible(true);
    custombarrenderer3d.setMaximumBarWidth(0.050000000000000003D);
    CategoryTextAnnotation categorytextannotation = new CategoryTextAnnotation("Minimum grade to pass",
            "Robert", 0.70999999999999996D);
    categorytextannotation.setCategoryAnchor(CategoryAnchor.START);
    categorytextannotation.setFont(new Font("SansSerif", 0, 12));
    categorytextannotation.setTextAnchor(TextAnchor.BOTTOM_LEFT);
    categoryplot.addAnnotation(categorytextannotation);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setNumberFormatOverride(NumberFormat.getPercentInstance());
    numberaxis.setUpperMargin(0.10000000000000001D);
    return jfreechart;
}