如何使用MPAndroidChart获取选定的条形X轴值? [英] How to get selected bar x-axis value using MPAndroidChart?
问题描述
我正在Android图形应用程序中使用 MPAndroidChart 库,我需要使用包含所选栏的x轴值的标题.
I am using the MPAndroidChart library in my Android graphs app and I need to display the dialog with a title containing the selected bar's x-axis values.
我在点击事件中引用了 Wiki条目到条形图中的条形.但是现在我需要获取选定的条形x轴值作为标题.有人可以告诉我如何实现吗?
I referred to this wiki entry for click events to the bars in the bar graph. But now I need to get the selected bar x-axis value as a title. Can any one tell me how to achieve it?
推荐答案
使用OnChartValueSelectedListener
:
@Override
public void onValueSelected(Entry e, Highlight h) {
final String x = chart.getXAxis().getValueFormatter().getFormattedValue(e.getX(), chart.getXAxis());
}
Highlight
对象包含有关所选位置的其他信息,例如dataSetIndex,所选值的x和y位置(以像素为单位),所选堆栈值(在堆叠的条形图中) ),...
The Highlight
object contains additional information regarding the selected position, such as the dataSetIndex, x- and y-position of the selected value in pixels, the selected stack value (in stacked bar chart), ...
还可以查看 高亮值的文档 .
Also hava a look at the documentation of highlighting values.
这篇关于如何使用MPAndroidChart获取选定的条形X轴值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!