pie chart not displayed in my application ,am using achartengine library for graph?
Am developing one apps in this i have to display pie chart , Am importing achartengine lib into my apps .the demo version of achartengine work fine it show the graph .But wen i use that into my apps nothing will displaying.anybody help me to solve this problem.
This is my code:
Main Activity:
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 class :
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;
}
}
Did you do all this
1:on your onCreate()
Intent achartIntent = new PieChart().execute(this);
startActivity(achartIntent);
2: added below line in AndroidManifest.xml
<activity android:name="org.achartengine.GraphicalActivity">
3:Added the achart.*.jar as a reference library in your project's build path
You better start the activity after used .execute function in main, like this: startActivity(new PieChart().execute(this));
精彩评论