0

I am using mpandroid chart library, I want to show float value in line graph but it shows normal value.

Screenshot.

My code:

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 Answer 1

1

look into ValueFormatter

As described there in the wiki, create your own ValueFormatter and set the format you wish.

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
    }
}

Then apply your Formatter to the ChartData or DataSet object:

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

// usage on individual dataset object
lineDataSet.setValueFormatter(new MyValueFormatter());
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.