AChartEngine,点击获取情节值

时间:2011-06-08 03:10:41

标签: java achartengine

我用achartengine编写一个简单的时间表。我想要做的是通过点击图表上的点来获取已经绘制的值,这可能吗?

1 个答案:

答案 0 :(得分:10)

假设mChartView是您的GraphicalView:

mChartView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                  SeriesSelection seriesSelection = mChartView.getCurrentSeriesAndPoint();
                  double[] xy = mChartView.toRealPoint(0);

                  if (seriesSelection == null) {
                    Toast.makeText(GraficoMensile.this, "No chart element was clicked", Toast.LENGTH_SHORT)
                        .show();
                  } else {
                    Toast.makeText(
                            GraficoMensile.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();
                  }
                }
              }); 

源: http://code.google.com/p/achartengine/source/browse/trunk/achartengine/demo/org/achartengine/chartdemo/demo/chart/XYChartBuilder.java