Android应用程序开发 - 库android-graphview

时间:2018-06-02 16:40:57

标签: android-graphview

我在android studio中的图形视图库中显示时间序列数据的可视化问题。当我试图在x轴上对非常小的值(间隔为0.00003)绘制图形时,没有图形。但是,当我尝试绘制整数值(在1的区间内)时,显示的图形与预期的一样。

我的工作代码 -

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_time);
    Intent intent = getIntent();
    int sample_freq = 32768;
    double []  data = intent.getDoubleArrayExtra(DataActivity.EXTRA_TIME_DATA);
    int n = data.length;
    GraphView graph = findViewById(R.id.graph);
    double sample_time = 1/sample_freq;
    DataPoint[] points = new DataPoint[n];
    for(int i = 0; i < n ; i++)
    {
        points[i] = new DataPoint(i, data[i]);
    }
    LineGraphSeries<DataPoint> series = new LineGraphSeries<>(points);
    graph.getViewport().setYAxisBoundsManual(true);
    graph.getViewport().setMinY(-15);
    graph.getViewport().setMaxY(15);
    graph.getViewport().setXAxisBoundsManual(true);
    graph.getViewport().setMinX(100);
    graph.getViewport().setMaxX(5000);
    graph.getViewport().setScalable(true);
    graph.getViewport().setScalableY(true);
    graph.addSeries(series);

    TextView textView = findViewById(R.id.textView);
    String message = String.valueOf(n);
    textView.setText(message);
}

无效的代码 -

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_time);
    Intent intent = getIntent();
    int sample_freq = 32768;
    double []  data = intent.getDoubleArrayExtra(DataActivity.EXTRA_TIME_DATA);
    int n = data.length;
    GraphView graph = findViewById(R.id.graph);
    double sample_time = 1/sample_freq;
    DataPoint[] points = new DataPoint[n];
    for(int i = 0; i < n ; i++)
    {
        points[i] = new DataPoint(i*sample_time, data[i]);
    }
    LineGraphSeries<DataPoint> series = new LineGraphSeries<>(points);
    graph.getViewport().setYAxisBoundsManual(true);
    graph.getViewport().setMinY(-15);
    graph.getViewport().setMaxY(15);
    graph.getViewport().setXAxisBoundsManual(true);
    graph.getViewport().setMinX(0.01);
    graph.getViewport().setMaxX(1);
    graph.getViewport().setScalable(true);
    graph.getViewport().setScalableY(true);
    graph.addSeries(series);

    TextView textView = findViewById(R.id.textView);
    String message = String.valueOf(n);
    textView.setText(message);
}

0 个答案:

没有答案