Search in sources :

Example 21 with DecimalFormat

use of java.text.DecimalFormat in project WilliamChart by diogobernardino.

the class AxisRendererTest method convertToLabelsFormat_Integer_StringXXDB.

@Test
public void convertToLabelsFormat_Integer_StringXXDB() {
    ArrayList<Integer> values = new ArrayList<>();
    values.add(3);
    DecimalFormat format = new DecimalFormat("#'DB'");
    assertEquals("3DB", mXRndr.convertToLabelsFormat(values, format).get(0));
}
Also used : DecimalFormat(java.text.DecimalFormat) ArrayList(java.util.ArrayList) MediumTest(android.test.suitebuilder.annotation.MediumTest) Test(org.junit.Test)

Example 22 with DecimalFormat

use of java.text.DecimalFormat in project WilliamChart by diogobernardino.

the class AxisRenderer method reset.

/**
	 * Reset renderer attributes to defaults.
	 */
public void reset() {
    mandatoryBorderSpacing = 0;
    borderSpacing = 0;
    topSpacing = 0;
    step = -1;
    labelsStaticPos = 0;
    labelFormat = new DecimalFormat();
    axisPosition = 0;
    minLabelValue = 0;
    maxLabelValue = 0;
    handleValues = false;
}
Also used : DecimalFormat(java.text.DecimalFormat)

Example 23 with DecimalFormat

use of java.text.DecimalFormat in project android-app by eoecn.

the class ImageUtil method FormetFileSize.

/**
	 * 转换文件大小
	 * 
	 * @param fileS
	 * @return
	 */
public static String FormetFileSize(long fileS) {
    DecimalFormat df = new DecimalFormat("#.00");
    String fileSizeString = "";
    if (fileS < 1024) {
        fileSizeString = df.format((double) fileS) + "B";
    } else if (fileS < 1048576) {
        fileSizeString = df.format((double) fileS / 1024) + "K";
    } else if (fileS < 1073741824) {
        fileSizeString = df.format((double) fileS / 1048576) + "M";
    } else {
        fileSizeString = df.format((double) fileS / 1073741824) + "G";
    }
    return fileSizeString;
}
Also used : DecimalFormat(java.text.DecimalFormat)

Example 24 with DecimalFormat

use of java.text.DecimalFormat in project MPAndroidChart by PhilJay.

the class StackedBarActivityNegative method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_age_distribution);
    setTitle("Age Distribution Austria");
    mChart = (HorizontalBarChart) findViewById(R.id.chart1);
    mChart.setOnChartValueSelectedListener(this);
    mChart.setDrawGridBackground(false);
    mChart.getDescription().setEnabled(false);
    // scaling can now only be done on x- and y-axis separately
    mChart.setPinchZoom(false);
    mChart.setDrawBarShadow(false);
    mChart.setDrawValueAboveBar(true);
    mChart.setHighlightFullBarEnabled(false);
    mChart.getAxisLeft().setEnabled(false);
    mChart.getAxisRight().setAxisMaximum(25f);
    mChart.getAxisRight().setAxisMinimum(-25f);
    mChart.getAxisRight().setDrawGridLines(false);
    mChart.getAxisRight().setDrawZeroLine(true);
    mChart.getAxisRight().setLabelCount(7, false);
    mChart.getAxisRight().setValueFormatter(new CustomFormatter());
    mChart.getAxisRight().setTextSize(9f);
    XAxis xAxis = mChart.getXAxis();
    xAxis.setPosition(XAxisPosition.BOTH_SIDED);
    xAxis.setDrawGridLines(false);
    xAxis.setDrawAxisLine(false);
    xAxis.setTextSize(9f);
    xAxis.setAxisMinimum(0f);
    xAxis.setAxisMaximum(110f);
    xAxis.setCenterAxisLabels(true);
    xAxis.setLabelCount(12);
    xAxis.setGranularity(10f);
    xAxis.setValueFormatter(new IAxisValueFormatter() {

        private DecimalFormat format = new DecimalFormat("###");

        @Override
        public String getFormattedValue(float value, AxisBase axis) {
            return format.format(value) + "-" + format.format(value + 10);
        }
    });
    Legend l = mChart.getLegend();
    l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
    l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
    l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
    l.setDrawInside(false);
    l.setFormSize(8f);
    l.setFormToTextSpace(4f);
    l.setXEntrySpace(6f);
    // IMPORTANT: When using negative values in stacked bars, always make sure the negative values are in the array first
    ArrayList<BarEntry> yValues = new ArrayList<BarEntry>();
    yValues.add(new BarEntry(5, new float[] { -10, 10 }));
    yValues.add(new BarEntry(15, new float[] { -12, 13 }));
    yValues.add(new BarEntry(25, new float[] { -15, 15 }));
    yValues.add(new BarEntry(35, new float[] { -17, 17 }));
    yValues.add(new BarEntry(45, new float[] { -19, 20 }));
    yValues.add(new BarEntry(45, new float[] { -19, 20 }, getResources().getDrawable(R.drawable.star)));
    yValues.add(new BarEntry(55, new float[] { -19, 19 }));
    yValues.add(new BarEntry(65, new float[] { -16, 16 }));
    yValues.add(new BarEntry(75, new float[] { -13, 14 }));
    yValues.add(new BarEntry(85, new float[] { -10, 11 }));
    yValues.add(new BarEntry(95, new float[] { -5, 6 }));
    yValues.add(new BarEntry(105, new float[] { -1, 2 }));
    BarDataSet set = new BarDataSet(yValues, "Age Distribution");
    set.setDrawIcons(false);
    set.setValueFormatter(new CustomFormatter());
    set.setValueTextSize(7f);
    set.setAxisDependency(YAxis.AxisDependency.RIGHT);
    set.setColors(new int[] { Color.rgb(67, 67, 72), Color.rgb(124, 181, 236) });
    set.setStackLabels(new String[] { "Men", "Women" });
    String[] xLabels = new String[] { "0-10", "10-20", "20-30", "30-40", "40-50", "50-60", "60-70", "70-80", "80-90", "90-100", "100+" };
    BarData data = new BarData(set);
    data.setBarWidth(8.5f);
    mChart.setData(data);
    mChart.invalidate();
}
Also used : Legend(com.github.mikephil.charting.components.Legend) BarDataSet(com.github.mikephil.charting.data.BarDataSet) IBarDataSet(com.github.mikephil.charting.interfaces.datasets.IBarDataSet) DecimalFormat(java.text.DecimalFormat) ArrayList(java.util.ArrayList) IAxisValueFormatter(com.github.mikephil.charting.formatter.IAxisValueFormatter) AxisBase(com.github.mikephil.charting.components.AxisBase) BarEntry(com.github.mikephil.charting.data.BarEntry) XAxis(com.github.mikephil.charting.components.XAxis) BarData(com.github.mikephil.charting.data.BarData)

Example 25 with DecimalFormat

use of java.text.DecimalFormat in project MPAndroidChart by PhilJay.

the class DefaultValueFormatter method setup.

/**
     * Sets up the formatter with a given number of decimal digits.
     *
     * @param digits
     */
public void setup(int digits) {
    this.mDecimalDigits = digits;
    StringBuffer b = new StringBuffer();
    for (int i = 0; i < digits; i++) {
        if (i == 0)
            b.append(".");
        b.append("0");
    }
    mFormat = new DecimalFormat("###,###,###,##0" + b.toString());
}
Also used : DecimalFormat(java.text.DecimalFormat)

Aggregations

DecimalFormat (java.text.DecimalFormat)719 DecimalFormatSymbols (java.text.DecimalFormatSymbols)89 NumberFormat (java.text.NumberFormat)88 BigDecimal (java.math.BigDecimal)45 IOException (java.io.IOException)42 ArrayList (java.util.ArrayList)40 IFormatterTextCallBack (org.xclcharts.common.IFormatterTextCallBack)33 ParseException (java.text.ParseException)30 IFormatterDoubleCallBack (org.xclcharts.common.IFormatterDoubleCallBack)29 Support_DecimalFormat (tests.support.Support_DecimalFormat)28 File (java.io.File)24 Date (java.util.Date)24 SimpleDateFormat (java.text.SimpleDateFormat)22 HashMap (java.util.HashMap)21 Locale (java.util.Locale)21 PrintWriter (java.io.PrintWriter)20 UsageVO (com.cloud.usage.UsageVO)19 JFreeChart (org.jfree.chart.JFreeChart)18 List (java.util.List)17 TextView (android.widget.TextView)15