I just tried to use achartengine demo, but every time I click on something to show the chart appears an error saying \"The application AChartengine has stopped unexpectedly.
See this for a solution to this: http://groups.google.com/group/achartengine/browse_thread/thread/4cb1efddad3c19d0/2b59e5164e05c469#2b59e5164e05c469
Dan
Quote:
In Eclipse: -> Right click your project - go to build path - select Configure build path -> go to the "Order and Export" tab -> Check the "achartengine-1.0.0.jar box and then single click its name -> move it up so its right below the Android dependancies (sometimes this can make a difference if you have multiple Jars)
click ok then clean your project. (Project -> Clean...)
Try running it again and see if that helps.
if you want to know how achartengine work then add the achartengine 0.7.0 jar to libs folder and link it with your project also have these below activity.
public class GeneratedChartDemo extends ListActivity {
private static final int SERIES_NR = 2;
private String[] mMenuText;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// I know, I know, this should go into strings.xml and accessed using
// getString(R.string....)
mMenuText = new String[] { "Line chart", "Scatter chart", "Time chart", "Bar chart" };
setListAdapter(new SimpleAdapter(this, getListValues(), android.R.layout.simple_list_item_1,
new String[] { "name"}, new int[] { android.R.id.text1 }));
}
private List<Map<String, String>> getListValues() {
List<Map<String, String>> values = new ArrayList<Map<String, String>>();
int length = mMenuText.length;
for (int i = 0; i < length; i++) {
Map<String, String> v = new HashMap<String, String>();
v.put("name", mMenuText[i]);
values.add(v);
}
return values;
}
private XYMultipleSeriesDataset getDemoDataset() {
XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
final int nr = 10;
Random r = new Random();
for (int i = 0; i < SERIES_NR; i++) {
XYSeries series = new XYSeries("Demo series " + (i + 1));
for (int k = 0; k < nr; k++) {
series.add(k, 20 + r.nextInt() % 100);
}
dataset.addSeries(series);
}
return dataset;
}
private XYMultipleSeriesDataset getDateDemoDataset() {
XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
final int nr = 10;
long value = new Date().getTime() - 3 * TimeChart.DAY;
Random r = new Random();
for (int i = 0; i < SERIES_NR; i++) {
TimeSeries series = new TimeSeries("Demo series " + (i + 1));
for (int k = 0; k < nr; k++) {
series.add(new Date(value + k * TimeChart.DAY / 4), 20 + r.nextInt() % 100);
}
dataset.addSeries(series);
}
return dataset;
}
private XYMultipleSeriesDataset getBarDemoDataset() {
XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
final int nr = 10;
Random r = new Random();
for (int i = 0; i < SERIES_NR; i++) {
CategorySeries series = new CategorySeries("Demo series " + (i + 1));
for (int k = 0; k < nr; k++) {
series.add(100 + r.nextInt() % 100);
}
dataset.addSeries(series.toXYSeries());
}
return dataset;
}
private XYMultipleSeriesRenderer getDemoRenderer() {
XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
renderer.setAxisTitleTextSize(16);
renderer.setChartTitleTextSize(20);
renderer.setLabelsTextSize(15);
renderer.setLegendTextSize(15);
renderer.setPointSize(5f);
renderer.setMargins(new int[] {20, 30, 15, 0});
XYSeriesRenderer r = new XYSeriesRenderer();
r.setColor(Color.BLUE);
r.setPointStyle(PointStyle.SQUARE);
r.setFillBelowLine(true);
r.setFillBelowLineColor(Color.WHITE);
r.setFillPoints(true);
renderer.addSeriesRenderer(r);
r = new XYSeriesRenderer();
r.setPointStyle(PointStyle.CIRCLE);
r.setColor(Color.GREEN);
r.setFillPoints(true);
renderer.setXLabels(0);
renderer.addXTextLabel(1, "aga");
renderer.addXTextLabel(2, "agar");
renderer.addSeriesRenderer(r);
renderer.setAxesColor(Color.DKGRAY);
renderer.setLabelsColor(Color.LTGRAY);
return renderer;
}
public XYMultipleSeriesRenderer getBarDemoRenderer() {
XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
renderer.setAxisTitleTextSize(16);
renderer.setChartTitleTextSize(20);
renderer.setLabelsTextSize(15);
renderer.setLegendTextSize(15);
renderer.setMargins(new int[] {20, 30, 15, 0});
SimpleSeriesRenderer r = new SimpleSeriesRenderer();
r.setColor(Color.BLUE);
renderer.addSeriesRenderer(r);
r = new SimpleSeriesRenderer();
r.setColor(Color.GREEN);
renderer.addSeriesRenderer(r);
return renderer;
}
private void setChartSettings(XYMultipleSeriesRenderer renderer) {
renderer.setChartTitle("Chart demo");
renderer.setXTitle("x values");
renderer.setYTitle("y values");
renderer.setXAxisMin(0);
renderer.setXAxisMax(5);
renderer.setYAxisMin(0);
renderer.setYAxisMax(250);
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
switch (position) {
case 0:
Intent intent = ChartFactory.getLineChartIntent(this, getDemoDataset(), getDemoRenderer());
startActivity(intent);
break;
case 1:
intent = ChartFactory.getScatterChartIntent(this, getDemoDataset(), getDemoRenderer());
startActivity(intent);
break;
case 2:
intent = ChartFactory.getTimeChartIntent(this, getDateDemoDataset(), getDemoRenderer(), null);
startActivity(intent);
break;
case 3:
XYMultipleSeriesRenderer renderer = getBarDemoRenderer();
setChartSettings(renderer);
intent = ChartFactory.getBarChartIntent(this, getBarDemoDataset(), renderer, Type.DEFAULT);
startActivity(intent);
break;
}
}
}