Beispiel #1
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);
  }
    private void drawChart() {
      DefaultRenderer render = new DefaultRenderer();

      CategorySeries incomeSeries = getDataSet();

      for (int i = 0; i < incomeSeries.getItemCount(); i++) {
        SimpleSeriesRenderer incomeSeriesRenderer = new SimpleSeriesRenderer();
        incomeSeriesRenderer.setColor(GraphsHelper.getColorCode(i));
        render.addSeriesRenderer(incomeSeriesRenderer);
      }

      render.setInScroll(true);
      render.setPanEnabled(true);
      render.setClickEnabled(false);
      render.setChartTitleTextSize(26);
      render.setShowLabels(true);
      render.setShowLegend(true);
      render.setShowGrid(true);
      render.setBackgroundColor(Color.BLACK);
      render.setLabelsTextSize(26);
      render.setLabelsColor(Color.BLACK);
      render.setLegendTextSize(26);
      render.setZoomButtonsVisible(true);

      GraphicalView chartView;

      chartView = ChartFactory.getPieChartView(getActivity(), getDataSet(), render);

      LinearLayout layout = (LinearLayout) getActivity().findViewById(R.id.dashboard_chart_layout);
      layout.removeAllViews();
      layout.addView(
          chartView, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT));
    }
  public GraphicalView getView(Context context) {
    List<double[]> values = new ArrayList<double[]>();
    values.add(new double[] {12, 14, 11, 10, 19});
    values.add(new double[] {10, 9, 14, 20, 11});
    List<String[]> titles = new ArrayList<String[]>();
    titles.add(new String[] {"P1", "P2", "P3", "P4", "P5"});
    titles.add(new String[] {"Project1", "Project2", "Project3", "Project4", "Project5"});
    int[] colors = new int[] {Color.BLUE, Color.GREEN, Color.MAGENTA, Color.YELLOW, Color.CYAN};

    DefaultRenderer renderer = buildCategoryRenderer(colors);
    renderer.setApplyBackgroundColor(true);
    renderer.setBackgroundColor(Color.rgb(222, 222, 200));
    renderer.setLabelsColor(Color.GRAY);

    return ChartFactory.getDoughnutChartView(
        context, buildMultipleCategoryDataset("Project budget", titles, values), renderer);
  }
 protected DefaultRenderer BuildCategoryRenderer(int[] colors) {
   DefaultRenderer _Renderer = new DefaultRenderer();
   _Renderer.setZoomButtonsVisible(true);
   _Renderer.setLabelsTextSize(15);
   _Renderer.setLegendTextSize(15);
   _Renderer.setLabelsColor(Color.BLUE);
   _Renderer.setMargins(new int[] {20, 30, 15, 10});
   int _Color = 0;
   for (int i = 0; i < mModelCategoryTotal.size(); i++) {
     SimpleSeriesRenderer _R = new SimpleSeriesRenderer();
     _R.setColor(colors[_Color]);
     _Renderer.addSeriesRenderer(_R);
     _Color++;
     if (_Color > colors.length) {
       _Color = 0;
     }
   }
   return _Renderer;
 }