我正在使用条形图,我试图在用户点击精确的条形图条目时调用函数,而不是在它周围的任何位置。是否可以限制触摸区域以点击确切的数据?
设置图表属性
mChart.setHighlightPerTapEnabled(true);
mChart.setHighlightPerDragEnabled(false);
mChart.setDoubleTapToZoomEnabled(false);
mChart.getLegend().setEnabled(false);
mChart.setPinchZoom(false);
mChart.getDescription().setEnabled(false);
mChart.getAxisRight().setEnabled(false);
YAxis yAxis = mChart.getAxisLeft();
yAxis.setDrawLabels(false); // no axis labels
yAxis.setDrawAxisLine(false); // no axis line
yAxis.setDrawGridLines(false); // no grid line
yAxis.setDrawZeroLine(true);
yAxis.setAxisMinimum(0f);
设置数据
float barWidth;
float barSpace;
float groupSpace;
barWidth = 0.8f;
barSpace = 0f;
groupSpace = 0f;
ArrayList<BarEntry> yVals1 = new ArrayList<>();
ArrayList<BarEntry> yVals2 = new ArrayList<>();
yVals1.add(new BarEntry(3f, deposit));
yVals2.add(new BarEntry(3f, loan));
BarDataSet set1, set2;
set1 = new BarDataSet(yVals1, "A");
set2 = new BarDataSet(yVals2, "B");
BarData data = new BarData(set1, set2);
mChart.setData(data);
mChart.getBarData().setBarWidth(barWidth);
设置值侦听器
mChart.setOnChartValueSelectedListener(new
OnChartValueSelectedListener() {
@Override
public void onValueSelected(Entry e, Highlight h) {
e.getData();
Log.d("VAL SELECTED",
"Value: " + e.getY() + ", xIndex: " + e.getX()
+ ", DataSet index: " + h.getDataSetIndex());
}
@Override
public void onNothingSelected() {
Log.d("BAR_CHART_SAMPLE", "nothing selected X is ");
}
});