コード例 #1
0
 private void addSliceToPie(String title, double value) {
   mSeries.add(title, value);
   SimpleSeriesRenderer renderer = new SimpleSeriesRenderer();
   renderer.setColor(COLORS[(mSeries.getItemCount() - 1) % COLORS.length]);
   mRenderer.addSeriesRenderer(renderer);
 }
コード例 #2
0
  private void setupChart(Typeface typeface) {
    LinearLayout chartLayout = (LinearLayout) findViewById(R.id.ll_grade_chart);
    LayoutParams params = chartLayout.getLayoutParams();
    if (originalHeightChartLayout < 0) {
      originalHeightChartLayout = params.height;
    }
    if (mGrade.nr_avaliations > 0) {
      params.height = originalHeightChartLayout;
      chartLayout.setLayoutParams(params);
      mRenderer = new LabelPercentRenderer();
      mSeries = new LabelCategorySeries(getString(R.string.concepts));

      mChartView = HelpChartFactory.getLabelPercentPieChartView(this, mSeries, mRenderer);

      mRenderer.setZoomButtonsVisible(false);
      mRenderer.setDisplayValues(false);
      mRenderer.setDisplayValuesAsPercent(false);
      mRenderer.setAntialiasing(true);
      mRenderer.setInScroll(false);

      mRenderer.setShowLabels(true);
      mRenderer.setShowLegend(false);

      mRenderer.setOnlyPercentToLabel(false);
      mRenderer.setAppendPercentToLabel(true);
      mRenderer.setTextTypeface(typeface);
      mRenderer.setClickEnabled(false);

      int size =
          (int)
              TypedValue.applyDimension(
                  TypedValue.COMPLEX_UNIT_SP, 12, getResources().getDisplayMetrics());
      mRenderer.setLabelsTextSize(size);
      mRenderer.setLegendTextSize(size);

      mRenderer.setLabelsColor(getResources().getColor(android.R.color.black));
      String titleBase = getString(R.string.concept);
      if (mGrade.nr_A > 0) {
        addSliceToPie(titleBase + " A: ", mGrade.nr_A);
      }
      if (mGrade.nr_B > 0) {
        addSliceToPie(titleBase + " B: ", mGrade.nr_B);
      }
      if (mGrade.nr_C > 0) {
        addSliceToPie(titleBase + " C: ", mGrade.nr_C);
      }
      if (mGrade.nr_D > 0) {
        addSliceToPie(titleBase + " D: ", mGrade.nr_D);
      }

      mChartView.repaint();
      chartLayout.removeAllViews();
      chartLayout.addView(
          mChartView, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    } else {
      params.height = 0;
      chartLayout.setLayoutParams(params);
    }
  }