无法在Eclipse中使用Graph View库

时间:2016-11-14 10:34:07

标签: java android eclipse android-graphview

我想在Android中绘制图表。因此,经过一些研究,我发现GraphView是一个很好的。所以,我遵循了这个(http://www.ssaurel.com/blog/create-a-real-time-line-graph-in-android-with-graphview/)教程,但我无法在eclipse中使用graphView。我使用Properties-> Java BuildPath-> Libraries添加了jar文件,并添加了jar文件。

当我运行项目时,我遇到了致命的错误。我很乐意提供有关此事的任何其他信息,

我在Windows 7上使用Eclipse Neon。

SS of first few lines from logCat

编辑 - 这是xml文件中图形布局的SS。

enter image description here

编辑 - 完成项目文件的布局

enter image description here

Java代码 -

package com.ssaurel.testgraphview;

import java.util.Random;

import android.app.Activity;
import android.os.Bundle;

import com.jjoe64.graphview.GraphView;
import com.jjoe64.graphview.Viewport;
import com.jjoe64.graphview.series.DataPoint;
import com.jjoe64.graphview.series.LineGraphSeries;

public class MainActivity extends Activity {

  private static final Random RANDOM = new Random();
  private LineGraphSeries<DataPoint> series;
  private int lastX = 0;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    // we get graph view instance
    GraphView graph = (GraphView) findViewById(R.id.graph);
    // data
    series = new LineGraphSeries<DataPoint>();
    graph.addSeries(series);
    // customize a little bit viewport
    Viewport viewport = graph.getViewport();
    viewport.setYAxisBoundsManual(true);
    viewport.setMinY(0);
    viewport.setMaxY(10);
    viewport.setScrollable(true);
  }

  @Override
  protected void onResume() {
   super.onResume();
   // we're going to simulate real time with thread that append data to the graph
   new Thread(new Runnable() {

     @Override
     public void run() {
       // we add 100 new entries
       for (int i = 0; i < 100; i++) {
         runOnUiThread(new Runnable() {

           @Override
           public void run() {
             addEntry();
           }
         });

         // sleep to slow down the add of entries
         try {
           Thread.sleep(600);
         } catch (InterruptedException e) {
           // manage error ...
         }
       }
     }
    }).start();
   }

   // add random data to graph
   private void addEntry() {
     // here, we choose to display max 10 points on the viewport and we scroll to end
     series.appendData(new DataPoint(lastX++, RANDOM.nextDouble() * 10d), true, 10);
   }

}

xml代码 -

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.ssaurel.testgraphview.MainActivity" >

    <com.jjoe64.graphview.GraphView
    android:id="@+id/graph"
    android:layout_width="match_parent"
    android:layout_height="300dp" />

</RelativeLayout>

0 个答案:

没有答案