Jean
Jean

Reputation: 2625

AChartEngine : how recognise touch in line chart?

In my android app I am trying to add touch to a line chart using AChartEngine. I used this simple example:

I added a click listener to the graph

this.graphView = ChartFactory.getLineChartView(this, this.graphDataset,
        this.graphRenderer);
....

this.graphView.setOnClickListener(buttonClickListenerGraph);

and within the buttonClickListenerGraph method I am doing this:

SeriesSelection seriesSelection = this.graphView.getCurrentSeriesAndPoint();
if (seriesSelection == null) {
  Toast.makeText(this, "No chart element", Toast.LENGTH_SHORT).show();
} else {
  // display information of the clicked point
  Toast.makeText(
      this,
      "Chart element in series index " + seriesSelection.getSeriesIndex()
          + " data point index " + seriesSelection.getPointIndex() + " was clicked"
          + " closest point value X=" + seriesSelection.getXValue() + ", Y="
          + seriesSelection.getValue(), Toast.LENGTH_SHORT).show();
}

I also enabled click

this.graphRenderer.setClickEnabled(true);

where graphRenderer is XYMultipleSeriesRenderer.

But this always returns "no chart element" toast on touch. Why is it not recognising the series and line? Can someone please help?

Upvotes: 2

Views: 451

Answers (1)

Dan D.
Dan D.

Reputation: 32391

You can control the "selectable buffer" of the clickable point, which means, the half the side of a square centered in the clicked point. AChartEngine will search over the entire square area to find a candidate for a clickable point and return the closest one.

mRenderer.setSelectableBuffer(circleRadiusInPixels);

Upvotes: 2

Related Questions