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);
 }
示例#2
0
  void drawPieForSpecificMonth(String month) {

    DatabaseHandler db = new DatabaseHandler(this);
    List<Finance> list = db.getmonthRecords(month);
    textView1 = (TextView) this.findViewById(R.id.textView1);

    if (databaseflag == 0) {
      if (mRenderer != null) mRenderer.removeAllRenderers();
      if (mSeries != null) mSeries.clear();
    }
    if (!list.isEmpty()) {

      databaseflag = 0;
      for (int i = 0; i < list.size(); i++) {

        Finance f = list.get(i);

        mSeries.add("" + f.getCategory(), f.getExpense());

        SimpleSeriesRenderer renderer = new SimpleSeriesRenderer();

        renderer.setColor(COLORS[(mSeries.getItemCount() - 1) % COLORS.length]);
        mRenderer.addSeriesRenderer(renderer);

        if (mChartView != null) {
          mChartView.repaint();

          textView1.setText("");
        }
      }
    } else {
      if (mChartView != null) mChartView.repaint();
      textView1.setText("Hey you have not added any data\n\t\tfor this month");
    }
  }
    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));
    }
示例#4
0
 /**
  * Builds a category renderer to use the provided colors.
  *
  * @param colors the colors
  * @return the category renderer
  */
 public DefaultRenderer buildCategoryRenderer(int[] colors) {
   DefaultRenderer renderer = new DefaultRenderer();
   renderer.setLabelsTextSize(15);
   renderer.setLegendTextSize(15);
   renderer.setMargins(new int[] {20, 30, 15, 0});
   for (int color : colors) {
     SimpleSeriesRenderer r = new SimpleSeriesRenderer();
     r.setColor(color);
     renderer.addSeriesRenderer(r);
   }
   return 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;
 }
示例#6
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_room_detail);

    Bundle Title = getIntent().getExtras();
    if (Title != null) {
      mPlace = Title.getString(Constants.PLACE);
    }

    mRoomNameView = (TextView) findViewById(R.id.detail_roomname);
    mSeatnumbnerView = (TextView) findViewById(R.id.detail_seatnumber);
    mDescriptionView = (TextView) findViewById(R.id.detail_description);
    mImageView = (ImageView) findViewById(R.id.detailed_image);
    mHistoryButton = (Button) findViewById(R.id.history_button);

    mPersistanceManager = new PersistanceManager(this);
    r = mPersistanceManager.getCurrentRoom();

    mRoomNameView.setText(r.getName());
    mSeatnumbnerView.setText(r.getNumberOfSeat());
    mDescriptionView.setText(r.getDescription());

    // set the achartengine pie chart parameters, including color, lable size as well as items shown
    // options
    double taken = Double.parseDouble(r.getFullness());
    double notTaken = 100 - taken;
    double[] PIECHARTVALUES = new double[] {taken, notTaken};

    mRenderer.setApplyBackgroundColor(true);
    mRenderer.setBackgroundColor(Color.argb(100, 50, 50, 50));
    mRenderer.setChartTitleTextSize(20);
    mRenderer.setLabelsTextSize(50);
    mRenderer.setShowLegend(false);
    mRenderer.setShowTickMarks(false);
    mRenderer.setZoomButtonsVisible(true);
    mRenderer.setStartAngle(90);

    // show the percentage
    for (int i = 0; i < PIECHARTVALUES.length; i++) {
      mSeries.add(NAME_LIST[i] + " " + PIECHARTVALUES[i] + "%", PIECHARTVALUES[i]);
      SimpleSeriesRenderer renderer = new SimpleSeriesRenderer();
      renderer.setColor(COLORS[(mSeries.getItemCount() - 1) % COLORS.length]);
      mRenderer.addSeriesRenderer(renderer);
    }

    if (mChartView != null) {
      mChartView.repaint();
    }

    // load the pie chart layout with the parameters in mRenderer and mSeries we set before.
    LinearLayout layout = (LinearLayout) findViewById(R.id.chart);
    mChartView = ChartFactory.getPieChartView(this, mSeries, mRenderer);
    mRenderer.setClickEnabled(true);
    mRenderer.setSelectableBuffer(10);

    layout.addView(
        mChartView,
        new AbsListView.LayoutParams(
            AbsListView.LayoutParams.FILL_PARENT, AbsListView.LayoutParams.FILL_PARENT));

    if (!r.getImage().equals("")) {
      Ion.with(mImageView)
          .load(r.getImage())
          .setCallback(
              new FutureCallback<ImageView>() {
                @Override
                public void onCompleted(Exception e, ImageView result) {
                  if (e == null) {
                    // yay

                  } else {
                    // log the error information , helping to check. Then keep running app without
                    // image
                    Log.d(TAG, "image failed to load " + e.toString());
                  }
                }
              });
    }

    // set the extre before going to history activity, helping to save which building and which room
    // to load.
    mHistoryButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            Intent intent = new Intent(getBaseContext(), HistoryActivity.class);
            intent.putExtra(Constants.ROOM, r.getName());
            intent.putExtra(Constants.PLACE, mPlace);
            startActivity(intent);
          }
        });
  }