我正在尝试通过从我的 sqlite 数据库中获取数据来创建饼图。我希望饼图显示朋友姓名和朋友支出。饼图应该根据朋友的消费来划分。我在这里做错了什么?请指导我。谢谢。
这是我的饼图代码:
public class PieChart {
public Intent getIntent(Context context,String eventId){
EventController controller = new EventController(context);
// this is my data of performance; data is collected in array.
HashMap<String, String> queryValues = new HashMap<String, String>();
queryValues.put("eventId", eventId);
ArrayList <HashMap<String,String>> getData = controller.getAllFriends(queryValues);
CategorySeries series = new CategorySeries("pie"); // adding series to charts.
int colorcode = -13959039;
ArrayList<String> coloring = new ArrayList<String>();
for (int a=0; a<getData.size();a++){
String friendName = null;
double friendSpend = 0;
HashMap<String, String> ValexpenseId = getData.get(a);
for (Entry<String, String> entry : ValexpenseId.entrySet()) {
String key = entry.getKey();
if (key.equals("friendName")){
String value = entry.getValue();
friendName = value;
}
else if (key.equals("friendSpending")){
String value = entry.getValue();
double friendSpending = Double.parseDouble(value);
friendSpend = friendSpending;
}
series.add(friendName,friendSpend);
coloring.add(String.valueOf(colorcode));
colorcode = colorcode + 1000000;
}
}
// set style for series
DefaultRenderer renderer = new DefaultRenderer();
for(String color : coloring){
SimpleSeriesRenderer r = new SimpleSeriesRenderer();
int colour = Integer.parseInt(color);
r.setColor(colour);
r.setDisplayBoundingPoints(true);
r.setDisplayChartValuesDistance(5);
r.setDisplayChartValues(true);
r.setChartValuesTextSize(15);
renderer.addSeriesRenderer(r);
}
renderer.isInScroll();
renderer.setZoomButtonsVisible(true); //set zoom button in Graph
renderer.setApplyBackgroundColor(true);
renderer.setBackgroundColor(Color.BLACK); //set background color
renderer.setChartTitle("Efforts");
renderer.setChartTitleTextSize((float) 30);
renderer.setShowLabels(true);
renderer.setLabelsTextSize(20);
renderer.setLegendTextSize(25);
renderer.setDisplayValues(true);
return ChartFactory.getPieChartIntent(context, series, renderer, "PieChart");
}
原木猫:
11-15 15:03:33.985: E/AndroidRuntime(24170): FATAL EXCEPTION: main
11-15 15:03:33.985: E/AndroidRuntime(24170): java.lang.NullPointerException
11-15 15:03:33.985: E/AndroidRuntime(24170): at org.achartengine.chart.AbstractChart.getFitText(AbstractChart.java:405)
11-15 15:03:33.985: E/AndroidRuntime(24170): at org.achartengine.chart.AbstractChart.drawLabel(AbstractChart.java:483)
11-15 15:03:33.985: E/AndroidRuntime(24170): at org.achartengine.chart.PieChart.draw(PieChart.java:134)
11-15 15:03:33.985: E/AndroidRuntime(24170): at org.achartengine.GraphicalView.onDraw(GraphicalView.java:168)
11-15 15:03:33.985: E/AndroidRuntime(24170): at android.view.View.draw(View.java:13877)
11-15 15:03:33.985: E/AndroidRuntime(24170): at android.view.View.getDisplayList(View.java:12811)
11-15 15:03:33.985: E/AndroidRuntime(24170): at android.view.View.getDisplayList(View.java:12859)
11-15 15:03:33.985: E/AndroidRuntime(24170): at android.view.View.draw(View.java:13593)
11-15 15:03:33.985: E/AndroidRuntime(24170): at android.view.ViewGroup.drawChild(ViewGroup.java:2954)
11-15 15:03:33.985: E/AndroidRuntime(24170): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2815)
11-15 15:03:33.985: E/AndroidRuntime(24170): at android.view.View.draw(View.java:13880)
11-15 15:03:33.985: E/AndroidRuntime(24170): at android.widget.FrameLayout.draw(FrameLayout.java:467)
11-15 15:03:33.985: E/AndroidRuntime(24170): at android.view.View.getDisplayList(View.java:12811)