1
votes

I'm working with MPAndroidChart on my app for drawing line charts, and I need to know the X and Y values of a touched item. My current code is:

chart = (LineChart) findViewById(R.id.weightChart);

chart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() {
    @Override
    public void onValueSelected(Entry e, int dataSetIndex, Highlight h) {
        weights.get(e.getXIndex());
        Log.i("Entry", String.valueOf(e));
        Log.i("dataSetIndex", String.valueOf(dataSetIndex));
        Log.i("Highlight", String.valueOf(h));
    }

    @Override
    public void onNothingSelected() {

    }
});

So that when an iten is touched, dataSetIndex is always 0,

Highlight is: Highlight, xIndex: x value, dataSetIndex: 0, stackIndex (only stacked barentry): -1,

and Entry is: Entry, xIndex: x value val (sum): y value

So, how could I get the X and Y values from the entry without having to format the Entry?

Thanks a lot

1
whether you got solution? - Shadow

1 Answers

0
votes

I know its pretty late to answer this, and you probably already found a work-around to it. But for posterity's sake, here's how I do things when it comes to getting the touched point and it's values;

chart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() {

        @Override
        public void onValueSelected(Entry e, Highlight h) {
            Log.d(TAG, "y value: " + e.getY());
            Log.d(TAG, "x value: " + e.getX());
        }

        @Override
        public void onNothingSelected() {

        }
    });

simple and clean.