use of com.github.mikephil.charting.data.PieEntry in project MPAndroidChart by PhilJay.
the class SimpleFragment method generatePieData.
/**
* 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;
}
use of com.github.mikephil.charting.data.PieEntry in project MPAndroidChart by PhilJay.
the class ListViewMultiChartActivity method generateDataPie.
/**
* 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;
}
use of com.github.mikephil.charting.data.PieEntry in project Gadgetbridge by Freeyourgadget.
the class SleepChartFragment method refreshSleepAmounts.
private MySleepChartsData refreshSleepAmounts(GBDevice mGBDevice, List<? extends ActivitySample> samples) {
ActivityAnalysis analysis = new ActivityAnalysis();
ActivityAmounts amounts = analysis.calculateActivityAmounts(samples);
PieData data = new PieData();
List<PieEntry> entries = new ArrayList<>();
List<Integer> colors = new ArrayList<>();
// int index = 0;
long totalSeconds = 0;
for (ActivityAmount amount : amounts.getAmounts()) {
if ((amount.getActivityKind() & ActivityKind.TYPE_SLEEP) != 0) {
long value = amount.getTotalSeconds();
totalSeconds += value;
// entries.add(new PieEntry(value, index++));
entries.add(new PieEntry(value, amount.getName(getActivity())));
colors.add(getColorFor(amount.getActivityKind()));
// data.addXValue(amount.getName(getActivity()));
}
}
String totalSleep = DateTimeUtils.formatDurationHoursMinutes(totalSeconds, TimeUnit.SECONDS);
PieDataSet set = new PieDataSet(entries, "");
set.setValueFormatter(new IValueFormatter() {
@Override
public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
return DateTimeUtils.formatDurationHoursMinutes((long) value, TimeUnit.SECONDS);
}
});
set.setColors(colors);
data.setDataSet(set);
//setupLegend(pieChart);
return new MySleepChartsData(totalSleep, data);
}
use of com.github.mikephil.charting.data.PieEntry in project Gadgetbridge by Freeyourgadget.
the class AbstractWeekChartFragment method refreshDayPie.
private DayData refreshDayPie(DBHandler db, Calendar day, GBDevice device) {
PieData data = new PieData();
List<PieEntry> entries = new ArrayList<>();
PieDataSet set = new PieDataSet(entries, "");
ActivityAmounts amounts = getActivityAmountsForDay(db, day, device);
float[] totalValues = getTotalsForActivityAmounts(amounts);
float totalValue = 0;
for (float value : totalValues) {
totalValue += value;
entries.add(new PieEntry(value));
}
set.setValueFormatter(getPieValueFormatter());
set.setColors(getColors());
if (totalValue < mTargetValue) {
entries.add(new PieEntry((mTargetValue - totalValue)));
set.addColor(Color.GRAY);
}
data.setDataSet(set);
//this hides the values (numeric) added to the set. These would be shown aside the strings set with addXValue above
data.setDrawValues(false);
return new DayData(data, formatPieValue((int) totalValue));
}
use of com.github.mikephil.charting.data.PieEntry in project AdMoney by ErnestoGonAr.
the class Reporte_Egresos method addData.
private void addData() {
ArrayList<PieEntry> yEntrys = new ArrayList<>();
for (int i = 0; i < yData.length; i++) {
yEntrys.add(new PieEntry(yData[i], "$ " + yData[i] + " " + xData[i]));
}
PieDataSet pieDataSet = new PieDataSet(yEntrys, "");
pieDataSet.setSliceSpace(3);
pieDataSet.setValueTextSize(24);
ArrayList<Integer> colors = new ArrayList<Integer>();
for (int c : ColorTemplate.MATERIAL_COLORS) colors.add(c);
for (int c : ColorTemplate.VORDIPLOM_COLORS) colors.add(c);
for (int c : ColorTemplate.JOYFUL_COLORS) colors.add(c);
for (int c : ColorTemplate.COLORFUL_COLORS) colors.add(c);
for (int c : ColorTemplate.LIBERTY_COLORS) colors.add(c);
for (int c : ColorTemplate.PASTEL_COLORS) colors.add(c);
pieDataSet.setColors(colors);
PieData pieData = new PieData(pieDataSet);
pieChart.setDrawEntryLabels(false);
pieChart.setCenterText("%");
pieChart.setCenterTextSize(30);
pieChart.setUsePercentValues(true);
pieChart.setData(pieData);
pieChart.highlightValue(null);
pieChart.invalidate();
pieChart.animateXY(2000, 2000);
}
Aggregations