private void setDefault() { v_pie_chart.clearChart(); v_pie_chart.addPieSlice( new PieModel( getContext() .getString(R.string.view_categories_chart_report_layout_no_categories_expenses), 0, getResources().getColor(R.color.half_black))); }
private void displayChart(List<CategoryReportModel> categoriesModel, double totalSpent) { v_pie_chart.clearChart(); for (CategoryReportModel categoryReportModel : categoriesModel) { String categoryTitle = Category.getCategoryTitle(categoryReportModel.getCategory(), getContext()); if (categoryTitle != null) { int categoryColor = getCategoryColor(categoryReportModel.getCategory()); double amount = categoryReportModel.getAmount(); float expenseToTotal = Math.abs((float) ((amount / totalSpent) * TOTAL_PERCENTAGE_VALUE)); BigDecimal roundExpenseToTotal = new BigDecimal(expenseToTotal).setScale(DECIMAL_NUMBER, BigDecimal.ROUND_HALF_UP); v_pie_chart.addPieSlice( new PieModel(categoryTitle, roundExpenseToTotal.floatValue(), categoryColor)); } } v_pie_chart.animate(); }
private void initSubViews() { ButterKnife.inject(this); DisplayMetrics displayMetrics = getContext().getResources().getDisplayMetrics(); float height = displayMetrics.heightPixels; float layoutHeight = height * HEIGHT_PERCENTAGE; LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, (int) layoutHeight); v_pie_chart.setLayoutParams(layoutParams); setDefault(); }
protected void makePieChart(JsonArray datas, PieChart mPieChart, LinearLayout mPieCount) { List<String> titles = new ArrayList<String>(); for (JsonElement element : datas) { String title = element.getAsJsonObject().get("issue").getAsString(); titles.add(title); } Set<String> unique = new HashSet<String>(titles); for (String key : unique) { System.out.println(key + ": " + Collections.frequency(titles, key)); Random rnd = new Random(); String hexes = colorHexes[rnd.nextInt(colorHexes.length)]; int color = Color.parseColor(hexes); int count = Collections.frequency(titles, key); PieModel pieModel = new PieModel(key, count, color); mPieChart.addPieSlice(pieModel); View piechartLegend = getLayoutInflater().inflate(R.layout.piechart_legend_layout, mPieCount, false); CircleView piechartIndicator = (CircleView) piechartLegend.findViewById(R.id.legend_indicator); piechartIndicator.setColorHex(color); TextView piechartText = (TextView) piechartLegend.findViewById(R.id.legend_text); piechartText.setText(key); TextView piechartCount = (TextView) piechartLegend.findViewById(R.id.legend_count); piechartCount.setText(MixUtils.convertToBurmese(String.valueOf(count))); if (isUnicode) { piechartText.setTypeface(typefacelight); piechartCount.setTypeface(typefacelight); } else { MMTextUtils.getInstance(this).prepareMultipleViews(piechartText, piechartCount); } mPieCount.addView(piechartLegend); } mPieChart.startAnimation(); }