使用 aChartEngine 获取饼图切片的值

发布于 2024-12-05 16:36:22 字数 177 浏览 0 评论 0原文

我试图开发一个包含饼图的 Android 应用程序。我使用 aChartEngine 来生成图表,但问题是我无法触摸/单击饼图的特定部分并获取相关数据!有人知道获取这些数据的方法吗? 这是每个图表框架都有的一个简单的东西,但我在 javadoc 上找不到一些可以做到这一点的方法,我想知道这样的东西是否存在。 任何帮助都是宝贵的,提前致谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

莳間冲淡了誓言ζ 2024-12-12 16:36:22

该功能已在1.0.0版本中添加,您可以使用SeriesSelection类获取点索引、系列索引、值和x值。您可以使用 GraphicalView 图表的 getCurrentSeriesAndPoint() 获取一个实例。

  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();
      }
    }
  });

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();
      }
    }
  });
金橙橙 2024-12-12 16:36:22

AChartEngine SVN 中的版本现在包含此功能。

您可以查看执行此操作的代码示例 这里

The version in the AChartEngine SVN contains now this feature.

You can see an example of code doing this here.

Dan

柏林苍穹下 2024-12-12 16:36:22

根据 AChartEngine 作者的说法 - 它还尚未实现:

AChartEngine 讨论组

您可以添加功能请求。

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

AChartEngine discussion group

You can a add a feature request.

情归归情 2024-12-12 16:36:22
    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);
    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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文