【问题标题】:Displaying plotted AChartEngine graph in separate activity在单独的活动中显示绘制的 AChartEngine 图
【发布时间】:2012-10-22 16:56:56
【问题描述】:

最初尝试使用 Google 的 AChartEngine 绘制图表。但是,我想用后退按钮将它绘制在不同的布局上。到目前为止,我找不到代码有任何问题,但是图表在需要时没有显示。所以我有一个主文件,它启动了启动 ShowGraph 活动的意图。此代码有效,因为它将我带到适当的屏幕。所以问题是图表没有显示在线性布局中,只有按钮显示。您能找到任何建议或错误吗?

buttonConfirm.setOnClickListener(new View.OnClickListener() {

                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    if (radioButtonGraph.isChecked()){
                        Intent sg = new Intent (MainActivity.this, ShowGraph.class);
                        startActivity(sg);

                    }

在显示图形屏幕上,xml 如下所示:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >


   <Button
    android:id="@+id/buttonBackGraph"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:background="@drawable/coolbutton"
    android:text="@string/doneAlarm" >
    </Button>


    <LinearLayout
    android:id="@+id/graphLayout"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" />
 </LinearLayout>

使用此布局的活动有一个按钮,以及对图形函数的调用:

public class ShowGraph extends Activity{
Button buttonDone1;
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.avgraph);
    buttonDone1 = (Button)findViewById(R.id.buttonBackGraph);
    buttonDone1.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent dne = new Intent(ShowGraph.this, MainActivity.class);
            startActivity(dne);
        }
    });
}

public void lineGraphHandler(View view){
    GraphActivity line = new GraphActivity();
    GraphicalView gView = line.getView(getApplicationContext());
    LinearLayout l1 = (LinearLayout)findViewById(R.id.graphLayout);
    l1.addView(gView);
}

}

最后,渲染图形并应该在上面的线性布局中绘制的图形函数:

public class GraphActivity extends Activity {

public GraphicalView getView(Context context){
    //hardcoded plotting data for now
    int[]x = {1,2,3,4,5,6,7,8,9,10};
    int[]y ={130, 150, 358, 200, 90,60, 110, 120, 130, 150};

    TimeSeries series = new TimeSeries ("BGL Data");
    for (int i=0; i<x.length;i++){
        series.add(x[i], y[i]);
    }

    XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
    dataset.addSeries(series);

    XYMultipleSeriesRenderer mrenderer = new XYMultipleSeriesRenderer();
    XYSeriesRenderer renderer = new XYSeriesRenderer();
    mrenderer.addSeriesRenderer(renderer);
    mrenderer.setChartTitle("Blood Glucose Levels Tracking");
    mrenderer.setXTitle("Test Date and Time Reference Number"); //number corresponding to date and time of test
    mrenderer.setXAxisMin(0);
    mrenderer.setXAxisMax(10);
    mrenderer.setYTitle("Blood Glucose Level/ mg/dl");

    return ChartFactory.getLineChartView(context, dataset, mrenderer); 

}
}

【问题讨论】:

  • 它不是“Google 的”AChartEngine。

标签: android button android-linearlayout achartengine


【解决方案1】:

lineGraphHandler 方法不会在任何地方调用。

【讨论】:

  • 谢谢你成功了。我在布局中添加了另一个按钮并设置了一个 onClick 来引用 lineGraphHandler 方法。抱歉,我的意思是说 aChartEngine for Android
猜你喜欢
  • 1970-01-01
  • 2015-01-17
  • 1970-01-01
  • 2012-09-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多