【问题标题】:GarphView not working, blank activityGarphView 不工作,空白活动
【发布时间】:2014-09-26 06:36:42
【问题描述】:

我已经在我的主要活动类中动态实现了 GraphView。 未显示结果。 Activity 启动时保持空白。

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    //GraphView
    int num = 150;
    GraphViewData[] data = new GraphViewData[num];
    double v=0;
    for (int i=0; i<num; i++) {
      v += 0.2;
      data[i] = new GraphViewData(i, Math.sin(v));
    }
    GraphView graphView = new LineGraphView(this, "GraphViewDemo");
    // add data
    GraphViewSeries graphViewSeries=new GraphViewSeries(data);
    graphView.addSeries(graphViewSeries);
    // set view port, start=2, size=40
    graphView.setViewPort(2, 40);
    graphView.setScrollable(true);
    // optional - activate scaling / zooming
    graphView.setScalable(true);
    Log.d("2", "closed");
    LinearLayout layout = (LinearLayout)  findViewById(R.id.layout);
    layout.addView(graphView);
    //GraphhView
}

我想念一些东西,但我什么也没得到。

【问题讨论】:

  • 请显示您的布局 xml 文件

标签: java android android-activity android-graphview


【解决方案1】:

您需要在实现GraphViewDataInterface 的代码中创建一个GraphViewData 类,如下例所示:

public class GraphViewData implements GraphViewDataInterface {
private double x,y;

    public GraphViewData(double x, double y) {
        this.x = x;
        this.y = y;
    }

    @Override
    public double getX() {
        return this.x;
    }

    @Override
    public double getY() {
        return this.y;
    }   
}

【讨论】:

    猜你喜欢
    • 2014-08-22
    • 2012-06-04
    • 1970-01-01
    • 2017-04-03
    • 2015-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多