2016-05-30 4 views
0

Es kann dumme Frage bin mit horizontalen mpandroid barchart bin mit Zahlen in x-Achse wie 6.000.000 so x Achse immer zusammengebrochen, was ist zu tun, ist die Zahl in indische Rupien wie 6 cr konvertieren wie kann ich das tun, was ich versucht haben, ist: wo bin Einstellung Wert für die horizontale BalkendiagrammWie wird der x-Achsenwert im horizontalen MPandroidchart angepasst?

Dies ist:

ArrayList<BarEntry> entries = new ArrayList<>(); 
     ArrayList<String> labels = new ArrayList<String>(); 
     Format format = NumberFormat.getCurrencyInstance(new Locale("en", "in")); 
     // System.out.println(format.format(new BigDecimal("100000000"))); 



     for(int i=0;i<listobj.size();i++){ 
      String s= format.format(listobj.get(i).getData()); 
     // Log.e("ss", s); 
//   Integer numberformat=Integer.parseInt(s); 
      entries.add(new BarEntry(listobj.get(i).getData(),i)); 
      labels.add(listobj.get(i).getLabel()); 
     } 
     XAxis axis=barChart.getXAxis(); 
     BarDataSet dataset = new BarDataSet(entries, "# of Calls"); 
     //dataset.setValueFormatter(new LargeValueFormatter()); 
     BarData datas = new BarData(labels, dataset); 
     /// datas.setValueFormatter(new LargeValueFormatter()); 
     barChart.setData(datas); 
     barChart.setDescription("Description"); 
     barChart.getLegend().setWordWrapEnabled(true); 

Dieser Wert Formatter ist:

/** 
* Created by 4264 on 30-05-2016. 
*/ 

import com.github.mikephil.charting.data.Entry; 
import com.github.mikephil.charting.formatter.ValueFormatter; 
import com.github.mikephil.charting.utils.ViewPortHandler; 

import java.text.DecimalFormat; 

/** 
* Predefined value-formatter that formats large numbers in a pretty way. 
* Outputs: 856 = 856; 1000 = 1k; 5821 = 5.8k; 10500 = 10k; 101800 = 102k; 
* 2000000 = 2m; 7800000 = 7.8m; 92150000 = 92m; 123200000 = 123m; 9999999 = 
* 10m; 1000000000 = 1b; Special thanks to Roman Gromov 
* (https://github.com/romangromov) for this piece of code. 
* 
* @author Philipp Jahoda 
* @author Oleksandr Tyshkovets <[email protected]> 
*/ 
class LargeValueFormatter implements ValueFormatter { 

    private static String[] SUFFIX = new String[]{ 
      "", "k", "m", "b", "t" 
    }; 
    private static final int MAX_LENGTH = 4; 
    private DecimalFormat mFormat; 
    private String mText = ""; 

    public LargeValueFormatter() { 
     mFormat = new DecimalFormat("###E0"); 
    } 

    /** 
    * Creates a formatter that appends a specified text to the result string 
    * 
    * @param appendix a text that will be appended 
    */ 
    public LargeValueFormatter(String appendix) { 
     this(); 
     mText = appendix; 
    } 

    // ValueFormatter 
    @Override 
    public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) { 
     return makePretty(value) + mText; 
    } 


    // YAxisValueFormatter 


    /** 
    * Set an appendix text to be added at the end of the formatted value. 
    * 
    * @param appendix 
    */ 
    public void setAppendix(String appendix) { 
     this.mText = appendix; 
    } 

    /** 
    * Set custom suffix to be appended after the values. 
    * Default suffix: ["", "k", "m", "b", "t"] 
    * 
    * @param suff new suffix 
    */ 
    public void setSuffix(String[] suff) { 
     if (suff.length == 5) { 
      SUFFIX = suff; 
     } 
    } 

    /** 
    * Formats each number properly. Special thanks to Roman Gromov 
    * (https://github.com/romangromov) for this piece of code. 
    */ 
    private String makePretty(double number) { 

     String r = mFormat.format(number); 

     r = r.replaceAll("E[0-9]", SUFFIX[Character.getNumericValue(r.charAt(r.length() - 1))/3]); 

     while (r.length() > MAX_LENGTH || r.matches("[0-9]+\\.[a-z]")) { 
      r = r.substring(0, r.length() - 2) + r.substring(r.length() - 1); 
     } 

     return r; 
    } 

    } 

ich weiß nicht, wie die x-Achse Wert anpassen, wie Kann ich das tun c jemand hilft mir aus danke im voraus !!

Antwort

0

Sie haben 2 Optionen, die Sie versuchen können, Ihr Problem zu lösen 1) Während Sie den Wert einfügen, können Sie den Wert durch 1000.000 teilen und Ihre Bezeichnung zu 6Cr ändern. Ich habe ein Diagramm, das 4000. Werte von 0 bis 30 und einen Wert hat, während der Wert in der Datenbank zu speichern ich es teilen durch 100, während der Anzeige von I das Etikett ändern den richtigen Wert Beispiel SQL Insert Wert anzuzeigen:

Float.valueOf(LEUCO_COUNT.getText().toString())/1000, 

2) Option 2 besteht darin, den Wert vor der Anzeige durch 1000,000 zu teilen und auch Ihr Babel so zu ändern, dass Cr angezeigt wird. Sie können durch die API gehen, um zu finden, wie man ein kundenspezifisches Etikett einstellt

Hoffe, dass dies hilft.

0

Sie müssen bestehende Funktion mit unten Funktion ersetzen. Es funktioniert für mich.

private String makePretty (double zahl) {

double Cr = 10000000; 
    double Lac = 100000; 

    String result = mFormat.format(number); 
    try { 
     double LAmt = Double.parseDouble(result); 
     String Append = ""; 
     if (LAmt > Cr) {//1Crore 
      LAmt /= Cr; 
      Append = "Cr"; 
     } else { 
      LAmt /= Lac; 
      Append = "L"; 
     } 
     result = CommonUtils.GetFormattedString("" + LAmt) + Append; 
    } catch (NumberFormatException e) { 
     Log.d("", ""); 
    } 
    return result; 
}