List of usage examples for java.text NumberFormat getPercentInstance
public static final NumberFormat getPercentInstance()
From source file:StringUtil.java
/** * Takes a double and turns it into a percent string. * Ex. 0.5 turns into 50%/* w w w .j a v a 2 s .com*/ * * @param value * @return corresponding percent string */ public static String getPercentValue(double value) { //moved from HTMLReport.getPercentValue() value = Math.floor(value * 100) / 100; //to represent 199 covered lines from 200 as 99% covered, not 100 % return NumberFormat.getPercentInstance().format(value); }
From source file:org.jfree.chart.demo.StackedBarChartDemo7.java
private static JFreeChart createChart(CategoryDataset categorydataset) { JFreeChart jfreechart = ChartFactory.createStackedBarChart("Stacked Bar Chart Demo 7", "Category", "Value", categorydataset, PlotOrientation.VERTICAL, true, true, false); jfreechart.setBackgroundPaint(Color.white); CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); categoryplot.setBackgroundPaint(Color.lightGray); categoryplot.setRangeGridlinePaint(Color.white); NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); numberaxis.setNumberFormatOverride(NumberFormat.getPercentInstance()); StackedBarRenderer stackedbarrenderer = (StackedBarRenderer) categoryplot.getRenderer(); stackedbarrenderer.setRenderAsPercentages(true); stackedbarrenderer.setDrawBarOutline(false); stackedbarrenderer.setBaseItemLabelsVisible(true); stackedbarrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); return jfreechart; }
From source file:org.oscarehr.common.model.ReportStatistic.java
public String getPercent() { NumberFormat percentInstance = NumberFormat.getPercentInstance(); percentInstance.setMinimumFractionDigits(0); percentInstance.setMaximumFractionDigits(2); return percentInstance.format(fraction.floatValue()); }
From source file:utils.Graphs.java
public static File generate(File baseFolder, String titles[], int[] values, Color backgroundColor) { DefaultPieDataset dataset = new DefaultPieDataset(); // add our data values int i = -1;//from ww w. j a v a 2s. c o m for (String title : titles) { i++; dataset.setValue(title, values[i]); } final JFreeChart chart = // ChartFactory.createPieChart("", dataset, true, true, false); ChartFactory.createPieChart("", // chart title dataset, // data true, // include legend true, false); PiePlot plot = (PiePlot) chart.getPlot(); //PiePlot3D plot = (PiePlot3D) chart.getPlot(); //plot.setStartAngle(290); plot.setStartAngle(45); plot.setDirection(Rotation.CLOCKWISE); plot.setForegroundAlpha(0.5f); // final PiePlot plot = (PiePlot) chart.getPlot(); plot.setBackgroundPaint(backgroundColor); // plot.setLegendLabelGenerator( // new StandardPieSectionLabelGenerator("{0} {2}")); chart.setBorderVisible(false); chart.getPlot().setOutlineVisible(false); chart.getLegend().setFrame(BlockBorder.NONE); // get the same background chart.setBackgroundPaint(backgroundColor); chart.getLegend().setBackgroundPaint(backgroundColor); // hide the shadow effects plot.setShadowXOffset(0); plot.setShadowYOffset(0); //chart.getLegend().setVisible(false); plot.setCircular(true); //plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} {2}", NumberFormat.getNumberInstance(), NumberFormat plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{2}", NumberFormat.getNumberInstance(), NumberFormat.getPercentInstance())); plot.setNoDataMessage("No data found."); Color greenColor = new Color(0x8FBC0C); Color redColor = new Color(0xFF0000); //Color redColor = new Color(0xDA6022); plot.setSectionPaint(0, greenColor); plot.setSectionPaint(1, redColor); plot.setSectionOutlinesVisible(true); final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); final File file = new File(baseFolder, "chart.png"); try { ChartUtilities.saveChartAsPNG(file, chart, 200, 160, info); } catch (IOException ex) { Logger.getLogger(Graphs.class.getName()).log(Level.SEVERE, null, ex); } // //// final ChartPanel chartPanel = new ChartPanel(chart, true); // final ChartPanel chartPanel = new ChartPanel(chart, true); // chartPanel.setMinimumDrawWidth(0); // chartPanel.setMaximumDrawWidth(Integer.MAX_VALUE); // chartPanel.setMinimumDrawHeight(0); // chartPanel.setMaximumDrawHeight(Integer.MAX_VALUE); // JDialog dialog = new JDialog(); // dialog.add(chartPanel); // dialog.setLayout(new GridLayout(1, 1)); // dialog.setSize(400, 200); // dialog.setVisible(true); return file; }
From source file:org.pentaho.chart.plugin.jfreechart.chart.bar.JFreeStacked100PercentBarChartGenerator.java
/** * Creates stacked 100 percent bar chart and creates range axis for it. * </p>//w w w .j a va 2 s . c o m * @param chartDocContext Current chart's document context. * @param data Current chart data. * @return Returns JFree stacked 100 percent bar chart. */ public JFreeChart createChart(final ChartDocumentContext chartDocContext, final ChartTableModel data) { final JFreeChart chart = super.createChart(chartDocContext, data); /* * Doing all the render stuff and then off to create range axis. * NOTE: The chart object will be updated. */ ((StackedBarRenderer) chart.getCategoryPlot().getRenderer()).setRenderAsPercentages(true); final NumberAxis rangeAxis = (NumberAxis) chart.getCategoryPlot().getRangeAxis(); rangeAxis.setNumberFormatOverride(NumberFormat.getPercentInstance()); createRangeAxis(chartDocContext, data, chart); return chart; }
From source file:org.sonar.plugins.ral.GaugeChart.java
@Override protected Plot getPlot(ChartParameters params) { ThermometerPlot plot = new ThermometerPlot(createDataset(params)); plot.setGap(1);/* ww w.j a v a2 s .c o m*/ plot.setRange(0, 1); plot.setSubrange(0, 0, 1); plot.setSubrangePaint(0, Color.decode("#ffffff")); plot.setSubrangePaint(1, Color.decode("#ffffff")); plot.setSubrangePaint(2, Color.decode("#ffffff")); plot.setMercuryPaint(Color.decode("#dddddd")); plot.setThermometerPaint(Color.decode("#aaaaaa")); plot.setValuePaint(Color.decode("#333333")); plot.setUseSubrangePaint(false); plot.setUnits(ThermometerPlot.UNITS_NONE); plot.setBulbRadius(15); plot.setColumnRadius(6); NumberAxis axis = new NumberAxis(); axis.setNumberFormatOverride(NumberFormat.getPercentInstance()); plot.setRangeAxis(axis); plot.setValueLocation(ThermometerPlot.NONE); return plot; }
From source file:org.opencastproject.videosegmenter.impl.jmf.ImageComparator.java
/** * Creates a new image comparator that will use <code>changesThreshold</code> as the threshold to decide whether two * images are different.// w w w. j a v a 2 s . co m * <p> * <b>Note:</b> turning on statistics will make the algorithm slightly less efficient. * * @param changesThreshold * the number of changes in percent that will make two images different */ public ImageComparator(float changesThreshold) { this.changesThreshold = changesThreshold; percentageNf = NumberFormat.getPercentInstance(); percentageNf.setMaximumFractionDigits(2); }
From source file:com.lzy.demo.okgo.SimpleDownloadActivity.java
@Override protected void onActivityCreate(Bundle savedInstanceState) { setContentView(R.layout.activity_file_download); ButterKnife.bind(this); setTitle("?"); numberFormat = NumberFormat.getPercentInstance(); numberFormat.setMinimumFractionDigits(2); checkSDCardPermission();// w w w.j a v a 2 s .c o m }
From source file:de.alpharogroup.wicket.js.addon.core.PercentNumberFormatTextValue.java
/** * Instantiates a new {@link PercentNumberFormatTextValue} object. * * @param name//from w w w .java2 s . co m * the name * @param value * the value */ public PercentNumberFormatTextValue(final String name, final Integer value) { super(name, NumberFormat.getPercentInstance().format((double) checkQuietly(name, value) / 100), StringTextType.STRING_INTEGER); }
From source file:org.rhq.enterprise.server.rest.reporting.PlatformUtilizationHandler.java
@Override public StreamingOutput generateReport(HttpServletRequest request) { if (log.isDebugEnabled()) { log.debug("Received request to generate report for " + caller); }/*from ww w . jav a 2 s .com*/ return new StreamingOutput() { private NumberFormat numberFormat; { numberFormat = NumberFormat.getPercentInstance(); numberFormat.setMaximumFractionDigits(2); } @Override public void write(OutputStream output) throws IOException, WebApplicationException { CsvWriter<PlatformMetricsSummary> csvWriter = new CsvWriter<PlatformMetricsSummary>(); csvWriter.setColumns("resource.name", "resource.version", "CPUUsage", "memoryUsage", "swapUsage"); csvWriter.setPropertyConverter("CPUUsage", new PropertyConverter<PlatformMetricsSummary>() { @Override public Object convert(PlatformMetricsSummary summary, String propertyName) { return calculateCPUUsage(summary); } }); csvWriter.setPropertyConverter("memoryUsage", new PropertyConverter<PlatformMetricsSummary>() { @Override public Object convert(PlatformMetricsSummary summary, String propertyName) { return calculateMemoryUsage(summary); } }); csvWriter.setPropertyConverter("swapUsage", new PropertyConverter<PlatformMetricsSummary>() { @Override public Object convert(PlatformMetricsSummary summary, String propertyName) { return calculateSwapUsage(summary); } }); output.write((getHeader() + "\n").getBytes()); PageList<PlatformMetricsSummary> summaries = platformUtilizationMgr.loadPlatformMetrics(caller); for (PlatformMetricsSummary summary : summaries) { csvWriter.write(summary, output); } } private String getHeader() { return "Name,Version,CPU,Memory,Swap"; } private String calculateCPUUsage(PlatformMetricsSummary summary) { if (!summary.isMetricsAvailable()) { return "NA"; } Double systemCPU = (Double) summary.getSystemCPU().getValue(); Double userCPU = (Double) summary.getUserCPU().getValue(); return numberFormat.format((systemCPU + userCPU)); } private String calculateMemoryUsage(PlatformMetricsSummary summary) { if (!summary.isMetricsAvailable()) { return "NA"; } Double totalMemory = (Double) summary.getTotalMemory().getValue(); Double usedMemory = (Double) summary.getActualUsedMemory().getValue(); return numberFormat.format((usedMemory / totalMemory)); } private String calculateSwapUsage(PlatformMetricsSummary summary) { if (!summary.isMetricsAvailable()) { return "NA"; } Double totalSwap = (Double) summary.getTotalSwap().getValue(); Double usedSwap = (Double) summary.getUsedSwap().getValue(); return numberFormat.format((usedSwap / totalSwap)); } }; }