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
  protected CategorySeries _BuildCategoryDataset(String title, List<ModelCategoryTotal> values) {
    CategorySeries series = new CategorySeries(title);
    for (ModelCategoryTotal value : values) {
      series.add("数量: " + value.Count, Double.parseDouble(value.Count));
    }

    return series;
  }
예제 #5
0
  /**
   * Builds a category series using the provided values.
   *
   * @param titles the series titles
   * @param values the values
   * @return the category series
   */
  public CategorySeries buildCategoryDataset(String title, double[] values) {
    CategorySeries series = new CategorySeries(title);
    int k = 0;
    for (double value : values) {
      series.add("Project " + ++k, value);
    }

    return series;
  }
 private XYMultipleSeriesDataset getBarDemoDataset() {
   XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
   final int nr = 10;
   Random r = new Random();
   for (int i = 0; i < SERIES_NR; i++) {
     CategorySeries series = new CategorySeries("Demo series " + (i + 1));
     for (int k = 0; k < nr; k++) {
       series.add(100 + r.nextInt() % 100);
     }
     dataset.addSeries(series.toXYSeries());
   }
   return dataset;
 }
예제 #7
0
 /**
  * Builds a bar multiple series dataset using the provided values.
  *
  * @param titles the series titles
  * @param values the values
  * @return the XY multiple bar dataset
  */
 public XYMultipleSeriesDataset buildBarDataset(String[] titles, List<double[]> values) {
   XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
   int length = titles.length;
   for (int i = 0; i < length; i++) {
     CategorySeries series = new CategorySeries(titles[i]);
     double[] v = values.get(i);
     int seriesLength = v.length;
     for (int k = 0; k < seriesLength; k++) {
       series.add(v[k]);
     }
     dataset.addSeries(series.toXYSeries());
   }
   return dataset;
 }
예제 #8
0
  @Override
  protected void onResume() {
    super.onResume();

    if (mChartView == null) {
      LinearLayout layout = (LinearLayout) findViewById(R.id.chart);
      mChartView = ChartFactory.getPieChartView(this, mSeries, mRenderer);
      mRenderer.setClickEnabled(true);

      mChartView.setOnLongClickListener(
          new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
              SeriesSelection seriesSelection = mChartView.getCurrentSeriesAndPoint();
              if (seriesSelection == null) {
                mChartView.repaint();
              } else {
                for (int i = 0; i < mSeries.getItemCount(); i++) {
                  mRenderer
                      .getSeriesRendererAt(i)
                      .setHighlighted(i == seriesSelection.getPointIndex());
                  getcategoryofclicked = mSeries.getCategory(seriesSelection.getPointIndex());
                }
                mChartView.repaint();

                Intent intent = new Intent(getApplicationContext(), PieChartDetails.class);
                intent.putExtra("selectedCategory", getcategoryofclicked);
                intent.putExtra("selectedDate", mdate);

                startActivity(intent);
              }
              return true;
            }
          });

      layout.addView(
          mChartView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
      if (mSeries.getItemCount() == 0)
        textView1.setText("Hey you have not added any data\n\t\tPlease add some");
    } else {
      mChartView.repaint();
    }
  }
예제 #9
0
  @Override
  protected void onStart() {
    // TODO Auto-generated method stub
    super.onStart();

    try {
      elec_thread.join();
    } catch (InterruptedException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    int k = CH.getNum_of_msg(); // 보여줄 데이터 개수

    Log.d("get", "onStart시작");

    int seriesLength = 0;
    double max = 0;

    recv_packet = new Packet[k];

    for (int i = 0; i < k; i++) {
      recv_packet[i] = CH.get_Packet(i);
    }
    Log.d("get", "recv_packet배열 저장");

    List<Float[]> values = new ArrayList<Float[]>();
    Float[][] a = new Float[4][k];
    int[][] c = new int[4][k];

    for (int j = 0; j < k; j++) {
      a[0][j] = Float.parseFloat(recv_packet[j].getData(3));
      a[1][j] = Float.parseFloat(recv_packet[j].getData(4));
      a[2][j] = Float.parseFloat(recv_packet[j].getData(5));
      a[3][j] = Float.parseFloat(recv_packet[j].getData(7));
      c[0][j] = (int) (a[0][j] * 10);
      c[1][j] = (int) (a[1][j] * 10);
      c[2][j] = (int) (a[2][j] * 10);
      c[3][j] = (int) (a[3][j] * 10);
      a[0][j] = ((float) c[0][j] / (float) 10);
      a[1][j] = ((float) c[1][j] / (float) 10);
      a[2][j] = ((float) c[2][j] / (float) 10);
      a[3][j] = ((float) c[3][j] / (float) 10);

      // a[3][j] = (float) Math.round(Float.parseFloat(recv_packet[j].getData(7))*10000)/10000;
      // values.add(a);// 이번달
    }
    for (int w = 0; w < 4; w++) {
      //        a[w] = Math.round(a[w]*10) / 10.0;
      values.add(a[w]);
    }

    Log.d("get", "values배열 저장");
    XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();

    renderer.setChartTitle("과거 사용량과의 비교");
    renderer.setChartTitleTextSize(50);

    String[] titles = new String[] {"3달 전", "2달 전", "1달 전", "이번 달"};

    int[] colors =
        new int[] {
          Color.rgb(255, 90, 217),
          Color.rgb(54, 255, 255),
          Color.rgb(255, 255, 72),
          Color.rgb(83, 255, 76)
        };
    // //////////////////////////////////////////////////////
    //   renderer.setLegendTextSize(35);

    int length = values.size(); // 항목갯수

    Log.d("get", "legnth : " + length);
    for (int i = 0; i < length; i++) {
      SimpleSeriesRenderer r = new SimpleSeriesRenderer();
      r.setColor(colors[i]);
      renderer.addSeriesRenderer(r);
    }

    renderer.setXTitle("제품별");
    renderer.setYTitle("사용량");
    renderer.setAxisTitleTextSize(28);
    renderer.setMarginsColor(Color.WHITE);

    renderer.setLabelsTextSize(20);
    renderer.setLegendHeight(200);
    renderer.setXAxisMin(0.5);
    // renderer.setXAxisMax(length + 0.5); // 장비 갯수 +0.5
    renderer.setYAxisMin(0);

    renderer.setLabelsColor(Color.BLACK);
    renderer.setBackgroundColor(Color.WHITE);

    // 그래프 위에 값 표시하기
    for (int i = 0; i < length; i++) {
      renderer.getSeriesRendererAt(i).setDisplayChartValues(true);
      renderer.getSeriesRendererAt(i).setChartValuesTextAlign(Align.RIGHT);
      renderer.getSeriesRendererAt(i).setChartValuesTextSize(20);
    }
    Log.d("get", "그래프위값 표시하기");

    renderer.setYLabels(5);

    // x,y축 정렬 방향
    renderer.setXLabelsAlign(Align.CENTER);
    renderer.setYLabelsAlign(Align.CENTER);
    renderer.setPanEnabled(true, true); // x,y축 스크롤 여부 on/off
    renderer.setZoomEnabled(true); // zoom기능 on/off
    renderer.setZoomRate(1.0f);
    renderer.setBarSpacing(0.5f);

    Log.d("get", "xy축 정렬 방향");

    XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
    for (int i = 0; i < titles.length; i++) {
      CategorySeries series = new CategorySeries(titles[i]);
      Float[] v = values.get(i);

      Log.d("get", "int i = 0; i < titles.length; i++");

      seriesLength = v.length;
      renderer.setXAxisMax(seriesLength + 0.5);

      for (int q = 0; q < seriesLength; q++) {
        series.add(v[q]);
        if (max < v[q]) {
          max = v[q];
        }
        // Log.d("Test", "series.add : " + v[q]);
        renderer.setXLabels(seriesLength + 1);
      }
      dataset.addSeries(series.toXYSeries());
    }
    Log.d("get", "111111111");
    String[] x_name = new String[seriesLength];
    for (int b = 0; b < k; b++) {
      x_name[b] = recv_packet[b].getData(2);
    }
    Log.d("get", "222222222");
    renderer.setXLabels(0);
    for (int i = 0; i < seriesLength; i++) {
      renderer.addXTextLabel(i + 1, x_name[i]);
    }
    renderer.setYAxisMax(max + (max * 0.1)); // max 찾아서 넣기
    GraphicalView gv = ChartFactory.getBarChartView(this, dataset, renderer, Type.DEFAULT);

    setContentView(gv);
  }
    public CategorySeries getDataSet() {
      String select;
      String[] selectArgs;

      String[] recordProjection = {
        DailyTables.TABLE_RECORDS_COLUMN_ID,
        DailyTables.TABLE_RECORDS_COLUMN_TITLE,
        DailyTables.TABLE_RECORDS_COLUMN_AMOUNT
      };
      String[] categoryProjection = {
        DailyTables.TABLE_CATEGORIES_COLUMN_ID, DailyTables.TABLE_CATEGORIES_COLUMN_TITLE
      };

      CategorySeries series = new CategorySeries("Chart");

      ArrayList<StringValuePair> expensesValues = new ArrayList<StringValuePair>();

      // get categories
      Cursor categoryCursor =
          getSherlockActivity()
              .getContentResolver()
              .query(
                  DailyContentProvider.CATEGORIES_CONTENT_URI,
                  categoryProjection,
                  null,
                  null,
                  null);
      for (boolean hasItem = categoryCursor.moveToFirst();
          hasItem;
          hasItem = categoryCursor.moveToNext()) {
        double expenses = 0;
        String categoryTitle =
            categoryCursor.getString(
                categoryCursor.getColumnIndexOrThrow(DailyTables.TABLE_CATEGORIES_COLUMN_TITLE));
        long categoryId =
            categoryCursor.getLong(
                categoryCursor.getColumnIndexOrThrow(DailyTables.TABLE_CATEGORIES_COLUMN_ID));

        // manage expense Records
        Map<String, String> selectionMap = Maps.newHashMap();
        RecordFilter filter = new RecordFilter();
        filter.reset();
        selectionMap.put(DailyTables.TABLE_RECORDS_COLUMN_BOOKING_TYPE + "=?", "" + 1);
        selectionMap.put(DailyTables.TABLE_RECORDS_COLUMN_CATEGORY_TYPE + "=?", "" + categoryId);
        // if there is a filter, attach the arguments
        if (mDateValuesFilter != null) {
          selectionMap.put(
              DailyTables.TABLE_RECORDS_COLUMN_UNIX_DATE + ">=?",
              "" + mDateValuesFilter.getValue1());
          selectionMap.put(
              DailyTables.TABLE_RECORDS_COLUMN_UNIX_DATE + "<=?",
              "" + mDateValuesFilter.getValue2());
        }
        filter.set(selectionMap);

        select = filter.getSelection();
        selectArgs = filter.getSelectionArgs();

        Cursor expensesRecords =
            getActivity()
                .getContentResolver()
                .query(
                    DailyContentProvider.RECORDS_CONTENT_URI,
                    recordProjection,
                    select,
                    selectArgs,
                    null);

        for (boolean hasItem2 = expensesRecords.moveToFirst();
            hasItem2;
            hasItem2 = expensesRecords.moveToNext()) {
          String recordTitle =
              expensesRecords.getString(
                  expensesRecords.getColumnIndexOrThrow(DailyTables.TABLE_RECORDS_COLUMN_TITLE));
          double recordAmount =
              expensesRecords.getDouble(
                  expensesRecords.getColumnIndexOrThrow(DailyTables.TABLE_RECORDS_COLUMN_AMOUNT));
          expensesValues.add(new StringValuePair(recordTitle, recordAmount));
          expenses += recordAmount;
        }
        expensesRecords.close();
        series.add(categoryTitle + ": " + expenses, expenses);
      }
      return series;
    }
예제 #11
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);
          }
        });
  }