2

嗨,我目前在使用 graphview 库时遇到了一些真正的困难。我正在尝试通过来自活动中的广播接收器的调用来更新图表。但由于某种原因,它只更新 x 和 y 轴上的值。但不是图表本身。任何帮助将非常感激。

public class ComputationActivity extends Activity {

private GraphViewSeries series;
private GraphView graphView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_computation);

     series = new GraphViewSeries(new GraphViewData[]{ new GraphViewData(0,0)});


    BroadcastReceiver brodcast = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {


        double[] pressure = intent.getDoubleArrayExtra("pressure");
        double[] X = intent.getDoubleArrayExtra("X");

        int length = X.length;

        graphView = new LineGraphView(getApplicationContext(), "graphView");


        GraphViewData[] graphData = new GraphViewData[length];

        for(int i = 0; i < length; i++)
        {
            graphData[i] = new GraphViewData(X[i], pressure[i]);    
        }
        series.addGraphView(graphView);

        graphView.addSeries(series); 

        series.resetData(graphData);
        LinearLayout layout = (LinearLayout) findViewById(R.id.dynamicGraph);

        layout.addView(graphView);

        }   

    };

    registerReceiver(brodcast, new IntentFilter(VCFVS.BROADCAST_ACTION));

Intent mServiceIntent = new Intent(ComputationActivity.this, ComputationIntent.class);
ComputationActivity.this.startService(mServiceIntent);



}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.computation, menu);
    return true;
}

}

4

0 回答 0