Reputation: 49
my question is: how can I plot in a LineChart (library MPAndroidChart) a java object from this class:
Object Class
public class Glycaemia {
private String date_of_addition, notes_by_the_user;
private float glycaemia;
public Glycaemia(){}
public Glycaemia(float value, String n)
{
this.glycaemia = value;
this.notes_by_the_user = n;
this.date_of_addition = setDate();
}
public Glycaemia(float value, String s, String s1)
{
this.glycaemia = value;
this.notes_by_the_user = s;
this.date_of_addition = s1;
}
private String setDate() {
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
String date = sdf.format(new Date());
return date;
}
public String getDate_of_addition()
{
return date_of_addition;
}
public String getNotes_by_the_user()
{
return notes_by_the_user;
}
public float getGlycaemia()
{
return glycaemia;
}
}
I want to set object'addition_date on the X-axis and it glycaemia_value on the Y-axis. Is there any way to plot a java object using this library? Something like creating a "format" which adapt the value to the chart?
Upvotes: 0
Views: 94
Reputation: 753
Set the glycaimia values cassually, then change the xAxisValues. Here is a sample code on how to change the xvalues
final String[] months = new String[] { "Jan", "Feb", "Mar", "Apr" };
IAxisValueFormatter formatter = new IAxisValueFormatter() {
@Override
public String getFormattedValue(float value, AxisBase axis) {
return months [(int) value];
}
@Override
public int getDecimalDigits() { return 0; }
};
XAxis xAxis = mLineChart.getXAxis();
xAxis.setGranularity(1f);
xAxis.setValueFormatter(formatter);
Hope this helps
Upvotes: 1