Mpchart浮点值未在数组列表中显示

时间:2017-11-14 06:25:41

标签: android mpandroidchart

我正在使用mpandroid图表库,我想在折线图中显示浮点值,但它显示正常值。

Screenshot

我的代码:

if (cursor != null) {

            for (int h = 0; h < cursor.getCount(); h++) {

                cursor.moveToNext();

                ans = cursor.getString(cursor.getColumnIndex("pnt_triiodothyronine"));

                entry1.add( new Entry(cursor.getFloat(cursor.getColumnIndex("pnt_triiodothyronine")),h));
                entry2.add( new Entry(cursor.getFloat(cursor.getColumnIndex("pnt_thyroxine")),h));
                entry3.add( new Entry(cursor.getFloat(cursor.getColumnIndex("pnt_tsh")),h));
                entry4.add( new Entry(cursor.getFloat(cursor.getColumnIndex("pnt_weight")),h));
                entry5.add((cursor.getString(cursor.getColumnIndex("date"))));

                ansText.setText(ans);
            }

            cursor.close();

        }

lDataSet1 = new LineDataSet(entry1, "T3");
        //lDataSet1.setDrawFilled(true);
        lDataSet1.setColors(new int[]{getResources().getColor(R.color.purple)}); //resolved color
        lDataSet1.setCircleColor(Color.parseColor("#ffffff"));
        lDataSet1.setLineWidth(1.5f);
        lDataSet1.setCircleColorHole(Color.parseColor("#9c27b0"));
        lDataSet1.setHighLightColor(Color.rgb(190, 190, 190));
        lDataSet1.setDrawCubic(true);
        //lDataSet1.setDrawFilled(true);
        lines.add(lDataSet1);

1 个答案:

答案 0 :(得分:1)

查看ValueFormatter

如wiki中所述,创建自己的ValueFormatter并设置所需的格式。

public class MyValueFormatter implements IValueFormatter {

    private DecimalFormat mFormat;

    public MyValueFormatter() {
        mFormat = new DecimalFormat("###,###,##0.0"); // use one decimal
    }

    @Override
    public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
        // write your logic here
        return mFormat.format(value) + " $"; // e.g. append a dollar-sign
    }
}

然后将Formatter应用于ChartData或DataSet对象:

// usage on whole data object
lineData.setValueFormatter(new MyValueFormatter());

// usage on individual dataset object
lineDataSet.setValueFormatter(new MyValueFormatter());