android 中的 LogLinear 和 LogLog 图

LogLinear and LogLog plots in android

我希望我的应用程序能够显示 frequency response graphs but I cannot find any graphing library that has this functionality. I am currently using MPAndroidChart for some other charts (and it is great !) but sadly I could not find any way to use it to do log plots. I have also tried using numAndroidCharts (numcharts logplot example),但是那个库似乎 broken/outdated 因为我什至无法让示例代码正常工作。无论如何,您知道如何实现这一目标吗?

我使用 MPAndroidChart 和带有转换值的对数刻度。

例如,如果您的值为 1E-5:

value = 1E-5;
Entry entry = new Entry();
entry.setX(Math.log10(value)); // entry.getX() will return -5

因为你现在的值是-5你需要创建一个AxisFormatter来表明它真的代表一个对数值:

public class Log10AxisValueFormatter implements IAxisValueFormatter {
    @Override
    public String getFormattedValue(float value, AxisBase axis) {
        return String.format(Locale.ENGLISH, "%.2E", Math.pow(10,value));
    }
}

您需要在创建图表时将其实例设置为轴:

XAxis xAxis = chart.getXAxis();
xAxis.setValueFormatter(new Log10AxisValueFormatter());