Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MPAndroidChart - wrong values in getFormattedValue method. Where they come from?

I am working with a project which is using MPAndroidChart library which makes me really crazy, I want to remove it.

The problem is I have created a custom ValueFormatter and I can't understand where these values come from, all are wrong.

 private void setData() {
  for (int i = 1; i <= 10; i++) {
        Entry entry = new Entry(i, i);
        values.add(entry);
    }


    IAxisValueFormatter valueFormatter = new myValueFormatter();
    XAxis xAxis = mChart.getXAxis();
    xAxis.setValueFormatter(valueFormatter);


    LineDataSet set1 = new LineDataSet(values, "DataSet 1");

    ArrayList<ILineDataSet> dataSets = new ArrayList<ILineDataSet>();
    dataSets.add(set1); // add the datasets

    // create a data object with the datasets
    LineData data = new LineData(dataSets);

    // set data
    mChart.setData(data);
}

custom formatter class: I have an array which has 1,2,3,4,5,6,7,8,9,10 values but I get 2,4,6,8,10 values in getFormattedValue method.

public classmyValueFormatter implements IAxisValueFormatter {

   @Override
public String getFormattedValue(float value, AxisBase axis) {

            System.out.println(value); //Here I get odd values where they come from I don't know.

}

}

like image 986
D B Avatar asked May 05 '18 08:05

D B


1 Answers

Well, generally that's how library is written. Have a look here:

https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/XAxisRenderer.java#L205

String label = mXAxis.getValueFormatter().getFormattedValue(mXAxis.mEntries[i / 2], mXAxis);

Author's intention was probably to give more spacing between labels. If you think this is a bug, submit issue to library's repository on Github.

like image 170
R. Zagórski Avatar answered Nov 15 '22 00:11

R. Zagórski