2017-06-07 2 views
0

私はbarchartにMPAndroidChartを使用しています。 実際に私はこのような状況があります enter image description hereMpAndroidChartはbarchartのゼロ値行を取得します

Iによりこの結果を得た:このように、私は0.0を持っているが、私は青い線は、ゼロの値にも描かれたい第2の値について enter image description here

を最大値の割合が非常に低くなっていますが、0.0を表示し、0.5を表示しません。 値が0.0の場合は、行を表示するために値を変更したくありません。方法はありますか?いくつかのアイデア?

これは私の棒グラフの設定は次のとおりです。

YAxis leftAxis = barChart.getAxisLeft(); 
    leftAxis.setAxisMinimum(0f); 

    barChart.setDrawBarShadow(false); 
    barChart.getDescription().setEnabled(false); 
    barChart.setPinchZoom(false); 
    barChart.setDrawGridBackground(false); 
    barChart.setScaleEnabled(false); 
    barChart.getLegend().setEnabled(false); 
    barChart.getXAxis().setDrawAxisLine(false); 
    barChart.getXAxis().setDrawGridLines(false); 
    barChart.getAxis(YAxis.AxisDependency.LEFT).setEnabled(true); 
barChart.getAxis(YAxis.AxisDependency.LEFT).setDrawGridLines(false); 
    barChart.getAxis(YAxis.AxisDependency.LEFT).setDrawLabels(false); 
    barChart.getAxis(YAxis.AxisDependency.RIGHT).setEnabled(false); 
    barChart.getXAxis().setDrawLabels(false); 
    barChart.setDrawValueAboveBar(true); 

おかげ

答えて

1

あなたはその考えフロアy値以下与えられた量よりもゼロにダウンカスタムIValueFormatterを書き込むことによってこの問題を解決することができます。次に、y値は0.5fに表示されますが、0.0というラベルが付けられます。ここで

は、プロジェクト内のDefaultValueFormatterから適応非常にラフな例である:

barData.setValueFormatter(new FlooringValueFormatter(2, 0.5f)); 

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

import java.text.DecimalFormat; 

public class FlooringValueFormatter implements IValueFormatter 
{ 

    protected DecimalFormat mFormat; 

    protected int mDecimalDigits; 
    protected float mMinimum; 

    public FlooringValueFormatter(int digits, float minimum) { 
     setup(digits); 
     this.mMinimum = minimum; 
    } 

    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()); 
    } 

    @Override 
    public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) { 
     if (value < mMinimum) { 
      return mFormat.format(0); 
     } 

     return mFormat.format(value); 
    } 

    public int getDecimalDigits() { 
     return mDecimalDigits; 
    } 
} 

はこのようにそれを消費します

関連する問題