yugidroid
yugidroid

Reputation: 6690

get pie chart slice's value using aChartEngine

I was trying to develop an android app which contains a pie chart. I used aChartEngine to generate the graph but the thing is that I can't touch/ click a specific slice of the pie and get related data! Does someone knows a way to get that data? It's a simple thing that every chart framework has but I can't find on javadoc some method that could do it and I'm wondering if such thing exists. Any help would be precious, thanks in advance.

Upvotes: 1

Views: 1916

Answers (4)

krunal patel
krunal patel

Reputation: 2499

    mChartView = ChartFactory.getPieChartView(getActivity(),mSeries,mRenderer);

            mChartView.setOnClickListener(new View.OnClickListener() { 
                @Override
                public void onClick(View v) {
                    SeriesSelection seriesSelection =mChartView.getCurrentSeriesAndPoint();
                    if (seriesSelection == null) {

                    } else {
                        for (int i = 0; i <mSeries.getItemCount(); i++) {
                            mRenderer.getSeriesRendererAt(i).setHighlighted(i == seriesSelection.getPointIndex());
                        }
                        mChartView.repaint();
                        // Toast.makeText( getActivity(), "Chart data point index " + seriesSelection.getPointIndex() + " selected" + " point value=" + seriesSelection.getValue(), Toast.LENGTH_SHORT).show();
                    }
                }
            });
            mRenderer.setClickEnabled(true);

Upvotes: 0

Ali Samz
Ali Samz

Reputation: 161

This feature has been added in version 1.0.0, you can get point-index, series indes, value and x-value using SeriesSelection class. you can get an instance using getCurrentSeriesAndPoint() of your GraphicalView chart.

  mChartView = ChartFactory.getPieChartView(this, mSeries, mRenderer);
  mRenderer.setClickEnabled(true);
  mRenderer.setSelectableBuffer(10);
  mChartView.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
      SeriesSelection seriesSelection = mChartView.getCurrentSeriesAndPoint();
      if (seriesSelection == null) {
        Toast
            .makeText(PieChartBuilder.this, "No chart element was clicked",
      Toast.LENGTH_SHORT)
            .show();
      } else {
        Toast.makeText(
            PieChartBuilder.this,
            "Chart element data point index " + seriesSelection.getPointIndex()
                + " was clicked" + " point value=" + seriesSelection.getValue(),
            Toast.LENGTH_SHORT).show();
      }
    }
  });

Upvotes: 2

Dan D.
Dan D.

Reputation: 32391

The version in the AChartEngine SVN contains now this feature.

You can see an example of code doing this here.

Dan

Upvotes: 1

Harald Wilhelm
Harald Wilhelm

Reputation: 6716

According to the AChartEngine author - it's not implemented yet:

AChartEngine discussion group

You can a add a feature request.

Upvotes: 0

Related Questions