I use the MPAndroidChart library in my Android graphics application, and I need to display a dialog with a heading containing the selected value bar along the x axis.
I referenced this wiki entry for click events in bars on a bar chart. But now I need to get the selected x-axis value as a header. Can someone tell me how to achieve it?
Use OnChartValueSelectedListener:
OnChartValueSelectedListener
@Override public void onValueSelected(Entry e, Highlight h) { final String x = chart.getXAxis().getValueFormatter().getFormattedValue(e.getX(), chart.getXAxis()); }
Highlight , dataSetIndex, x- y- , ( ),...
Highlight
.
: MPAndroidChart 3.x.x :
chart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() { @Override public void onValueSelected(Entry e, Highlight h) { chart.getXAxis().getValueFormatter().getFormattedValue(e.getX(), chart.getXAxis()); } @Override public void onNothingSelected() { } });
onValueSelected:
public void onValueSelected(Entry e, int dataSetIndex, Highlight h) { int position = e.getXIndex(); Log.d("positin", position ); //XValue final String selectedValue=barchart.getXAxis().getValues().get(position); Log.d("selctdX", selectedValue); //YValue final String selectedYValue = String.valueOf(e.getVal()); Log.d("selctdY", selectedValue); }
, , .
Source: https://habr.com/ru/post/1624722/More articles:What is the main difference between ReactiveCocoa and PromiseKit? - promiseRaw code displayed in all php files - evalGetting information about the line number at the stage of semantic analysis (using Alex, Happy) - compiler-constructionUICollectionView reorders an integral cell - iosHow to get all changes with a given topic from gerrit - gitHow to get the selected x-axis name (rows added to x-axis) using MP Chart? - androidHow to stop Wordpress.com from removing whitespace when copying? - formattingCNContact.imageData not working - cncontactGet gitlab-ci token with gitlab API - gitlabInitial setup of Flask Mega Tutorial on pythonanywhere - pythonAll Articles