I am using LineChart to be able to generate a graph and represent certain values.
I get this graph from the following library: com.github.PhilJay:MPAndroidChart:v3.0.0-beta1
My problem comes when it comes to seeing the points drawn on the graph since it shows me said points with 3 decimal places and the values that I give it are with 0, 1 or 2 decimal places, never with 3.
For example, if I enter 1.2 on the graph it shows me 1,200.
As you can see, all the values are shown to me with 3 decimal places.
The way I generate the points is as follows:
entries.add(new Entry((float) listaFechasOrig[listaDatos.length - 1 - i].getTime(), Float.parseFloat(datoOrigRecortado.replace(",","."))));
There, the values are passed correctly (with the desired decimal places).
The marker I use is a custom one that inherits from the MarkerView, this is the code but this is not where it rounds it off.
public class CustomMarkerView extends MarkerView {
private TextView tvContent;
private Context cont;
public CustomMarkerView (Context context, int layoutResource) {
super(context, layoutResource);
// this markerview only displays a textview
tvContent = (TextView) findViewById(R.id.tvContent);
cont = context;
}
// callbacks everytime the MarkerView is redrawn, can be used to update the
// content (user-interface)
@Override
public void refreshContent(Entry e, Highlight highlight) {
Date d = new Date((long)e.getX());
String fecha = d.toString().substring(0,20);
fecha = fecha.replace("Jan", "Ene");
fecha = fecha.replace("Apr", "Abr");
fecha = fecha.replace("Aug", "Ago");
fecha = fecha.replace("Dec", "Dic");
fecha = fecha.replace("Mon", "Lunes");
fecha = fecha.replace("Tue", "Martes");
fecha = fecha.replace("Wed", "Miércoles");
fecha = fecha.replace("Thu", "Jueves");
fecha = fecha.replace("Fri", "Viernes");
fecha = fecha.replace("Sat", "Sábado");
fecha = fecha.replace("Sun", "Domingo");
try
{
Tab1Prueba.rellenaDatos(fecha, e.getY()+"");
}catch(Exception exc)
{}
try
{
Tab1Gra.rellenaDatos(fecha, e.getY()+"");
}catch(Exception exc)
{}
}
@Override
public int getXOffset(float xpos) {
// this will center the marker-view horizontally
return -(getWidth() / 2);
}
@Override
public int getYOffset(float ypos) {
// this will cause the marker-view to be above the selected value
return -getHeight();
}
}
I thought it was a property of the Marker but I haven't put anything on it (I don't know if it comes from the class I inherited) or some attribute of the graph must be changed and not of the marker.
Thanks.
What you should do is use a formatter provided by the library itself, as explained here .
First you implement the interface
IValueFormatter
And to use it, you simply call the method
setValueFormatter
passing your class as a parameter: