嗨,我正在使用 achartengine 的饼图来表示我的实际销售额,现在当我的应用程序启动时,饼图中的图表元素之一应该会突出显示,就像我们在饼图上执行 onclick 时一样。
下面是我的饼图的代码
final DefaultRenderer renderer = buildCategoryRenderer(colors);
renderer.setPanEnabled(false);// Disable User Interaction
renderer.setLabelsColor(Color.BLACK);
renderer.setShowLegend(true);
renderer.setLegendTextSize(20);
renderer.setInScroll(true);
renderer.setStartAngle(180);
renderer.setChartTitle("Sales By Market Segment- Month");
renderer.setLabelsTextSize(22);
final CategorySeries categorySeries = new CategorySeries("Sales");
categorySeries.add("Craft1", cursor.getInt(1));
categorySeries.add("product1", cursor.getInt(2) );
categorySeries.add("product2", cursor.getInt(3) );
categorySeries.add("product", cursor.getInt(4));
categorySeries.add("product1", cursor.getInt(5));
mChartView2=ChartFactory.getPieChartView(context, categorySeries,renderer);
parent.addView(mChartView2);
renderer.setClickEnabled(true);
mChartView2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SeriesSelection seriesSelection = mChartView2.getCurrentSeriesAndPoint();
if (seriesSelection == null) {
Toast.makeText(getActivity(), "No chart element selected", Toast.LENGTH_SHORT)
.show();
}else {
for (int i = 0; i < categorySeries.getItemCount(); i++) {
renderer.getSeriesRendererAt(i).setHighlighted(i == seriesSelection.getPointIndex());
}
mChartView2.repaint();
Toast.makeText(
getActivity(),
"Chart data point index " + seriesSelection.getPointIndex() + " selected"
+ " point value=" + seriesSelection.getValue(), Toast.LENGTH_SHORT).show();
}
}
});
return ChartFactory.getPieChartIntent(context, categorySeries, renderer,null);
}
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;
}
单击时产品会突出显示,但我想在应用启动时突出显示一个产品。