1

我正在使用 achartengine 在 android 中绘制动态时间序列。下面是我的代码:

    public class RandomActivity extends Activity {
private XYMultipleSeriesDataset eeg1 = new XYMultipleSeriesDataset();
private XYMultipleSeriesRenderer renderer_eeg1 = new XYMultipleSeriesRenderer();
private TimeSeries series1;
private GraphicalView view_eeg1;
private static int a;

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);


renderer_eeg1.setAxisTitleTextSize(16);
renderer_eeg1.setChartTitleTextSize(20);
renderer_eeg1.setLabelsTextSize(15);
renderer_eeg1.setLegendTextSize(15);
renderer_eeg1.setMargins(new int[] {20, 30, 15, 0});
renderer_eeg1.setAxesColor(Color.BLUE);
renderer_eeg1.setXTitle("Time");
renderer_eeg1.setChartTitle("eeg1");
final XYSeriesRenderer seriesrenderer1 = new XYSeriesRenderer();
seriesrenderer1.setColor(Color.YELLOW);
renderer_eeg1.addSeriesRenderer(seriesrenderer1); 
series1= new TimeSeries("eeg1");
eeg1.addSeries(series1);

Thread timer = new Thread(){
    public void run(){
        try{
            for(int r=0;r<=600;r++)
            {
                sleep(500);
                if(r%2==0){
                    a=1;
                    seriesrenderer1.setColor(Color.RED);
                }
                else{
                    a=-1;
                    seriesrenderer1.setColor(Color.YELLOW);
                }
                Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT+1:00"));
                Date dt = cal.getTime();
                series1.add(dt, a);
                if(r<=50){
                    renderer_eeg1.setXAxisMax(50);
                }
                else if(r>50){
                    double maxX = series1.getMaxX();
                    double minX = maxX - 50;
                    renderer_eeg1.setXAxisMin(minX);
                    renderer_eeg1.setXAxisMax(maxX);
                }
                view_eeg1.repaint();

            } }catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } 
        }
    };
timer.start();
}

protected void onResume() {
    super.onResume();  
    if(view_eeg1==null){
    LinearLayout layout_eeg1 = (LinearLayout) findViewById(R.id.chart_container);
     view_eeg1 = (GraphicalView) ChartFactory.getTimeChartView(this, eeg1, renderer_eeg1,"hh:mm:ss");
    layout_eeg1.addView(view_eeg1);}
    else
         view_eeg1.repaint();
        }

}

问题是这段代码挂起并且没有绘制任何东西。我使用了在这里找到的演示代码https://www.box.com/s/65d1c23a01430e206342。我只是将它从 XYSeries 更改为 Timeseries。请帮我解决问题

4

0 回答 0