Example usage for java.text NumberFormat getInstance

List of usage examples for java.text NumberFormat getInstance

Introduction

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

Prototype

public static final NumberFormat getInstance() 

Source Link

Document

Returns a general-purpose number format for the current default java.util.Locale.Category#FORMAT FORMAT locale.

Usage

From source file:com.squarespace.template.UnitTestBase.java

public String commas(long num) {
    return NumberFormat.getInstance().format(num);
}

From source file:be.ibridge.kettle.trans.step.textfileinput.TextFileInputData.java

/**
 * /*from  w  w w .  j  a  v a  2s.co  m*/
 */
public TextFileInputData() {
    super();

    thisline = null;
    nextline = null;

    lineBuffer = new ArrayList();
    nf = NumberFormat.getInstance();
    df = (DecimalFormat) nf;
    dfs = new DecimalFormatSymbols();
    daf = new SimpleDateFormat();
    dafs = new DateFormatSymbols();

    nr_repeats = 0;
    previous_row = null;
    filenr = 0;

    nrLinesOnPage = 0;

    fr = null;
    zi = null;

    filterProcessor = null;
}

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

private static JFreeChart createChart(CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createStackedBarChart("Item Label Demo 5", null, null, categorydataset,
            PlotOrientation.VERTICAL, false, true, false);
    jfreechart.setBackgroundPaint(new Color(255, 255, 255));
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    MyStackedBarRenderer mystackedbarrenderer = new MyStackedBarRenderer();
    categoryplot.setRenderer(mystackedbarrenderer);
    ItemLabelPosition itemlabelposition = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER,
            TextAnchor.CENTER, 0.0D);//from   w  w w . ja va2  s .c  om
    mystackedbarrenderer.setPositiveItemLabelPositionFallback(itemlabelposition);
    mystackedbarrenderer.setNegativeItemLabelPositionFallback(itemlabelposition);
    StandardCategoryItemLabelGenerator standardcategoryitemlabelgenerator = new StandardCategoryItemLabelGenerator(
            "{0}", NumberFormat.getInstance());
    mystackedbarrenderer.setBaseItemLabelGenerator(standardcategoryitemlabelgenerator);
    mystackedbarrenderer.setBaseItemLabelsVisible(true);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setUpperBound(100D);
    return jfreechart;
}

From source file:servlet.SalesReportEventsBarChart.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from w ww  .j a v  a  2 s . c  o  m*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    List<ArrayList> data = productSession.getEventSessionNo();

    final DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    for (int i = 0; i < data.size(); i++) {
        dataset.addValue(Integer.valueOf(data.get(i).get(1).toString()), "Sessions",
                data.get(i).get(0).toString());
    }

    final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());

    JFreeChart barChart = ChartFactory.createBarChart("No of Sessions", "Event", "Sessions", dataset,
            PlotOrientation.VERTICAL, true, true, false);

    CategoryPlot cplot = (CategoryPlot) barChart.getPlot();
    cplot.setBackgroundPaint(Color.WHITE);//change background color

    //set  bar chart color
    ((BarRenderer) cplot.getRenderer()).setBarPainter(new StandardBarPainter());

    BarRenderer r = (BarRenderer) barChart.getCategoryPlot().getRenderer();
    r.setSeriesPaint(0, Color.GREEN);

    r.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}", NumberFormat.getInstance()));
    r.setBaseItemLabelsVisible(true);

    CategoryAxis categoryAxis = cplot.getDomainAxis();
    categoryAxis.setUpperMargin(0.15);

    NumberAxis rangeAxis = (NumberAxis) cplot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setUpperMargin(0.15);

    int width = 550; /* Width of the image */

    int height = 450; /* Height of the image */

    response.setContentType("image/png");
    OutputStream out = response.getOutputStream();

    ChartUtilities.writeChartAsPNG(out, barChart, 400, 300, info);

}

From source file:com.squarespace.template.UnitTestBase.java

public String commas(double num) {
    return NumberFormat.getInstance().format(num);
}

From source file:net.sourceforge.processdash.ui.web.reports.XYChart.java

/** Create a scatter plot. */
@Override//from w  w w.ja v a2s  .  co  m
public JFreeChart createChart() {
    JFreeChart chart;
    String xLabel = null, yLabel = null;
    if (!chromeless) {
        xLabel = Translator.translate(data.getColName(1));

        yLabel = getSetting("yLabel");
        if (yLabel == null && data.numCols() == 2)
            yLabel = data.getColName(2);
        if (yLabel == null)
            yLabel = getSetting("units");
        if (yLabel == null)
            yLabel = "Value";
        yLabel = Translator.translate(yLabel);
    }

    Object autoZero = parameters.get("autoZero");

    boolean firstColumnContainsDate = data.numRows() > 0 && data.numCols() > 0
            && data.getData(1, 1) instanceof DateData;
    if (firstColumnContainsDate || parameters.get("xDate") != null) {
        chart = ChartFactory.createTimeSeriesChart(null, xLabel, yLabel, data.xyDataSource(), true, true,
                false);
        if (firstColumnContainsDate && ((DateData) data.getData(1, 1)).isFormatAsDateOnly())
            chart.getXYPlot().getRenderer().setBaseToolTipGenerator(
                    new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                            DateFormat.getDateInstance(DateFormat.SHORT), NumberFormat.getInstance()));
    } else {
        XYDataset src = data.xyDataSource();
        chart = ChartFactory.createScatterPlot(null, xLabel, yLabel, src, PlotOrientation.VERTICAL, true, true,
                false);
        if (src instanceof XYToolTipGenerator) {
            chart.getXYPlot().getRenderer().setBaseToolTipGenerator((XYToolTipGenerator) src);
        }

        String trendLine = getParameter("trend");
        if ("none".equalsIgnoreCase(trendLine))
            ;
        else if ("average".equalsIgnoreCase(trendLine))
            addTrendLine(chart,
                    XYDataSourceTrendLine.getAverageLine(src, 0, autoZero != null && !autoZero.equals("y")));
        else
            addTrendLine(chart,
                    XYDataSourceTrendLine.getRegressionLine(src, 0, autoZero != null && !autoZero.equals("y")));
    }

    if (autoZero != null) {
        if (!"x".equals(autoZero))
            ((NumberAxis) chart.getXYPlot().getRangeAxis()).setAutoRangeIncludesZero(true);
        if (!"y".equals(autoZero))
            ((NumberAxis) chart.getXYPlot().getDomainAxis()).setAutoRangeIncludesZero(true);
    }

    if (data.numCols() == 2)
        chart.removeLegend();

    return chart;
}

From source file:org.netxilia.functions.TextFunctions.java

public String FIXED(double number, int decimals, boolean no_thousands_separator) {
    NumberFormat format = NumberFormat.getInstance();
    format.setMaximumFractionDigits(decimals);
    format.setGroupingUsed(!no_thousands_separator);
    return format.format(number);
}

From source file:net.sourceforge.eclipsetrader.charts.ChartsPlugin.java

public static NumberFormat getPercentageFormat() {
    if (percentageFormat == null) {
        percentageFormat = NumberFormat.getInstance();
        percentageFormat.setGroupingUsed(false);
        percentageFormat.setMinimumIntegerDigits(1);
        percentageFormat.setMinimumFractionDigits(2);
        percentageFormat.setMaximumFractionDigits(2);
    }//from ww  w  . j a  v a  2s .c  o  m
    return percentageFormat;
}

From source file:com.googlecode.logVisualizer.chart.HorizontalBarChartBuilder.java

private JFreeChart createChart(final CategoryDataset dataset) {
    final JFreeChart chart = ChartFactory.createBarChart(getTitle(), xLable, yLable, dataset,
            PlotOrientation.HORIZONTAL, isIncludeLegend(), true, false);
    final CategoryPlot plot = (CategoryPlot) chart.getPlot();
    final BarRenderer renderer = (BarRenderer) plot.getRenderer();
    final CategoryAxis categoryAxis = plot.getDomainAxis();
    final NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis();

    plot.setNoDataMessage("No data available");
    plot.setBackgroundPaint(Color.white);
    plot.setRangeGridlinePaint(Color.black);
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    setBarShadowVisible(chart, false);/* w  w  w .  j a  v  a 2 s.c  om*/

    renderer.setBaseItemLabelsVisible(true);
    renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    renderer.setBaseToolTipGenerator(
            new StandardCategoryToolTipGenerator("{1}, {2}", NumberFormat.getInstance()));

    categoryAxis.setCategoryMargin(0.02);
    categoryAxis.setUpperMargin(0.02);
    categoryAxis.setLowerMargin(0.02);
    numberAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    numberAxis.setUpperMargin(0.1);

    return chart;
}

From source file:com.alibaba.json.test.JSONParser2Test.java

private void f_jackson() throws Exception {
    long startNano = System.nanoTime();
    for (int i = 0; i < COUNT; ++i) {
        ObjectMapper mapper = new ObjectMapper();
        mapper.readTree(text);//www.j  a  v  a 2s  . c o  m
        // JsonNode head = node.get(0);
        // JsonNode body = node.get(1);
    }
    long nano = System.nanoTime() - startNano;
    System.out.println("jackson \t: " + NumberFormat.getInstance().format(nano));
}