我正在尝试在 eclipse/android Sdk 中创建一个图表,我正在逐步遵循不同的教程,但是在任何地方我都有同样的问题,该图表不想显示(我没有错误,我可以编译我的程序)。目前我正在使用 AChartEngine 库。有什么建议么?
package com.example.linegraph;
import org.achartengine.ChartFactory;
import org.achartengine.model.TimeSeries;
import org.achartengine.model.XYMultipleSeriesDataset;
import org.achartengine.renderer.XYMultipleSeriesRenderer;
import org.achartengine.renderer.XYSeriesRenderer;
import android.content.Context;
import android.content.Intent;
public class LineGraph {
public Intent getIntent (Context context)
{
int[] x={1,2,3,4,5,6,7,8,9,10};
int[]y={11,22,33,44,55,66,77,88,99,11};
TimeSeries series =new TimeSeries("Line1");
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);
Intent intent=ChartFactory.getLineChartIntent(context, dataset, mRenderer,"Line Graph Title");
return intent;
}
}
MainActivity 如下
package com.example.linegraph;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void lineGraphHandler (View view){
LineGraph line= new LineGraph();
Intent lineIntent=line.getIntent(this);
startActivity(lineIntent);
}
}
布局xml如下。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
</RelativeLayout>
是的,这段代码应该显示图有教程上的链接-> https://www.youtube.com/watch?v=-ThKImy6PPM 其他东西,比如文本视图,除了图,也许我需要安装一些额外的功能?