/** * generates less data (1 DataSet, 4 values) * @return */ protected PieData generatePieData() { int count = 4; ArrayList<PieEntry> entries1 = new ArrayList<PieEntry>(); 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; }
private void setData(int count, float range) { ArrayList<PieEntry> values = new ArrayList<PieEntry>(); for (int i = 0; i < count; i++) { values.add(new PieEntry((float) ((Math.random() * range) + range / 5), mParties[i % mParties.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(mTfLight); mChart.setData(data); mChart.invalidate(); }
/** * generates a random ChartData object with just one DataSet * * @return */ private PieData generateDataPie(int cnt) { ArrayList<PieEntry> entries = new ArrayList<PieEntry>(); 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); PieData cd = new PieData(d); return cd; }
private PieData generatePieData(List<PieChartItem> pieChartItems) { ArrayList<PieEntry> entries = new ArrayList<>(); for (PieChartItem item : pieChartItems) { entries.add(new PieEntry(item.getTime(), item.getName(), item.getPercent())); } PieDataSet pieDataSet = new PieDataSet(entries, ""); pieDataSet.setAutomaticallyDisableSliceSpacing(true); pieDataSet.setColors(chartColors); PieData pieData = new PieData(pieDataSet); pieData.setValueFormatter(new CustomPercentFormatter()); pieData.setValueTextColor(Color.WHITE); return pieData; }
private void createPieChart(ArrayList<PieEntry> yEntrys, ArrayList<Integer> colors) { //create the data set PieDataSet pieDataSet = new PieDataSet(yEntrys, ""); pieDataSet.setSliceSpace(2); pieDataSet.setValueTextSize(12); pieDataSet.setColors(colors); pieChart.setCenterText(start.toString() + "\n" + end.toString()); pieChart.setCenterTextColor(Color.BLACK); pieChart.setCenterTextSize(20); pieChart.animateY(2000); pieChart.animateX(2000); pieChart.getLegend().setEnabled(true); Description description = new Description(); description.setText(""); pieChart.setDescription(description); //create pie data object PieData pieData = new PieData(); pieData.addDataSet(pieDataSet); pieChart.setData(pieData); pieChart.invalidate(); }
private void setPieChartData(int count, float range) { ArrayList<PieEntry> entries = ChartData.getPieData(count, range); PieDataSet dataSet = new PieDataSet(entries, "Weekly spend distribution"); dataSet.setDrawIcons(false); dataSet.setSliceSpace(3f); dataSet.setIconsOffset(new MPPointF(0, 40)); dataSet.setSelectionShift(5f); ArrayList<Integer> colors = new ArrayList<>(); for (int c : ColorTemplate.LIBERTY_COLORS) colors.add(c); dataSet.setColors(colors); PieData data = new PieData(dataSet); data.setValueFormatter(new PercentFormatter()); data.setValueTextSize(11f); data.setValueTextColor(Color.GRAY); pieChart.setData(data); pieChart.highlightValues(null); pieChart.invalidate(); }
/** * generates a random ChartData object with just one DataSet * * @return */ private PieData generateDataPie(int cnt) { ArrayList<Entry> entries = new ArrayList<Entry>(); for (int i = 0; i < 4; i++) { entries.add(new Entry((int) (Math.random() * 70) + 30, i)); } PieDataSet d = new PieDataSet(entries, ""); // space between slices d.setSliceSpace(2f); d.setColors(ColorTemplate.VORDIPLOM_COLORS); PieData cd = new PieData(getQuarters(), d); return cd; }
private void setupChart(String shortClicks, String longClicks) { List<PieEntry> entries = new ArrayList<>(); Float short_actual = Float.parseFloat(shortClicks); Float long_actual = Float.parseFloat(longClicks); Float short_final_percent = (short_actual / (long_actual + short_actual)) * 100; Float long_final_percent = (long_actual / (long_actual + short_actual)) * 100; if (short_actual != Float.parseFloat("0")) entries.add(new PieEntry(short_final_percent, getString(R.string.short_url_clicks_pie_chart))); if (long_actual != Float.parseFloat("0")) entries.add(new PieEntry(long_final_percent, getString(R.string.long_url_click_pie_chart))); PieDataSet set = new PieDataSet(entries, getString(R.string.url_clikc_count_pie_chart)); set.setColors(ColorTemplate.MATERIAL_COLORS); PieData data = new PieData(set); pieChart.setData(data); pieChart.invalidate(); // refresh if (pieChart.isEmpty()) { pieChart.setVisibility(View.GONE); errorLayout.setVisibility(View.VISIBLE); } }
/** * generates a random ChartData object with just one DataSet */ private PieData generateDataPie() { ArrayList<Entry> entries = new ArrayList<Entry>(); for (int i = 0; i < 4; i++) { entries.add(new Entry((int) (Math.random() * 70) + 30, i)); } PieDataSet d = new PieDataSet(entries, ""); // 设置各个扇形部分之间的间距 d.setSliceSpace(12f); // 设置各个扇形部分的颜色 d.setColors(ColorTemplate.VORDIPLOM_COLORS); PieData cd = new PieData(getQuarters(), d); return cd; }
public PieDataSet createPieDataSet(List<PieEntry> pieEntryList, @Nullable String label, @Nullable List<Integer> colors) { PieDataSet pieDataSet = new PieDataSet(pieEntryList, label); pieDataSet.setSliceSpace(1.5f); pieDataSet.setSelectionShift(2f); pieDataSet.setDrawValues(true); if (colors == null) { colors = new ArrayList<>(3); colors.add(utilsUI.getColor(R.color.colorPrimaryDark)); colors.add(utilsUI.getColor(R.color.colorPrimary)); colors.add(utilsUI.getColor(R.color.colorAccent)); } pieDataSet.setColors(colors); return pieDataSet; }
private void showResults(NutritionAnalysisResult nutritionAnalysisResult) { if (nutritionAnalysisResult == null) return; calories.set(context.getString(R.string.calories, nutritionAnalysisResult.getCalories())); yield.set(context.getString(R.string.yields, String.valueOf(nutritionAnalysisResult.getYield()))); List<PieEntry> pieEntries = diagramUtils.preparePieEntries(nutritionAnalysisResult.getTotalNutrients()); chartVisibility.set(pieEntries.isEmpty() ? View.GONE : View.VISIBLE); if (pieEntries.isEmpty()) return; PieDataSet pieDataSet = diagramUtils.createPieDataSet(pieEntries, "Nutrients", null); pieData = diagramUtils.createPieData(pieDataSet); if (onDataLoadedListener != null) onDataLoadedListener.onDataLoaded(pieData); }
@NonNull private PieData getData(Leader leader) { RealmList<Language> languages = leader.getRunningTotal().getLanguages(); List<PieEntry> entries = new ArrayList<>(languages.size()); List<Integer> colors = new ArrayList<>(languages.size()); for (Language language : languages) { entries.add(new PieEntry(language.getTotalSeconds(), language.getName())); colors.add(linguist.decode(language.getName())); } PieDataSet pieDataSet = new PieDataSet(entries, getString(R.string.languages)); pieDataSet.setColors(colors); pieDataSet.setSliceSpace(3f); pieDataSet.setSelectionShift(5f); PieData pieData = new PieData(pieDataSet); pieData.setValueFormatter((value, entry, dataSetIndex, viewPortHandler) -> String.valueOf(toMinutes((long) value))); pieData.setValueTextSize(16f); pieData.setValueTextColor(Color.WHITE); return pieData; }
public static PieChart defaultLanguageChart(List<Language> languages, PieChart chart, Linguist linguist) { chart.setCenterText(chart.getContext().getString(R.string.title_languages)); List<PieEntry> dataSet = new ArrayList<>(languages.size()); List<Integer> colors = new ArrayList<>(languages.size()); for (Language language : languages) { dataSet.add(new PieEntry(language.getPercent(), language.getName())); int color = linguist.decode(language.getName()); colors.add(color); } PieDataSet pieDataSet = new PieDataSet(dataSet, chart.getContext().getString(R.string.title_languages)); pieDataSet.setValueTextColor(Color.WHITE); pieDataSet.setSliceSpace(3f); pieDataSet.setSelectionShift(5f); pieDataSet.setColors(colors); pieDataSet.setValueTextSize(14f); PieData pieData = new PieData(pieDataSet); pieData.setValueFormatter(new PercentFormatter()); chart.setData(pieData); return chart; }
public static PieChart defaultOSChart(List<OperatingSystem> operatingSystems, PieChart chart, Linguist linguist) { chart.setCenterText(chart.getContext().getString(R.string.title_os)); List<PieEntry> entries = new ArrayList<>(operatingSystems.size()); List<Integer> colors = new ArrayList<>(operatingSystems.size()); for (OperatingSystem operatingSystem : operatingSystems) { entries.add(new PieEntry(operatingSystem.getPercent(), operatingSystem.getName())); colors.add(linguist.decodeOS(operatingSystem.getName())); } PieDataSet pieDataSet = new PieDataSet(entries, chart.getContext().getString(R.string.title_os)); pieDataSet.setColors(colors); pieDataSet.setSliceSpace(3f); pieDataSet.setSelectionShift(5f); pieDataSet.setValueTextSize(14f); pieDataSet.setValueTextColor(Color.WHITE); PieData pieData = new PieData(pieDataSet); pieData.setValueFormatter(new PercentFormatter()); chart.setData(pieData); return chart; }
public static PieChart defaultEditorsChart(List<Editor> editors, PieChart chart) { chart.setCenterText(chart.getContext().getString(R.string.title_editors)); int size = 0; if (editors != null) { size = editors.size(); } List<PieEntry> dataSet = new ArrayList<>(size); //noinspection Convert2streamapi for (Editor editor : editors) { dataSet.add(new PieEntry(editor.getPercent(), editor.getName())); } PieDataSet pieDataSet = new PieDataSet(dataSet, chart.getContext().getString(R.string.title_editors)); pieDataSet.setColors(ColorTemplate.JOYFUL_COLORS); pieDataSet.setValueTextColor(Color.WHITE); pieDataSet.setValueTextSize(14f); pieDataSet.setSliceSpace(3f); pieDataSet.setSelectionShift(5f); PieData pieData = new PieData(pieDataSet); pieData.setValueFormatter(new PercentFormatter()); chart.setData(pieData); return chart; }
public PieData createPieChartData() { List<Entry> entries = new ArrayList<>(); entries.add(new Entry(50, 0)); entries.add(new Entry(25, 1)); entries.add(new Entry(12.5f, 2)); entries.add(new Entry(12.5f, 3)); PieDataSet data = new PieDataSet(entries, null); data.setDrawValues(false); data.setColors(new int[] { 0xFF673ab7, 0xFF2196f3, 0xFF4caf50, 0xFF009688 }); String[] labels = new String[] {"Blackberry", "Blueberry", "Green apple", "Seaweed"}; return new PieData(labels, data); }
/** * Initializes the PieChart with the given parameters. Automatically hides description and adds animation. * * @param chart: PieChart object defined in XML layout * @param colorTemplate: int[] array of colors, where each color is a resource, i.e. R.color.green * @param data: HashMap of section name label to value, i.e. "Yes": 40, "No": 60 */ public void initializeChart(PieChart chart, int[] colorTemplate, HashMap<String, Integer> data) { // Add y-values from data to the pie chart data set ArrayList<Entry> values = new ArrayList<Entry>(); int index = 0; for (int value : data.values()) values.add(new Entry(value, index++)); PieDataSet dataSet = new PieDataSet(values, ""); // Create section labels and disable x-value labels chart.setData(new PieData(new ArrayList<String>(data.keySet()), dataSet)); chart.setDrawXValues(false); // Add colors from color template dataSet.setColors(colorTemplate); // Hide description and legend chart.setDescription(""); chart.setDrawLegend(false); // Add animation chart.animateXY(1500, 1500); }
private void refreshSleepAmounts(List<ActivityData> samples) { ActivityAnalysis analysis = new ActivityAnalysis(); ActivityAmounts amounts = analysis.calculateActivityAmounts(samples); float hoursOfSleep = amounts.getTotalSeconds() / (float) (60 * 60); pieChart.setCenterText((int) hoursOfSleep + "h"); // FIXME PieData data = new PieData(); List<Entry> entries = new ArrayList<>(); List<Integer> colors = new ArrayList<>(); int index = 0; for (ActivityAmount amount : amounts.getAmounts()) { entries.add(new Entry(amount.getTotalSeconds(), index++)); colors.add(getColorFor(amount.getActivityKind())); data.addXValue(amount.getName()); } PieDataSet set = new PieDataSet(entries, "Sleep comparison"); set.setColors(colors); data.setDataSet(set); pieChart.setData(data); //setupLegend(pieChart); pieChart.invalidate(); }
public PieChartCustom(PieChart graphical, ArrayList<Entry> entries, String entriesLegend, ArrayList<String> labels, String chartDecription) { this.entries = entries; this.chart = graphical; this.dataset = new PieDataSet(entries, entriesLegend); this.data = new PieData(labels, this.dataset); this.colors = new ArrayList<>(); //chart.setTouchEnabled(false); this.legend = chart.getLegend(); if(chartDecription!= null) chart.setDescription(chartDecription); else chart.setDescription(""); float sum = 0f; for(int i = 0; i<entries.size(); i++) { sum += entries.get(i).getVal(); } this.chart.setCenterText(String.format("%1$s\n%2$.2f", "Total", sum)); this.chart.setCenterTextSize(16); Paint text = new Paint(); text.setTextAlign(Paint.Align.CENTER); this.chart.setPaint(text, Chart.PAINT_CENTER_TEXT); this.chart.setUsePercentValues(true); setDefaultChart(); setDefaultLegend(); }
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); }
private void setSizePieChart() { PieChart pieChart = (PieChart) findViewById(R.id.size_pie_chart); ArrayList<Entry> yVals = new ArrayList<Entry>(); yVals.add(new Entry(totalSize(DeviceDataContract.VideoDataEntry.TABLE_NAME, VideoDataCollector.videoColumnNames), 0)); yVals.add(new Entry(totalSize(DeviceDataContract.ImageDataEntry.TABLE_NAME, ImageDataCollector.imageColumnNames), 1)); yVals.add(new Entry(totalSize(DeviceDataContract.AudioDataEntry.TABLE_NAME, AudioDataCollector.audioColumnNames), 2)); yVals.add(new Entry(totalSize(DeviceDataContract.TextDataEntry.TABLE_NAME, TextDataCollector.textColumnNames), 3)); ArrayList<String> xVals = new ArrayList<String>(); xVals.add("Videos (kB)"); xVals.add("Images (kB)"); xVals.add("Audio (kB)"); xVals.add("Text files (kB)"); PieDataSet pieDataSet = new PieDataSet(yVals, ""); int[] colorsi = new int[] {R.color.red, R.color.blue, R.color.yellow, R.color.green} ; pieDataSet.setColors(colorsi, this); PieData data = new PieData(xVals, pieDataSet); pieChart.setDescription(""); pieChart.setData(data); }
private void setCountPieChart() { PieChart pieChart = (PieChart) findViewById(R.id.count_pie_chart); ArrayList<Entry> yVals = new ArrayList<Entry>(); yVals.add(new Entry(count(DeviceDataContract.VideoDataEntry.TABLE_NAME, VideoDataCollector.videoColumnNames), 0)); yVals.add(new Entry(count(DeviceDataContract.ImageDataEntry.TABLE_NAME, ImageDataCollector.imageColumnNames), 1)); yVals.add(new Entry(count(DeviceDataContract.AudioDataEntry.TABLE_NAME, AudioDataCollector.audioColumnNames), 2)); yVals.add(new Entry(count(DeviceDataContract.TextDataEntry.TABLE_NAME, TextDataCollector.textColumnNames), 3)); yVals.add(new Entry(count(DeviceDataContract.ApplicationDataEntry.TABLE_NAME, ApplicationDataCollector.applicationDataColumnNames), 4)); ArrayList<String> xVals = new ArrayList<String>(); xVals.add("Videos"); xVals.add("Images"); xVals.add("Audio"); xVals.add("Text files"); xVals.add("Applications"); PieDataSet pieDataSet = new PieDataSet(yVals, ""); int[] colorsi = new int[] {R.color.red, R.color.blue, R.color.yellow, R.color.green} ; pieDataSet.setColors(colorsi, this); PieData data = new PieData(xVals, pieDataSet); pieChart.setDescription(""); pieChart.setData(data); }
private void showPieChart(List<Exam> exams){ barChart.setVisibility(View.GONE); pieChart.setVisibility(View.VISIBLE); Map<String, Integer> gradeCount = calculateGradeDistribution(exams); List<PieEntry> entries = new ArrayList<>(); for (String GRADE : GRADES) { entries.add(new PieEntry(gradeCount.get(GRADE), GRADE)); } PieDataSet set = new PieDataSet(entries, getString(R.string.grades_without_weight)); set.setColors(GRADE_COLORS, this); set.setDrawValues(false); pieChart.setData(new PieData(set)); pieChart.setDrawEntryLabels(false); pieChart.getLegend().setWordWrapEnabled(true); pieChart.setDescription(null); pieChart.invalidate(); }
private void addData() { 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)); xEntrys.add(xData[i]); } PieDataSet pieDataSet = new PieDataSet(yEntrys, "Category History"); pieDataSet.setSliceSpace(2); pieDataSet.setValueTextSize(12); pieDataSet.setValueTextColor(Color.WHITE); ArrayList<Integer> colors = new ArrayList<>(); colors.add(Color.RED); colors.add(Color.BLUE); pieDataSet.setColors(colors); Legend legend = pieChart.getLegend(); List<LegendEntry> legends = new ArrayList<>(); LegendEntry red = new LegendEntry(); red.label = "Missed"; red.formColor = Color.RED; legends.add(red); LegendEntry blue = new LegendEntry(); blue.label = "Completed"; blue.formColor = Color.BLUE; legends.add(blue); pieChart.getLegend().setCustom(legends); legend.setForm(Legend.LegendForm.CIRCLE); PieData pieData = new PieData(pieDataSet); pieChart.setData(pieData); pieChart.invalidate(); pieChart.getDescription().setEnabled(false); }
/** * Set the pie chart data source */ public static PieData populatePieData(List<PieEntry> entries, String label){ PieDataSet dataSet = new PieDataSet(entries, label); dataSet.setSliceSpace(3f); dataSet.setSelectionShift(5f); //dataSet.setColors(populateColors());// add a lot of colors dataSet.setColors(ColorTemplate.MATERIAL_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.setValueTextSize(11f); return new PieData(dataSet); }
/** * Creates a PieData object containing entries with the numbers of due and not due challenges * * @return PieData object containing the numbers of the due and not due challenges */ public PieData findDueData() { //Calculate numbers for the data to be visualized DueChallengeLogic dueChallengeLogic = mUserLogicFactory.createDueChallengeLogic(mUser); //Retrieve due numbers int dueNumber = dueChallengeLogic.getDueChallenges(mCategoryId).size(); int notDueNumber = mChallengeDataSource.getByCategoryId(mCategoryId).size() - dueNumber; if (dueNumber + notDueNumber > 0) { //Create lists ArrayList<Entry> entries = new ArrayList<>(); ArrayList<String> labels = new ArrayList<>(); //Add entries labels.add(mApplication.getString(R.string.challenge_due_text)); entries.add(new Entry(dueNumber > 0 ? dueNumber : nullValue(notDueNumber), 0)); labels.add(mApplication.getString(R.string.challeng_not_due_text)); entries.add(new Entry(notDueNumber > 0 ? notDueNumber : nullValue(dueNumber), 1)); //Create dataset PieDataSet dataset = new PieDataSet(entries, ""); mSettings.applyDataSetSettings(dataset, StatisticType.TYPE_DUE); //Create data PieData data = new PieData(labels, dataset); mSettings.applyDataSettings(data); //Return the PieData object return data; } else return null; }
/** * Creates a PieData object containing entries with the numbers of challenges in each stage * * @return PieData object containing the numbers of the challenges in each stage */ public PieData findStageData() { //Create lists ArrayList<Entry> entries = new ArrayList<>(); ArrayList<String> labels = new ArrayList<>(); //Retrieve stage numbers int numbers[] = {0, 0, 0, 0, 0, 0}; int totalNumber = 0; for (int i = 0; i <= 5; i++) { numbers[i] = mCompletionDataSource.findByUserAndStageAndCategory(mUser, i + 1, mCategoryId).size(); totalNumber += numbers[i]; } if (totalNumber > 0) { //Add entries for (int i = 0; i <= 5; i++) { entries.add(new Entry(numbers[i] != 0 ? numbers[i] : nullValue(totalNumber), i)); labels.add("" + (i + 1)); } //Create dataset PieDataSet dataset = new PieDataSet(entries, ""); mSettings.applyDataSetSettings(dataset, StatisticType.TYPE_STAGE); //Create data PieData data = new PieData(labels, dataset); mSettings.applyDataSettings(data); //Return the PieData object return data; } else return null; }
/** * Applies the specified format to the PieDataSet Object. * * @param dataset the dataset which will be formatted * @param type the statistic type of the chart the format is applied to */ public void applyDataSetSettings(PieDataSet dataset, StatisticType type) { dataset.setSliceSpace(SLICE_SPACE); dataset.setValueTextSize(VALUE_TEXT_SIZE); dataset.setSelectionShift(SELECTION_SHIFT); if (type == StatisticType.TYPE_STAGE) { dataset.setColors(mColorsetStage); } else if (type == StatisticType.TYPE_DUE) { dataset.setColors(mColorsetDue); } else { dataset.setColors(mColorsetPlayed); } dataset.setValueFormatter(new CustomizedFormatter()); }
/** * generates less data (1 DataSet, 4 values) * @return */ protected PieData generatePieData() { int count = 4; ArrayList<Entry> entries1 = new ArrayList<Entry>(); ArrayList<String> xVals = new ArrayList<String>(); xVals.add("Quarter 1"); xVals.add("Quarter 2"); xVals.add("Quarter 3"); xVals.add("Quarter 4"); for(int i = 0; i < count; i++) { xVals.add("entry" + (i+1)); entries1.add(new Entry((float) (Math.random() * 60) + 40, i)); } 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(xVals, ds1); d.setValueTypeface(tf); return d; }
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(); }
private void addPieChartData(int correctAnswer, int noOfQuestion) { float[] yData; String[] xData = {getString(R.string.correct_quantity), getString(R.string.incorrect_quantity)}; ArrayList<Integer> colors = new ArrayList<>(); colors.add(ContextCompat.getColor(getContext(), R.color.colorDarkBlue)); colors.add(ContextCompat.getColor(getContext(), R.color.colorRaspberry)); if (correctAnswer == noOfQuestion) { yData = new float[]{100}; } else if (correctAnswer == 0) { yData = new float[]{100}; colors.remove(0); } else { float good = (float) correctAnswer * 100 / noOfQuestion; yData = new float[]{good, 100 - good}; } ArrayList<Entry> yValues = new ArrayList<>(); for (int i = 0; i < yData.length; i++) yValues.add(new Entry(yData[i], i)); ArrayList<String> xValues = new ArrayList<>(); Collections.addAll(xValues, xData); PieDataSet dataSet = new PieDataSet(yValues, getString(R.string.your_score)); dataSet.setColors(colors); dataSet.setSliceSpace(5); dataSet.setSelectionShift(10); PieData data = new PieData(xValues, dataSet); data.setValueFormatter(new PercentFormatter()); data.setValueTextColor(ContextCompat.getColor(getContext(), R.color.colorGrey)); data.setValueTextSize(20); pieChart.setData(data); pieChart.highlightValues(null); pieChart.invalidate(); }
private void setupPie(PieChart pieChart, int pos, float dados[], String labels[]) { List<PieEntry> entries = new ArrayList<>(); int index = 0; for (float dado : dados) { entries.add(new PieEntry(dado, labels[index])); index++; } //entries.add(new PieEntry(24.0f, "Red")); //entries.add(new PieEntry(30.8f, "Blue")); PieDataSet set = new PieDataSet(entries, ""); Description description = new Description(); description.setText(" "); pieChart.setDescription(description); set.setColors(ColorTemplate.MATERIAL_COLORS); PieData data = new PieData(set); pieChart.setData(data); pieChart.invalidate(); Legend l = pieChart.getLegend(); l.setFormSize(15f); // set the size of the legend forms/shapes l.setForm(Legend.LegendForm.CIRCLE); // set what type of form/shape should be used l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT); l.setOrientation(Legend.LegendOrientation.VERTICAL); l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP); l.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD)); l.setTextSize(18f); l.setTextColor(Color.BLACK); l.setXEntrySpace(5f); // set the space between the legend entries on the x-axis l.setYEntrySpace(5f); pieChart.animateXY(3000, 3000); }
@Override public void calculateOffsets() { super.calculateOffsets(); // prevent nullpointer when no data set if (mDataNotSet) return; float diameter = getDiameter(); float radius = diameter / 2f; PointF c = getCenterOffsets(); final List<PieDataSet> dataSets = mData.getDataSets(); float maxShift = 0.f; for (int i = 0; i < dataSets.size(); i++) { final float shift = dataSets.get(i).getSelectionShift(); if (shift > maxShift) maxShift = shift; } final float halfMaxShift = maxShift / 2.f; // create the circle box that will contain the pie-chart (the bounds of // the pie-chart) mCircleBox.set(c.x - radius + halfMaxShift, c.y - radius + halfMaxShift, c.x + radius - halfMaxShift, c.y + radius - halfMaxShift); }