本文介绍了Android的achartEngine如何突出特定的图表元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用achartengine的饼图重新present我的实际销量,现在为我的应用程序启动图表元素在饼图中的一个应该得到强调的,当我们做饼图上的onclick等。

Hi i am using achartengine's pie-chart to represent my actual sales, now as my app starts one of the chart element in the piechart should get highlighted, like when we do the onclick on pie chart.

下面是code为我的饼图

Below is the code for my piechart

final DefaultRenderer renderer = buildCategoryRenderer(colors);
       renderer.setPanEnabled(false);// Disable User Interaction
       renderer.setLabelsColor(Color.BLACK);
       renderer.setShowLegend(true);
       renderer.setLegendTextSize(20);
       renderer.setInScroll(true);
       renderer.setStartAngle(180);

     renderer.setChartTitle("Sales By Market Segment- Month");
       renderer.setLabelsTextSize(22);
      final CategorySeries categorySeries = new CategorySeries("Sales");
       categorySeries.add("Craft1",  cursor.getInt(1));
             categorySeries.add("product1", cursor.getInt(2) );
              categorySeries.add("product2",  cursor.getInt(3) );
              categorySeries.add("product",  cursor.getInt(4));
              categorySeries.add("product1", cursor.getInt(5));

      mChartView2=ChartFactory.getPieChartView(context, categorySeries,renderer);
      parent.addView(mChartView2);
      renderer.setClickEnabled(true);
      mChartView2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              SeriesSelection seriesSelection = mChartView2.getCurrentSeriesAndPoint();
              if (seriesSelection == null) {
                Toast.makeText(getActivity(), "No chart element selected", Toast.LENGTH_SHORT)
                    .show();
              }else {
                  for (int i = 0; i < categorySeries.getItemCount(); i++) {
                      renderer.getSeriesRendererAt(i).setHighlighted(i == seriesSelection.getPointIndex());
                    }
                  mChartView2.repaint();
                    Toast.makeText(
                        getActivity(),
                        "Chart data point index " + seriesSelection.getPointIndex() + " selected"
                            + " point value=" + seriesSelection.getValue(), Toast.LENGTH_SHORT).show();
                  }
                }
              });
      return ChartFactory.getPieChartIntent(context, categorySeries, renderer,null);
     }
     protected DefaultRenderer buildCategoryRenderer(int[] colors) {
      DefaultRenderer renderer = new DefaultRenderer();
      for (int color : colors) {
      SimpleSeriesRenderer r = new SimpleSeriesRenderer();
      r.setColor(color);
      renderer.addSeriesRenderer(r);

      }
      return renderer;
      }

当点击

产品越来越突出,但我想强调一个产品,应用程序启动时。

products are getting highlighted when clicking but I want to highlight one product, when app starts.

推荐答案

找到了解决办法:

 mChartView2=ChartFactory.getPieChartView(context, categorySeries,renderer);
      parent.addView(mChartView2);
      renderer.getSeriesRendererAt(0).setHighlighted(true);
      mChartView2.repaint();

这篇关于Android的achartEngine如何突出特定的图表元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 14:50