我正在开发一个应用程序,我必须显示饼图,我将achartengine lib导入我的应用程序.Achartengine的演示版本工作正常它显示图表。但是我使用它进入我的应用程序什么都不会显示。任何人帮助我来解决这个问题。
这是我的代码:
主要活动:
public class HomeScreenPage extends Activity {
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.homescreenpage);
PieChart achartIntent = new PieChart();
achartIntent.execute(this);
}
Piechart课程:
import org.achartengine.ChartFactory;
import org.achartengine.model.CategorySeries;
import org.achartengine.renderer.DefaultRenderer;
import org.achartengine.renderer.SimpleSeriesRenderer;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
public class PieChart {
public Intent execute(Context context) {
double[] values = new double[] {12, 14, 11, 10,2};
int[] colors = new int[] {Color.BLUE, Color.GREEN, Color.MAGENTA, Color.YELLOW, Color.CYAN};
DefaultRenderer renderer = buildCategoryRenderer(colors);
renderer.setLabelsTextSize(10);
return ChartFactory.getPieChartIntent(context, buildCategoryDataset("Project budget", values), renderer);
}
protected DefaultRenderer buildCategoryRenderer(int[] colors) {
DefaultRenderer renderer = new DefaultRenderer();
for (int color : colors) {
SimpleSeriesRenderer r = new SimpleSeriesRenderer();
r.setColor(color);
renderer.addSeriesRenderer(r);
}
return renderer;
}
protected CategorySeries buildCategoryDataset(String title, double[] values) {
CategorySeries series = new CategorySeries(title);
int k = 0;
for (double value : values) {
series.add("Project " + ++k, value);
}
return series;
}
}
答案 0 :(得分:2)
你做了这一切吗
1:on onCreate()
Intent achartIntent = new PieChart().execute(this);
startActivity(achartIntent);
2:在AndroidManifest.xml中添加到以下行
<activity android:name="org.achartengine.GraphicalActivity">
3:在项目的构建路径中添加了achart。*。jar作为参考库
答案 1 :(得分:0)
你最好在main中使用.execute函数后启动活动,如下所示: startActivity(new PieChart()。execute(this));