I am trying to modify the values of my X axis when plotting with AndroidPlot. This is because I am trying to represent the FFT of an audio spectrum and I would like the X axis to show the different frequencies. In the documentation is it recomended to use:
SimpleXYSeries.ArrayFormat.Y_VALS_ONLY
which uses the element index as the x value, but this is not what I need.
I need to do the following operation to convert the axis f = i * Fs / N being Fs, the sample rate in Hz and N, the number of points in the FFT.
I know that I need to create a new formatter and I have already check several examples like this,
this.getGraphWidget().setDomainValueFormat(new GraphXLabelFormat());
// ...
private class GraphXLabelFormat extends Format {
private static LABELS = ["Label 1", "Label 2", "Label 3"];
@Override
public StringBuffer format(Object object, StringBuffer buffer, FieldPosition field) {
int parsedInt = Math.round(Float.parseFloat(object.toString()));
String labelString = = LABELS[parsedInt];
buffer.append(labelString);
return buffer;
}
@Override
public Object parseObject(String string, ParsePosition position) {
return java.util.Arrays.asList(LABELS).indexOf(string);
}
}
The problem is that I dont really understand how it works and I don“t know how to adapt it to my necesities.
Thanks in advance!