private View createPieChart() {
   String[] code = new String[] {"eclair", "froyo"};
   double[] distribution = {20.0, 40.0};
   int[] color = {Color.WHITE, getResources().getColor(R.color.button_signup_color)};
   CategorySeries distributionSeries = new CategorySeries("Top Blocked Number");
   for (int i = 0; i < distribution.length; i++) {
     distributionSeries.add(code[i], distribution[i]);
   }
   DefaultRenderer defaultRenderer = new DefaultRenderer();
   for (int i = 0; i < distribution.length; i++) {
     SimpleSeriesRenderer seriesRenderer = new SimpleSeriesRenderer();
     seriesRenderer.setColor(color[i]);
     seriesRenderer.setShowLegendItem(false);
     defaultRenderer.addSeriesRenderer(seriesRenderer);
   }
   defaultRenderer.setDisplayValues(false);
   defaultRenderer.setShowLabels(false);
   defaultRenderer.setPanEnabled(false);
   defaultRenderer.setZoomEnabled(false);
   /*defaultRenderer.setChartTitle("Top Blocked Number");
   defaultRenderer.setChartTitleTextSize(20F);
   defaultRenderer.setDisplayValues(true);
   */
   return ChartFactory.getPieChartView(
       getActivity().getApplicationContext(), distributionSeries, defaultRenderer);
 }
Example #2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_pie_chart);
    // getActionBar().setDisplayHomeAsUpEnabled(true);

    final Context mContext = this;
    mRenderer.setApplyBackgroundColor(true);
    // mRenderer.setBackgroundColor(Color.argb(100, 80, 80, 50));
    mRenderer.setChartTitleTextSize(15);
    mRenderer.setLabelsTextSize(20);
    mRenderer.setLabelsColor(color.black);
    mRenderer.setDisplayValues(true);
    mRenderer.setLabelsColor(Color.BLACK);
    mRenderer.setLegendTextSize(20);
    mRenderer.setShowLabels(true);
    mRenderer.setMargins(new int[] {20, 30, 15, 0});
    mRenderer.setZoomButtonsVisible(true);
    mRenderer.setStartAngle(180);

    Calendar d = new GregorianCalendar();

    int yr = d.get(Calendar.YEAR);

    if (yr > 99) {
      mdate = d.get(Calendar.DATE) + "/" + d.get(Calendar.MONTH) + "/20" + (yr % 100);
    } else {
      mdate = d.get(Calendar.DATE) + "/" + d.get(Calendar.DAY_OF_MONTH) + "/19" + (yr % 100);
    }
    System.out.println("date is " + mdate);
    drawPieForSpecificDate();
    editText_specificDate = (EditText) this.findViewById(R.id.editText_specificDate);
    editText_specificDate.setCursorVisible(false);
    editText_specificDate.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            // custom dialog
            flag = 1;

            final Calendar c = Calendar.getInstance();
            year = c.get(Calendar.YEAR);
            month = c.get(Calendar.MONTH);
            day = c.get(Calendar.DAY_OF_MONTH);
            DatePickerDialog datePickerDialog =
                new DatePickerDialog(mContext, PieChart_lower.this, year, month, day);

            datePickerDialog.show();
            flag = 1;
          }
        }); // button_specificDate setListener

    if (flag == 1) drawPieForSpecificDate();

    Button button_specificMonth = (Button) this.findViewById(R.id.button_specificMonth);
    alert = new AlertDialog.Builder(this);

    button_specificMonth.setVisibility(View.GONE);
  }