Android 通过单击一个条来获取Y值
我正在使用Achartengine在我的Android应用程序中创建一个条形图。我需要的是,如果用户点击一个条,那么他就得到了Yaxis的值。出于某种原因,我不想使用此选项:Android 通过单击一个条来获取Y值,android,bar-chart,achartengine,Android,Bar Chart,Achartengine,我正在使用Achartengine在我的Android应用程序中创建一个条形图。我需要的是,如果用户点击一个条,那么他就得到了Yaxis的值。出于某种原因,我不想使用此选项: renderer.setDisplayChartValues(true); 我写了这篇文章,但它不起作用: final GraphicalView mChartView; mChartView = ChartFactory.getBarChartView(context, dataset, mRender
renderer.setDisplayChartValues(true);
我写了这篇文章,但它不起作用:
final GraphicalView mChartView;
mChartView = ChartFactory.getBarChartView(context, dataset, mRenderer, Type.DEFAULT);
mChartView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
// handle the click event on the chart
SeriesSelection seriesSelection = mChartView.getCurrentSeriesAndPoint();
if (seriesSelection != null) {
// Getting the y value after clicking BAR
int amount = (int) seriesSelection.getValue();
Log.i("point: ", "is "+amount);
}
mChartView.repaint();
}
});
我还将以下内容添加到我的多重渲染器中:
mRenderer.setClickEnabled(true);
mRenderer.setSelectableBuffer(30);
尝试将
类型替换为null
。我不知道为什么,但这似乎是我尝试使用bcoz的原因,也可以参见mChart.toRealPoint
thing
mChart.setOnClickListener(new View.OnClickListener(){
public void onClick(View v)
{
System.out.println("X :" + mChart.toRealPoint(0)[0]);
System.out.println("Y:" + mChart.toRealPoint(0)[1]);
SeriesSelection seriesSelection = mChart.getCurrentSeriesAndPoint();
if (seriesSelection != null) {
// Getting the y value after clicking BAR
int amount = (int) seriesSelection.getValue();
Log.i("point: ", "is "+amount);
}
mChart.repaint();
}
});
chartLayout.addView(mChart);
seriesSelection.getValue()是Y值,但将其转换为int-amount=seriesSelection.getValue.intValue()需要加倍;如果我写了你的行,我会得到一个错误。但是这里的问题是,我没有得到日志上的值。是的,很抱歉,看看这里