Achartengine动态情节不起作用

时间:2012-12-20 06:18:03

标签: android achartengine

我正在使用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。请帮我弄清楚问题

0 个答案:

没有答案