Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Achart engine Onclick pie chart slice not working sometimes a bug?

i am working on a pie chart and i am using AchartEngine.

i have the pie chart like this:

Image of a Pie Chart

i have added the onclick to the slices but sometimes only the green slice onlick will not work.

this is my code:

mChartView = ChartFactory.getPieChartView(this, adc.buildCategoryDataset("Project budget", values), renderer);
        mChartView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              SeriesSelection seriesSelection = mChartView.getCurrentSeriesAndPoint();
              if (seriesSelection == null) {
                  Toast
                      .makeText(GeneratedChartDemo.this, "No chart element was clicked", Toast.LENGTH_SHORT)
                      .show();
                } else {
                  Toast.makeText(
                          GeneratedChartDemo.this,
                      "Chart element data point index " + seriesSelection.getPointIndex()
                          + " was clicked" + " point value=" + seriesSelection.getValue(),
                      Toast.LENGTH_SHORT).show();
                }
            }
          });

where am i going wrong have i missed something?

EDIT

Thanks to Dan who helped me in solving the problem.

like image 669
Goofy Avatar asked Nov 30 '25 14:11

Goofy


1 Answers

Did you add a selectable buffer?

mRenderer.setClickEnabled(true);
mRenderer.setSelectableBuffer(10);

Update: there was a bug that I fixed. You can download a version including this fix here.

like image 64
Dan D. Avatar answered Dec 04 '25 07:12

Dan D.