com.github.mikephil.charting.data.PieEntry Java Examples
The following examples show how to use
com.github.mikephil.charting.data.PieEntry.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PredictionsFragment.java From SEAL-Demo with MIT License | 6 votes |
/** * Return a list of all the entries in the pie chart excluding the intensities that don't exist * since the pie chart doesn't detect empty entries. * @return A list of all the entries in the pie chart. */ private ArrayList<PieEntry> filterPieEntries() { ArrayList<PieEntry> entries = new ArrayList<>(); String lowIntensityStr = getResources().getString(R.string.classification_low); String medIntensityStr = getResources().getString(R.string.classification_medium); String highIntensityStr = getResources().getString(R.string.classification_high); if(mLowRuns > 0) { entries.add(new PieEntry(mLowRuns, lowIntensityStr)); } if(mMedRuns > 0) { entries.add(new PieEntry(mMedRuns, medIntensityStr)); } if(mHighRuns > 0) { entries.add(new PieEntry(mHighRuns, highIntensityStr)); } return entries; }
Example #2
Source File: CountFragment.java From AccountBook with GNU General Public License v3.0 | 6 votes |
/** * 初始化图表 */ private void initChart() { ChartUtils.initPieChart(mChartView); mChartView.setOnChartValueSelectedListener(new OnChartValueSelectedListener() { @Override public void onValueSelected(Entry e, Highlight h) { // 单独显示每个分类的统计情况 PieEntry entry = (PieEntry) e; float money = entry.getValue(); String type = entry.getLabel(); mChartView.setCenterText(generateCenterSpannableText( String.valueOf(money), "(".concat(type).concat(")"))); } @Override public void onNothingSelected() { setChartData(); } }); }
Example #3
Source File: ListViewMultiChartActivity.java From StockChart-MPAndroidChart with MIT License | 6 votes |
/** * generates a random ChartData object with just one DataSet * * @return Pie data */ private PieData generateDataPie() { ArrayList<PieEntry> entries = new ArrayList<>(); for (int i = 0; i < 4; i++) { entries.add(new PieEntry((float) ((Math.random() * 70) + 30), "Quarter " + (i+1))); } PieDataSet d = new PieDataSet(entries, ""); // space between slices d.setSliceSpace(2f); d.setColors(ColorTemplate.VORDIPLOM_COLORS); return new PieData(d); }
Example #4
Source File: HalfPieChartActivity.java From StockChart-MPAndroidChart with MIT License | 6 votes |
private void setData(int count, float range) { ArrayList<PieEntry> values = new ArrayList<>(); for (int i = 0; i < count; i++) { values.add(new PieEntry((float) ((Math.random() * range) + range / 5), parties[i % parties.length])); } PieDataSet dataSet = new PieDataSet(values, "Election Results"); dataSet.setSliceSpace(3f); dataSet.setSelectionShift(5f); dataSet.setColors(ColorTemplate.MATERIAL_COLORS); //dataSet.setSelectionShift(0f); PieData data = new PieData(dataSet); data.setValueFormatter(new PercentFormatter()); data.setValueTextSize(11f); data.setValueTextColor(Color.WHITE); data.setValueTypeface(tfLight); chart.setData(data); chart.invalidate(); }
Example #5
Source File: SimpleFragment.java From StockChart-MPAndroidChart with MIT License | 6 votes |
/** * generates less data (1 DataSet, 4 values) * @return PieData */ protected PieData generatePieData() { int count = 4; ArrayList<PieEntry> entries1 = new ArrayList<>(); for(int i = 0; i < count; i++) { entries1.add(new PieEntry((float) ((Math.random() * 60) + 40), "Quarter " + (i+1))); } PieDataSet ds1 = new PieDataSet(entries1, "Quarterly Revenues 2015"); ds1.setColors(ColorTemplate.VORDIPLOM_COLORS); ds1.setSliceSpace(2f); ds1.setValueTextColor(Color.WHITE); ds1.setValueTextSize(12f); PieData d = new PieData(ds1); d.setValueTypeface(tf); return d; }
Example #6
Source File: LoadFolderSpaceData.java From PowerFileExplorer with GNU General Public License v3.0 | 6 votes |
private void updateChart(String totalSpace, List<PieEntry> entries) { boolean isDarkTheme = appTheme.getMaterialDialogTheme() == Theme.DARK; PieDataSet set = new PieDataSet(entries, null); set.setColors(COLORS); set.setXValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE); set.setYValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE); set.setSliceSpace(5f); set.setAutomaticallyDisableSliceSpacing(true); set.setValueLinePart2Length(1.05f); set.setSelectionShift(0f); PieData pieData = new PieData(set); pieData.setValueFormatter(new GeneralDialogCreation.SizeFormatter(context)); pieData.setValueTextColor(isDarkTheme? Color.WHITE:Color.BLACK); chart.setCenterText(new SpannableString(context.getString(R.string.total) + "\n" + totalSpace)); chart.setData(pieData); }
Example #7
Source File: LoadFolderSpaceData.java From PowerFileExplorer with GNU General Public License v3.0 | 6 votes |
@Override protected Pair<String, List<PieEntry>> doInBackground(Void... params) { long[] dataArray = Futils.getSpaces(file, context, new OnProgressUpdate<Long[]>() { @Override public void onUpdate(Long[] data) { publishProgress(data); } }); if (dataArray != null && dataArray[0] != -1 && dataArray[0] != 0) { long totalSpace = dataArray[0]; List<PieEntry> entries = createEntriesFromArray(dataArray, false); return new Pair<String, List<PieEntry>>(Formatter.formatFileSize(context, totalSpace), entries); } return null; }
Example #8
Source File: PredictionsFragment.java From SEAL-Demo with MIT License | 6 votes |
/** * Updates the data in the pie chart with all the runs. */ private void updatePieChart() { ArrayList<PieEntry> entries = filterPieEntries(); PieDataSet dataSet = new PieDataSet(entries, "Predictions"); dataSet.setDrawIcons(false); dataSet.setSliceSpace(2f); dataSet.setIconsOffset(new MPPointF(0, 40)); dataSet.setSelectionShift(5f); dataSet.setColors(new int[]{R.color.classification_low_intensity, R.color.classification_medium_intensity, R.color.classification_high_intensity}, getActivity()); PieData data = new PieData(dataSet); data.setValueFormatter(new PercentFormatter()); data.setValueTextSize(22f); data.setValueTextColor(Color.WHITE); mChart.setData(data); mChart.invalidate(); }
Example #9
Source File: MainActivity.java From android-ponewheel with MIT License | 5 votes |
public void updateBatteryRemaining(final int percent) { // Update ongoing notification notify.remain(percent); notify.alert(percent); runOnUiThread(() -> { try { ArrayList<PieEntry> entries = new ArrayList<>(); entries.add(new PieEntry(percent, 0)); entries.add(new PieEntry(100 - percent, 1)); PieDataSet dataSet = new PieDataSet(entries, "battery percentage"); ArrayList<Integer> mColors = new ArrayList<>(); mColors.add(ColorTemplate.rgb("#2E7D32")); //green mColors.add(ColorTemplate.rgb("#C62828")); //red dataSet.setColors(mColors); dataSet.setDrawValues(false); PieData newPieData = new PieData( dataSet); mBatteryChart.setCenterText(percent + "%"); mBatteryChart.setCenterTextTypeface(Typeface.DEFAULT_BOLD); mBatteryChart.setCenterTextColor(ColorTemplate.rgb("#616161")); mBatteryChart.setCenterTextSize(20f); mBatteryChart.setDescription(null); mBatteryChart.setData(newPieData); mBatteryChart.notifyDataSetChanged(); mBatteryChart.invalidate(); } catch (Exception e) { Timber.e( "Got an exception updating battery:" + e.getMessage()); } }); alertsController.handleChargePercentage(percent); }
Example #10
Source File: RealmPieDataSet.java From MPAndroidChart-Realm with Apache License 2.0 | 5 votes |
@Override protected void calcMinMax(PieEntry e) { if (e == null) return; calcMinMaxY(e); }
Example #11
Source File: RealmPieDataSet.java From MPAndroidChart-Realm with Apache License 2.0 | 5 votes |
@Override public PieEntry buildEntryFromResultObject(T realmObject, float x) { DynamicRealmObject dynamicObject = new DynamicRealmObject(realmObject); if (mLabelField == null) { return new PieEntry(dynamicObject.getFloat(mYValuesField)); } else { return new PieEntry(dynamicObject.getFloat(mYValuesField), dynamicObject.getString(mLabelField)); } }
Example #12
Source File: ReportAdapter.java From outlay with Apache License 2.0 | 5 votes |
private void updateChartData(PieChart chart) { ArrayList<PieEntry> entries = new ArrayList<>(); ArrayList<Integer> colors = new ArrayList<>(); double sum = 0; for (int i = 0; i < categorizedExpenses.getCategories().size(); i++) { Category c = categorizedExpenses.getCategory(i); Report r = categorizedExpenses.getReport(c); sum += r.getTotalAmount().doubleValue(); entries.add(new PieEntry((int) (r.getTotalAmount().doubleValue() * 1000), c.getTitle())); colors.add(c.getColor()); } PieDataSet dataSet = new PieDataSet(entries, "Outlay"); dataSet.setSliceSpace(2f); dataSet.setSelectionShift(10f); dataSet.setColors(colors); PieData data = new PieData(dataSet); data.setValueFormatter((value, entry, dataSetIndex, viewPortHandler) -> NumberUtils.formatAmount((double) value / 1000)); data.setValueTextSize(11f); data.setValueTextColor(Color.WHITE); chart.setData(data); chart.setCenterText(NumberUtils.formatAmount(sum)); chart.highlightValues(null); chart.invalidate(); }
Example #13
Source File: ProductDetailActivity.java From FaceT with Mozilla Public License 2.0 | 5 votes |
private void setData(PieChart colorPie, float value) { ArrayList<PieEntry> entries = new ArrayList<PieEntry>(); float result = value / 5f; Log.d(TAG + " result ", result + ""); entries.add(new PieEntry(result, 0)); entries.add(new PieEntry(1 - result, 1)); // NOTE: The order of the entries when being added to the entries array determines their position around the center of // the chart. // colorPie.setCenterTextTypeface(mTfLight); int centerTextColor = android.graphics.Color.argb(255, 57, 197, 193); colorPie.setCenterTextColor(centerTextColor); PieDataSet dataSet = new PieDataSet(entries, ""); dataSet.setSliceSpace(3f); dataSet.setSelectionShift(3f); // add a lot of colors ArrayList<Integer> colors = new ArrayList<Integer>(); colors.add(Color.argb(120, 57, 197, 193)); colorPie.setCenterText(value + ""); colorPie.setCenterTextSize(30); colors.add(Color.argb(100, 214, 214, 214)); dataSet.setColors(colors); PieData data = new PieData(dataSet); data.setValueFormatter(new PercentFormatter()); data.setValueTextSize(0f); data.setValueTextColor(Color.WHITE); colorPie.setData(data); // undo all highlights colorPie.highlightValues(null); colorPie.invalidate(); }
Example #14
Source File: NodeInfoFragment.java From android-wallet-app with GNU General Public License v3.0 | 5 votes |
private void setData(long tips, long transactionsToRequest) { ArrayList<PieEntry> entries = new ArrayList<>(); entries.add(new PieEntry(tips, getString(R.string.tips) + " " + "(" + tips + ")")); entries.add(new PieEntry(transactionsToRequest, getString(R.string.transactions_to_request) + " " + "(" + transactionsToRequest + ")")); PieDataSet dataSet = new PieDataSet(entries, getString(R.string.transactions) + "\n(" + (tips + transactionsToRequest) + ")"); dataSet.setSliceSpace(3f); dataSet.setSelectionShift(5f); // add a lot of colors ArrayList<Integer> colors = new ArrayList<>(); for (int c : ColorTemplate.LIBERTY_COLORS) colors.add(c); dataSet.setColors(colors); dataSet.setValueLinePart1OffsetPercentage(80.f); dataSet.setValueLinePart1Length(0.2f); dataSet.setValueLinePart2Length(0.4f); dataSet.setXValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE); dataSet.setYValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE); dataSet.setValueTextColor(ContextCompat.getColor(getActivity(), R.color.colorPrimary)); PieData data = new PieData(dataSet); data.setValueFormatter(new PercentFormatter()); data.setValueTextSize(12f); data.setValueTextColor(ContextCompat.getColor(getActivity(), R.color.colorPrimary)); chart.setData(data); // undo all highlights chart.highlightValues(null); chart.invalidate(); }
Example #15
Source File: ChartFormatter.java From AccountBook with GNU General Public License v3.0 | 5 votes |
public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) { String formatValue = this.mFormat.format((double) value); PieEntry e = (PieEntry) entry; String type = e.getLabel(); mPercentMap.put(type, Float.valueOf(formatValue)); if(mSize == mPercentMap.size() && mListener != null && !mIsCallback){ mListener.onFormattedValue(mPercentMap); mIsCallback = true; } return formatValue + " %"; }
Example #16
Source File: GraphicActivity.java From ToDay with MIT License | 5 votes |
private void addDataSet() { Log.d(TAG, "addDataSet started"); ArrayList<PieEntry> yEntrys = new ArrayList<>(); ArrayList<String> xEntrys = new ArrayList<>(); for(int i = 0; i < yData.length; i++){ yEntrys.add(new PieEntry(yData[i] , i)); } for(int i = 1; i < xData.length; i++){ xEntrys.add(xData[i]); } //create the data set PieDataSet pieDataSet = new PieDataSet(yEntrys, "Төлөвлөгөөний үзүүлэлтлл"); pieDataSet.setSliceSpace(2); pieDataSet.setValueTextSize(12); //add colors to dataset ArrayList<Integer> colors = new ArrayList<>(); colors.add(Color.GRAY); colors.add(Color.BLUE); colors.add(Color.RED); colors.add(Color.GREEN); colors.add(Color.CYAN); colors.add(Color.YELLOW); colors.add(Color.MAGENTA); pieDataSet.setColors(colors); //add legend to chart Legend legend = pieChart.getLegend(); legend.setForm(Legend.LegendForm.CIRCLE); legend.setPosition(Legend.LegendPosition.LEFT_OF_CHART); //create pie data object PieData pieData = new PieData(pieDataSet); pieChart.setData(pieData); pieChart.invalidate(); }
Example #17
Source File: LoadFolderSpaceData.java From PowerFileExplorer with GNU General Public License v3.0 | 5 votes |
private List<PieEntry> createEntriesFromArray(long[] dataArray, boolean loading) { long usedByFolder = dataArray[2], usedByOther = dataArray[0] - dataArray[1] - dataArray[2], freeSpace = dataArray[1]; List<PieEntry> entries = new ArrayList<>(); entries.add(new PieEntry(usedByFolder, LEGENDS[0], loading? ">":null)); entries.add(new PieEntry(usedByOther, LEGENDS[1], loading? "<":null)); entries.add(new PieEntry(freeSpace, LEGENDS[2])); return entries; }
Example #18
Source File: LoadFolderSpaceData.java From PowerFileExplorer with GNU General Public License v3.0 | 5 votes |
@Override protected void onProgressUpdate(Long[] dataArray) { if (dataArray != null && dataArray[0] != -1 && dataArray[0] != 0) { long totalSpace = dataArray[0]; List<PieEntry> entries = createEntriesFromArray( new long[]{dataArray[0], dataArray[1], dataArray[2]}, true); updateChart(Formatter.formatFileSize(context, totalSpace), entries); chart.notifyDataSetChanged(); chart.invalidate(); } }
Example #19
Source File: PercentFormatter.java From StockChart-MPAndroidChart with MIT License | 5 votes |
@Override public String getPieLabel(float value, PieEntry pieEntry) { if (pieChart != null && pieChart.isUsePercentValuesEnabled()) { // Converted to percent return getFormattedValue(value); } else { // raw value, skip percent sign return mFormat.format(value); } }
Example #20
Source File: CameraActivity.java From dbclf with Apache License 2.0 | 5 votes |
private void setupPieChart() { mChart.getDescription().setEnabled(false); mChart.setUsePercentValues(true); mChart.setTouchEnabled(false); // show center text only first time final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); final boolean previouslyStarted = prefs.getBoolean("showhelp", false); if (!previouslyStarted) { SharedPreferences.Editor edit = prefs.edit(); edit.putBoolean("showhelp", Boolean.TRUE); edit.apply(); mChart.setCenterTextTypeface(Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf")); mChart.setCenterText(generateCenterSpannableText()); mChart.setCenterTextSizePixels(23); mChart.setDrawCenterText(true); } mChart.setExtraOffsets(14, 0.f, 14, 0.f); mChart.setHoleRadius(85); mChart.setHoleColor(Color.TRANSPARENT); mChart.setHovered(true); mChart.setDrawMarkers(false); mChart.setRotationEnabled(false); mChart.setHighlightPerTapEnabled(false); mChart.getLegend().setEnabled(false); mChart.setAlpha(0.9f); // display unknown slice final ArrayList<PieEntry> entries = new ArrayList<>(); // set unknown slice to transparent entries.add(new PieEntry(100, "")); final PieDataSet set = new PieDataSet(entries, ""); set.setColor(R.color.transparent); set.setDrawValues(false); final PieData data = new PieData(set); mChart.setData(data); }
Example #21
Source File: LoadFolderSpaceData.java From PowerFileExplorer with GNU General Public License v3.0 | 5 votes |
@Override protected void onPostExecute(Pair<String, List<PieEntry>> data) { if(data == null) { chart.setVisibility(View.GONE); return; } updateChart(data.first, data.second); chart.notifyDataSetChanged(); chart.invalidate(); }
Example #22
Source File: StatisticsActivity.java From ActivityDiary with GNU General Public License v3.0 | 4 votes |
public void onLoadFinished(Loader<Cursor> loader, Cursor data) { // Swap the new cursor in. (The framework will take care of closing the // old cursor once we return.) List<PieEntry> entries = new ArrayList<>(); List<Integer> colors = new ArrayList<>(); int portion_idx = data.getColumnIndex(ActivityDiaryContract.DiaryStats.PORTION); int name_idx = data.getColumnIndex(ActivityDiaryContract.DiaryStats.NAME); int col_idx = data.getColumnIndex(ActivityDiaryContract.DiaryStats.COLOR); int dur_idx = data.getColumnIndex(ActivityDiaryContract.DiaryStats.DURATION); if ((data != null) && data.moveToFirst()) { float acc = 0.0f; float acc_po = 0.0f; while (!data.isAfterLast()) { float portion = data.getFloat(portion_idx); long duration = data.getLong(dur_idx); if(portion > 3.0f){ PieEntry ent = new PieEntry((float)duration, data.getString(name_idx)); entries.add(ent); colors.add(data.getInt(col_idx)); }else{ // accumulate the small, not shown entries acc += duration; acc_po += portion; } data.moveToNext(); } if(acc_po > 2.0f) { entries.add(new PieEntry(acc, getResources().getString(R.string.statistics_others))); colors.add(Color.GRAY); } } PieDataSet set = new PieDataSet(entries, getResources().getString(R.string.activities)); PieData dat = new PieData(set); set.setColors(colors); set.setValueFormatter(new IValueFormatter() { @Override public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) { PieEntry e = (PieEntry)entry; return TimeSpanFormatter.format((long)e.getValue()); } }); chart.setData(dat); chart.setUsePercentValues(true); chart.setRotationAngle(180.0f); chart.invalidate(); // refresh }
Example #23
Source File: StatisticsFragment.java From budgetto with MIT License | 4 votes |
private void dataUpdated() { if (calendarStart != null && calendarEnd != null && walletEntryListDataSet != null) { List<WalletEntry> entryList = new ArrayList<>(walletEntryListDataSet.getList()); long expensesSumInDateRange = 0; long incomesSumInDateRange = 0; HashMap<Category, Long> categoryModels = new HashMap<>(); for (WalletEntry walletEntry : entryList) { if (walletEntry.balanceDifference > 0) { incomesSumInDateRange += walletEntry.balanceDifference; continue; } expensesSumInDateRange += walletEntry.balanceDifference; Category category = CategoriesHelper.searchCategory(user, walletEntry.categoryID); if (categoryModels.get(category) != null) categoryModels.put(category, categoryModels.get(category) + walletEntry.balanceDifference); else categoryModels.put(category, walletEntry.balanceDifference); } categoryModelsHome.clear(); ArrayList<PieEntry> pieEntries = new ArrayList<>(); ArrayList<Integer> pieColors = new ArrayList<>(); for (Map.Entry<Category, Long> categoryModel : categoryModels.entrySet()) { float percentage = categoryModel.getValue() / (float) expensesSumInDateRange; final float minPercentageToShowLabelOnChart = 0.1f; categoryModelsHome.add(new TopCategoryStatisticsListViewModel(categoryModel.getKey(), categoryModel.getKey().getCategoryVisibleName(getContext()), user.currency, categoryModel.getValue(), percentage)); if (percentage > minPercentageToShowLabelOnChart) { Drawable drawable = getContext().getDrawable(categoryModel.getKey().getIconResourceID()); drawable.setTint(Color.parseColor("#FFFFFF")); pieEntries.add(new PieEntry(-categoryModel.getValue(), drawable)); } else { pieEntries.add(new PieEntry(-categoryModel.getValue())); } pieColors.add(categoryModel.getKey().getIconColor()); } PieDataSet pieDataSet = new PieDataSet(pieEntries, ""); pieDataSet.setDrawValues(false); pieDataSet.setColors(pieColors); pieDataSet.setSliceSpace(2f); PieData data = new PieData(pieDataSet); pieChart.setData(data); pieChart.setTouchEnabled(false); pieChart.getLegend().setEnabled(false); pieChart.getDescription().setEnabled(false); pieChart.setDrawHoleEnabled(true); pieChart.setHoleColor(ContextCompat.getColor(getContext(), R.color.backgroundPrimary)); pieChart.setHoleRadius(55f); pieChart.setTransparentCircleRadius(55f); pieChart.setDrawCenterText(true); pieChart.setRotationAngle(270); pieChart.setRotationEnabled(false); pieChart.setHighlightPerTapEnabled(true); pieChart.invalidate(); Collections.sort(categoryModelsHome, new Comparator<TopCategoryStatisticsListViewModel>() { @Override public int compare(TopCategoryStatisticsListViewModel o1, TopCategoryStatisticsListViewModel o2) { return Long.compare(o1.getMoney(), o2.getMoney()); } }); adapter.notifyDataSetChanged(); DateFormat dateFormat = new SimpleDateFormat("dd-MM-yy"); dividerTextView.setText("Date range: " + dateFormat.format(calendarStart.getTime()) + " - " + dateFormat.format(calendarEnd.getTime())); expensesTextView.setText(CurrencyHelper.formatCurrency(user.currency, expensesSumInDateRange)); incomesTextView.setText(CurrencyHelper.formatCurrency(user.currency, incomesSumInDateRange)); float progress = 100 * incomesSumInDateRange / (float) (incomesSumInDateRange - expensesSumInDateRange); incomesExpensesProgressBar.setProgress((int) progress); } }
Example #24
Source File: StatisticActivity.java From memorize with MIT License | 4 votes |
@Override public void setStatData(int total, int memorized, int favorited, int active) { ArrayList<PieEntry> entries = new ArrayList<PieEntry>(); entries.add(new PieEntry((float) memorized, "Цээжилсэн үг " + memorized, getResources().getDrawable(R.drawable.ic_timeline))); entries.add(new PieEntry((float) favorited, "Цээжилж байгаа " + favorited, getResources().getDrawable(R.drawable.ic_timeline))); entries.add(new PieEntry((float) active, "Цээжлээгүй " + active, getResources().getDrawable(R.drawable.ic_timeline))); PieDataSet dataSet = new PieDataSet(entries, "Memorize results"); dataSet.setDrawIcons(false); dataSet.setSliceSpace(3f); dataSet.setIconsOffset(new MPPointF(0, 40)); dataSet.setSelectionShift(5f); // add a lot of colors ArrayList<Integer> colors = new ArrayList<Integer>(); colors.add(getResources().getColor(R.color.chartGreen)); colors.add(getResources().getColor(R.color.chartBlue)); colors.add(getResources().getColor(R.color.chartPink)); dataSet.setColors(colors); //dataSet.setSelectionShift(0f); PieData data = new PieData(dataSet); data.setValueFormatter(new PercentFormatter()); data.setValueTextSize(11f); data.setValueTextColor(Color.WHITE); SpannableString s = new SpannableString("Нийт үг :" + total); s.setSpan(new RelativeSizeSpan(1.7f), 0, s.length(), 0); s.setSpan(new ForegroundColorSpan(ColorTemplate.getHoloBlue()), 0, s.length(), 0); pieData = new PieData(dataSet); }
Example #25
Source File: CountFragment.java From AccountBook with GNU General Public License v3.0 | 4 votes |
/** * 设置图表数据 */ @Override public void setChartData() { if (mMoneyMap.size() > 0) { mChartView.setVisibility(View.VISIBLE); // 设置总支出/收入 String typeStr = mCountType == AppConfig.TYPE_COST ? UiUtils.getString(R.string.total_cost_chart) : UiUtils.getString(R.string.total_income_chart); mChartView.setCenterText(generateCenterSpannableText( String.valueOf(getTotalMoney()), typeStr)); // 设置图表数据与颜色 ArrayList<PieEntry> entries = new ArrayList<>(); ArrayList<Integer> colors = new ArrayList<>(); for (Map.Entry<String, Double> entry : mMoneyMap.entrySet()) { // 添加分类、金额数据 Float money = Float.valueOf(String.valueOf(entry.getValue())); String type = entry.getKey(); PieEntry pieEntry = new PieEntry(money, type); entries.add(pieEntry); // 添加从分类图片中取色的颜色 String iconName = mIconMap.get(entry.getKey()); Bitmap bitmap = BitmapFactory.decodeResource(getResources(), UiUtils.getImageResIdByName(iconName)); int colorRgb = PaletteUtils.getColorRgb(bitmap); mColorMap.put(type,colorRgb); colors.add(colorRgb); } PieDataSet dataSet = new PieDataSet(entries, ""); dataSet.setSliceSpace(3f); dataSet.setSelectionShift(5f); dataSet.setColors(colors); PieData data = new PieData(dataSet); ChartFormatter formatter = new ChartFormatter(mPercentMap, mMoneyMap.size()); formatter.setOnFormattedValueListener(this); data.setValueFormatter(formatter); data.setValueTextSize(11f); data.setValueTextColor(Color.WHITE); mChartView.setData(data); mChartView.animateX(800); }else{ mChartView.setVisibility(View.GONE); } }
Example #26
Source File: StatsActivity.java From android with MIT License | 4 votes |
private void createPieChart(List<Long> contacts, List<Long> voicemails, List<Long> unavailables, long firstTimestamp) { Date date = new Date(firstTimestamp); ArrayList<Integer> colorsList = new ArrayList<>(); // Create pie pieChart data entries and add correct colors. ArrayList<PieEntry> entries = new ArrayList<>(); if (contacts.size() > 0) { entries.add(new PieEntry(contacts.size(), getResources().getString(R.string.contact_n))); colorsList.add(getResources().getColor(R.color.contacted_color)); } if (voicemails.size() > 0) { entries.add(new PieEntry(voicemails.size(), getResources().getString(R.string.voicemail_n))); colorsList.add(getResources().getColor(R.color.voicemail_color)); } if (unavailables.size() > 0) { entries.add(new PieEntry(unavailables.size(), getResources().getString(R.string.unavailable_n))); colorsList.add(getResources().getColor(R.color.unavailable_color)); } PieDataSet dataSet = new PieDataSet(entries, getResources().getString(R.string.menu_stats)); // Add colors and set visual properties for pie pieChart. dataSet.setColors(colorsList); dataSet.setSliceSpace(3f); dataSet.setSelectionShift(5f); dataSet.setValueLinePart1OffsetPercentage(80.f); dataSet.setValueLinePart1Length(.1f); dataSet.setValueLinePart2Length(.5f); dataSet.setValueLineColor(getResources().getColor(R.color.colorPrimaryDark)); dataSet.setYValuePosition(PieDataSet.ValuePosition.INSIDE_SLICE); dataSet.setXValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE); PieData data = new PieData(dataSet); data.setValueTextSize(18f); data.setValueFormatter(new DefaultValueFormatter(0)); data.setValueTextColor(Color.WHITE); SpannableString insideCircleText = new SpannableString(getResources().getString(R.string.stats_summary_total) +"\n" + Integer.toString(voicemails.size()+contacts.size()+unavailables.size()) + "\n" + this.dateFormat.format(date) + "-" + this.dateFormat.format(new Date(System.currentTimeMillis())) ); insideCircleText.setSpan(new RelativeSizeSpan(2f), 0, insideCircleText.length() - 17, 0); pieChart.setData(data); pieChart.setCenterText(insideCircleText); pieChart.setCenterTextColor(getResources().getColor(R.color.colorPrimaryDark)); pieChart.setCenterTextSize(11f); pieChart.setHoleRadius(70); pieChart.setEntryLabelColor(getResources().getColor(R.color.colorPrimaryDark)); pieChart.getLegend().setEnabled(false); pieChart.setDescription(new Description()); pieChart.getDescription().setText(""); pieChart.invalidate(); }
Example #27
Source File: ColorDetectionActivity.java From FaceT with Mozilla Public License 2.0 | 4 votes |
private void setData(PieChart colorPie, int order, int color) { ArrayList<PieEntry> entries = new ArrayList<PieEntry>(); float colorValue = color / 255f; entries.add(new PieEntry(colorValue, 0)); entries.add(new PieEntry(1 - colorValue, 1)); // NOTE: The order of the entries when being added to the entries array determines their position around the center of // the chart. // colorPie.setCenterTextTypeface(mTfLight); colorPie.setCenterTextColor(ColorTemplate.getHoloBlue()); PieDataSet dataSet = new PieDataSet(entries, ""); dataSet.setSliceSpace(3f); dataSet.setSelectionShift(3f); // add a lot of colors ArrayList<Integer> colors = new ArrayList<Integer>(); colors.clear(); switch (order) { case 0: colors.add(Color.argb(100, color, 0, 0)); colorPie.setCenterText("Red"); break; case 1: colors.add(Color.argb(100, 0, color, 0)); colorPie.setCenterText("Green"); break; case 2: colors.add(Color.argb(100, 0, 0, color)); colorPie.setCenterText("Blue"); break; } colors.add(Color.argb(80, 214, 214, 214)); dataSet.setColors(colors); PieData data = new PieData(dataSet); data.setValueFormatter(new PercentFormatter()); data.setValueTextSize(0f); data.setValueTextColor(Color.WHITE); colorPie.setData(data); // undo all highlights colorPie.highlightValues(null); colorPie.invalidate(); }
Example #28
Source File: CameraActivity.java From dbclf with Apache License 2.0 | 4 votes |
void updatePieChart(List<Classifier.Recognition> results) { final ArrayList<PieEntry> entries = new ArrayList<>(); float sum = 0; if (results != null) for (int i = 0; i < results.size(); i++) { sum += results.get(i).getConfidence(); PieEntry entry = new PieEntry(results.get(i).getConfidence() * 100, results.get(i).getTitle()); entries.add(entry); } // add unknown slice final float unknown = 1 - sum; entries.add(new PieEntry(unknown * 100, "")); //calculate center of slice final float offset = entries.get(0).getValue() * 3.6f / 2; // calculate the next angle final float end = 270f - (entries.get(0).getValue() * 3.6f - offset); final PieDataSet set = new PieDataSet(entries, ""); if (entries.size() > 2) set.setSliceSpace(3f); // set slice colors final ArrayList<Integer> sliceColors = new ArrayList<>(); for (int c : CHART_COLORS) sliceColors.add(c); if (entries.size() > 0) sliceColors.set(entries.size() - 1, R.color.transparent); set.setColors(sliceColors); set.setDrawValues(false); final PieData data = new PieData(set); mChart.setData(data); //rotate to center of first slice mChart.setRotationAngle(end); mChart.setEntryLabelTextSize(16); mChart.invalidate(); }
Example #29
Source File: ValueFormatter.java From StockChart-MPAndroidChart with MIT License | 2 votes |
/** * Used to draw pie value labels, calls {@link #getFormattedValue(float)} by default. * * @param value float to be formatted, may have been converted to percentage * @param pieEntry slice being labeled, contains original, non-percentage Y value * @return formatted string label */ public String getPieLabel(float value, PieEntry pieEntry) { return getFormattedValue(value); }