AChartEngine, getting values of plots on click

血红的双手。 提交于 2020-01-13 10:48:10

问题


I used achartengine for coding a simple time chart. What I want to do is get the values that are already plotted by clicking on the point on the graph, is this possible?


回答1:


Assuming that mChartView is your 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();
                  }
                }
              }); 

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



来源:https://stackoverflow.com/questions/6273796/achartengine-getting-values-of-plots-on-click

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!