是否有任何具有向下钻取功能的图表库?(可点击事件)。我已经在 Achartengine 中使用 onTouch 进行了尝试,但我无法获得 SeriesSelection,它总是抛出 null。我使用的代码片段:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.barchart_show);
barLayout = (LinearLayout) findViewById(R.id.barchart_main);
stBarChart = new StackedBarChart();
List<double[]> values = new ArrayList<double[]>();
values.add(new double[] { 14230, 12300, 14240, 15244, 15900, 19200, 22030, 21200, 19500, 15500,
12600, 14000 });
values.add(new double[] { 5230, 7300, 9240, 10540, 7900, 9200, 12030, 11200, 9500, 10500,
11600, 13500 });
barChartView = stBarChart.execute(values, getApplicationContext());
if(barChartView!=null) {
barChartView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
SeriesSelection seriesSelection = barChartView.getCurrentSeriesAndPoint();
double[] xy = barChartView.toRealPoint(0);
if (seriesSelection == null) {
Toast.makeText(BarChartShow.this, "No chart element was clicked", Toast.LENGTH_SHORT)
.show();
} else {
Toast.makeText(
BarChartShow.this,
"Chart element in series index " + seriesSelection.getSeriesIndex()
+ " data point index " + seriesSelection.getPointIndex() + " was clicked"
+ " closest point value X=" + seriesSelection.getXValue() + ", Y=" + seriesSelection.getValue()
+ " clicked point value X=" + (float) xy[0] + ", Y=" + (float) xy[1], Toast.LENGTH_SHORT).show();
}
return true;
}
});
barLayout.addView(barChartView, new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
}
}
公共图形视图执行(列表值,上下文上下文){
String[] titles = new String[] { "2008", "2007" };
int[] colors = new int[] { Color.BLUE, Color.CYAN };
XYMultipleSeriesRenderer renderer = buildBarRenderer(colors);
renderer.setOrientation(Orientation.VERTICAL);
setChartSettings(renderer, "Monthly sales in the last 2 years", "Month", "Units sold", 0.5,
12.5, 0, 24000, Color.GRAY, Color.LTGRAY);
renderer.getSeriesRendererAt(0).setDisplayChartValues(true);
renderer.getSeriesRendererAt(1).setDisplayChartValues(true);
//renderer.getSeriesRendererAt(2).setDisplayChartValues(true);
renderer.setXLabels(12);
renderer.setYLabels(10);
renderer.setXLabelsAlign(Align.LEFT);
renderer.setYLabelsAlign(Align.LEFT);
renderer.setPanEnabled(true, false);
// renderer.setZoomEnabled(false);
renderer.setZoomRate(1.1f);
renderer.setBarSpacing(0.5f);
renderer.setClickEnabled(true);
barChartView = ChartFactory.getBarChartView(context, buildBarDataset(titles, values),
renderer, Type.STACKED);
return barChartView;
}