嗨,我是 android 新手,我正在开发一个应用程序来使用 achartengine 显示前 10 个旅游目的地。问题是我正在使用生成的随机值来绘制图表。我需要的是连接使用 sqlite 数据浏览器创建的数据库来绘制图形。我正在按照以下教程绘制图表http://www.youtube.com/watch?v=E9fozQ5NlSo。但是我没有找到很多关于如何连接数据库来绘制条形图的教程。请张贴以上任何链接。
package flu.solutions.travelsense;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import org.achartengine.ChartFactory;
import org.achartengine.chart.BarChart.Type;
import org.achartengine.model.CategorySeries;
import org.achartengine.model.XYMultipleSeriesDataset;
import org.achartengine.renderer.SimpleSeriesRenderer;
import org.achartengine.renderer.XYMultipleSeriesRenderer;
import org.achartengine.renderer.XYMultipleSeriesRenderer.Orientation;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Menu;
public class ChartActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
XYMultipleSeriesRenderer renderer = getBarDemoRenderer();
setChartSettings(renderer);
Intent intent = ChartFactory.getBarChartIntent(this, getBarDemoDataset(), renderer, Type.DEFAULT);
startActivity(intent);
}
public Intent createIntent()
{
String[] titles = new String[] { "Top 10 Destinations", " " };
List<double[]> values = new ArrayList<double[]>();
values.add(new double[] { 8, 6, 4, 6, 7, 7, 9, 5, 7, 8, 8 });
values.add(new double[] {});
int[] colors = new int[] { Color.RED, Color.BLACK};
XYMultipleSeriesRenderer renderer = buildBarRenderer(colors);
renderer.setOrientation(Orientation.HORIZONTAL);
setChartSettings(renderer);
renderer.setXLabels(1);
renderer.setYLabels(10);
renderer.addXTextLabel(1, "Bangalore");
renderer.addXTextLabel(2, "Mysore");
renderer.addXTextLabel(3, "Chennai");
renderer.addXTextLabel(4, "Delhi");
renderer.addXTextLabel(5, "Kolkatta");
renderer.addXTextLabel(6, "Kashmir");
renderer.addXTextLabel(7, "Hyderabad");
renderer.addXTextLabel(8, "Mumbai");
renderer.addXTextLabel(9, "Kerala");
renderer.addXTextLabel(10, "Gujarat");
int length = renderer.getSeriesRendererCount();
for (int i = 0; i < length; i++)
{
SimpleSeriesRenderer seriesRenderer = renderer.getSeriesRendererAt(i);
seriesRenderer.setDisplayChartValues(false);
}
return ChartFactory.getBarChartIntent(this, buildBarDataset(titles, values), renderer,Type.DEFAULT);
}
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 XYMultipleSeriesDataset getBarDemoDataset() {
XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
final int nr = 10;
Random r = new Random();
int SERIES_NR = 2;
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 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);
}
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_chart, menu);
return true;
}
}
你能告诉我我在这里做错了什么吗?