List of usage examples for java.text DecimalFormat setNegativeSuffix
public void setNegativeSuffix(String newValue)
From source file:Main.java
public static void main(String[] argv) throws Exception { DecimalFormat format = new DecimalFormat(); format.setNegativeSuffix("minus"); System.out.println(format.format(-123456789.12345678)); }
From source file:org.jfree.chart.demo.WaterfallChartDemo1.java
private static JFreeChart createChart(CategoryDataset categorydataset) { JFreeChart jfreechart = ChartFactory.createWaterfallChart("Product Cost Breakdown", "Expense Category", "Cost Per Unit", categorydataset, PlotOrientation.VERTICAL, false, true, false); jfreechart.setBackgroundPaint(Color.white); CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); categoryplot.setBackgroundPaint(Color.lightGray); categoryplot.setRangeGridlinePaint(Color.white); categoryplot.setRangeGridlinesVisible(true); categoryplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D)); ValueAxis valueaxis = categoryplot.getRangeAxis(); DecimalFormat decimalformat = new DecimalFormat("##,###"); decimalformat.setNegativePrefix("("); decimalformat.setNegativeSuffix(")"); TickUnits tickunits = new TickUnits(); tickunits.add(new NumberTickUnit(5D, decimalformat)); tickunits.add(new NumberTickUnit(10D, decimalformat)); tickunits.add(new NumberTickUnit(20D, decimalformat)); tickunits.add(new NumberTickUnit(50D, decimalformat)); tickunits.add(new NumberTickUnit(100D, decimalformat)); tickunits.add(new NumberTickUnit(200D, decimalformat)); tickunits.add(new NumberTickUnit(500D, decimalformat)); tickunits.add(new NumberTickUnit(1000D, decimalformat)); tickunits.add(new NumberTickUnit(2000D, decimalformat)); tickunits.add(new NumberTickUnit(5000D, decimalformat)); valueaxis.setStandardTickUnits(tickunits); BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer(); barrenderer.setDrawBarOutline(false); barrenderer.setBase(5D);/*from ww w .j av a2 s . c om*/ DecimalFormat decimalformat1 = new DecimalFormat("$##,###.00"); decimalformat1.setNegativePrefix("("); decimalformat1.setNegativeSuffix(")"); barrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}", decimalformat1)); barrenderer.setBaseItemLabelsVisible(true); return jfreechart; }
From source file:Main.java
@NonNull static String convertAmount(int amount) { DecimalFormat formatter = (DecimalFormat) NumberFormat.getCurrencyInstance(); formatter.setCurrency(Currency.getInstance("EUR")); String symbol = formatter.getCurrency().getSymbol(); formatter.setNegativePrefix(symbol + "-"); formatter.setNegativeSuffix(""); return formatter.format((double) amount / 100.0); }
From source file:org.jfree.chart.demo.WaterfallChartDemo.java
/** * Returns the chart./*from w w w . j a v a2 s.co m*/ * * @param dataset the dataset. * * @return The chart. */ private JFreeChart createChart(final CategoryDataset dataset) { final JFreeChart chart = ChartFactory.createWaterfallChart("Product Cost Breakdown", "Expense Category", "Cost Per Unit", dataset, PlotOrientation.VERTICAL, true, true, false); chart.setBackgroundPaint(Color.white); final CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setRangeGridlinePaint(Color.white); plot.setRangeGridlinesVisible(true); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); final ValueAxis rangeAxis = plot.getRangeAxis(); // create a custom tick unit collection... final DecimalFormat formatter = new DecimalFormat("##,###"); formatter.setNegativePrefix("("); formatter.setNegativeSuffix(")"); final TickUnits standardUnits = new TickUnits(); standardUnits.add(new NumberTickUnit(5, formatter)); standardUnits.add(new NumberTickUnit(10, formatter)); standardUnits.add(new NumberTickUnit(20, formatter)); standardUnits.add(new NumberTickUnit(50, formatter)); standardUnits.add(new NumberTickUnit(100, formatter)); standardUnits.add(new NumberTickUnit(200, formatter)); standardUnits.add(new NumberTickUnit(500, formatter)); standardUnits.add(new NumberTickUnit(1000, formatter)); standardUnits.add(new NumberTickUnit(2000, formatter)); standardUnits.add(new NumberTickUnit(5000, formatter)); rangeAxis.setStandardTickUnits(standardUnits); final BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); final DecimalFormat labelFormatter = new DecimalFormat("$##,###.00"); labelFormatter.setNegativePrefix("("); labelFormatter.setNegativeSuffix(")"); // renderer.setLabelGenerator( // new StandardCategoryLabelGenerator("{2}", labelFormatter) // ); renderer.setItemLabelsVisible(true); return chart; }
From source file:edu.ucla.stat.SOCR.chart.demo.WaterfallChartDemo1.java
/** * Returns the chart./* w ww . ja v a 2 s.c o m*/ * * @param dataset the dataset. * * @return The chart. */ protected JFreeChart createChart(CategoryDataset dataset) { JFreeChart chart = ChartFactory.createWaterfallChart(chartTitle, domainLabel, rangeLabel, dataset, PlotOrientation.VERTICAL, !legendPanelOn, true, false); chart.setBackgroundPaint(Color.white); CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setRangeGridlinePaint(Color.white); plot.setRangeGridlinesVisible(true); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); ValueAxis rangeAxis = plot.getRangeAxis(); // create a custom tick unit collection... DecimalFormat formatter = new DecimalFormat("##,###"); formatter.setNegativePrefix("("); formatter.setNegativeSuffix(")"); TickUnits standardUnits = new TickUnits(); standardUnits.add(new NumberTickUnit(5, formatter)); standardUnits.add(new NumberTickUnit(10, formatter)); standardUnits.add(new NumberTickUnit(20, formatter)); standardUnits.add(new NumberTickUnit(50, formatter)); standardUnits.add(new NumberTickUnit(100, formatter)); standardUnits.add(new NumberTickUnit(200, formatter)); standardUnits.add(new NumberTickUnit(500, formatter)); standardUnits.add(new NumberTickUnit(1000, formatter)); standardUnits.add(new NumberTickUnit(2000, formatter)); standardUnits.add(new NumberTickUnit(5000, formatter)); rangeAxis.setStandardTickUnits(standardUnits); BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); renderer.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator()); DecimalFormat labelFormatter = new DecimalFormat("$##,###.00"); labelFormatter.setNegativePrefix("("); labelFormatter.setNegativeSuffix(")"); renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}", labelFormatter)); renderer.setBaseItemLabelsVisible(true); setCategorySummary(dataset); return chart; }
From source file:org.jfree.chart.demo.WaterfallChartDemo2.java
/** * Returns the chart.// w ww. j a va 2 s . com * * @param dataset the dataset. * * @return The chart. */ private JFreeChart createChart(final CategoryDataset dataset) { final CategoryAxis xAxis = new CategoryAxis("Category"); final NumberAxis yAxis = new NumberAxis("$ in Thousands"); yAxis.setLowerMargin(0.10); yAxis.setUpperMargin(0.10); // create a custom tick unit collection... final DecimalFormat formatter = new DecimalFormat("##,###"); formatter.setNegativePrefix("("); formatter.setNegativeSuffix(")"); final TickUnits standardUnits = new TickUnits(); standardUnits.add(new NumberTickUnit(200, formatter)); standardUnits.add(new NumberTickUnit(500, formatter)); standardUnits.add(new NumberTickUnit(1000, formatter)); standardUnits.add(new NumberTickUnit(2000, formatter)); standardUnits.add(new NumberTickUnit(5000, formatter)); yAxis.setStandardTickUnits(standardUnits); // **************************************************************************** // * JFREECHART DEVELOPER GUIDE * // * The JFreeChart Developer Guide, written by David Gilbert, is available * // * to purchase from Object Refinery Limited: * // * * // * http://www.object-refinery.com/jfreechart/guide.html * // * * // * Sales are used to provide funding for the JFreeChart project - please * // * support us so that we can continue developing free software. * // **************************************************************************** final DecimalFormat labelFormatter = new DecimalFormat("##,###"); labelFormatter.setNegativePrefix("("); labelFormatter.setNegativeSuffix(")"); final WaterfallBarRenderer renderer = new WaterfallBarRenderer(); // renderer.setLabelGenerator( // new StandardCategoryLabelGenerator("{2}", labelFormatter) // ); renderer.setItemLabelsVisible(Boolean.TRUE); final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); plot.setBackgroundPaint(Color.lightGray); plot.setRangeGridlinePaint(Color.white); plot.setRangeGridlinesVisible(true); final ValueMarker baseline = new ValueMarker(0.0); baseline.setPaint(Color.blue); baseline.setStroke(new BasicStroke(1.1f)); plot.addRangeMarker(baseline, Layer.FOREGROUND); final JFreeChart chart = new JFreeChart("OM WaterFall Chart", JFreeChart.DEFAULT_TITLE_FONT, plot, false); chart.setBackgroundPaint(Color.white); return chart; }
From source file:edu.ucla.stat.SOCR.chart.demo.HistogramChartDemo7.java
/** * Returns the chart.//from ww w . j av a 2 s. c om * * @param dataset the dataset. * * @return The chart. */ protected JFreeChart createChart(CategoryDataset dataset) { JFreeChart chart = ChartFactory.createBarChart(chartTitle, domainLabel, rangeLabel, dataset, PlotOrientation.VERTICAL, false, //!legendPanelOn, true, false); chart.setBackgroundPaint(Color.white); CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setRangeGridlinePaint(Color.white); plot.setRangeGridlinesVisible(true); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); ValueAxis rangeAxis = plot.getRangeAxis(); BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); renderer.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator()); DecimalFormat labelFormatter = new DecimalFormat("##,###.##"); labelFormatter.setNegativePrefix("("); labelFormatter.setNegativeSuffix(")"); renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}", labelFormatter)); renderer.setBaseItemLabelsVisible(true); //setCategorySummary(dataset); return chart; }
From source file:edu.ucla.stat.SOCR.chart.ChartGenerator_JTable.java
private JFreeChart createCategoryBarChart(String title, String xLabel, String yLabel, CategoryDataset dataset) { // System.out.println("layout = "+layout); JFreeChart chart;//w w w . j a v a2 s. c o m if (dimension.equalsIgnoreCase("3d")) { chart = ChartFactory.createBarChart3D(title, // chart title xLabel, // domain axis label yLabel, // range axis label dataset, // data orientation, // orientation true, // include legend true, // tooltips false // urls ); CategoryPlot plot = chart.getCategoryPlot(); plot.setDomainGridlinesVisible(true); CategoryAxis axis = plot.getDomainAxis(); axis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 8.0)); BarRenderer3D renderer = (BarRenderer3D) plot.getRenderer(); //renderer.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator()); renderer.setDrawBarOutline(false); return chart; } if (layout.equalsIgnoreCase("stacked")) { chart = ChartFactory.createStackedBarChart(title, // chart title xLabel, // domain axis label yLabel, // range axis label dataset, // data orientation, // the plot orientation true, // legend true, // tooltips false // urls ); } else if (layout.equalsIgnoreCase("waterfall")) { chart = ChartFactory.createWaterfallChart(title, xLabel, yLabel, dataset, orientation, true, true, false); CategoryPlot plot = chart.getCategoryPlot(); BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); DecimalFormat labelFormatter = new DecimalFormat("$##,###.00"); labelFormatter.setNegativePrefix("("); labelFormatter.setNegativeSuffix(")"); renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}", labelFormatter)); renderer.setBaseItemLabelsVisible(true); } else { chart = ChartFactory.createBarChart(title, // chart title xLabel, // domain axis label yLabel, // range axis label dataset, // data orientation, // orientation true, // include legend true, // tooltips? false // URLs? ); } // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... // set the background color for the chart... chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customisation... CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinePaint(Color.white); // set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // disable bar outlines... if (layout.equalsIgnoreCase("stacked")) { StackedBarRenderer renderer = (StackedBarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); renderer.setBaseItemLabelsVisible(true); renderer.setSeriesItemLabelGenerator(0, new StandardCategoryItemLabelGenerator()); } else if (layout.equalsIgnoreCase("layered")) { LayeredBarRenderer renderer = new LayeredBarRenderer(); renderer.setDrawBarOutline(false); plot.setRenderer(renderer); plot.setRowRenderingOrder(SortOrder.DESCENDING); } else { BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); } /* CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions( CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0) );*/ // OPTIONAL CUSTOMISATION COMPLETED. return chart; }