Search in sources :

Example 6 with PieEntry

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;
}
Also used : PieEntry(com.github.mikephil.charting.data.PieEntry) PieDataSet(com.github.mikephil.charting.data.PieDataSet) ArrayList(java.util.ArrayList) PieData(com.github.mikephil.charting.data.PieData)

Example 7 with PieEntry

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;
}
Also used : PieEntry(com.github.mikephil.charting.data.PieEntry) PieDataSet(com.github.mikephil.charting.data.PieDataSet) ArrayList(java.util.ArrayList) PieData(com.github.mikephil.charting.data.PieData)

Example 8 with PieEntry

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);
}
Also used : PieEntry(com.github.mikephil.charting.data.PieEntry) ArrayList(java.util.ArrayList) ActivityAmount(nodomain.freeyourgadget.gadgetbridge.model.ActivityAmount) ViewPortHandler(com.github.mikephil.charting.utils.ViewPortHandler) Entry(com.github.mikephil.charting.data.Entry) LegendEntry(com.github.mikephil.charting.components.LegendEntry) PieEntry(com.github.mikephil.charting.data.PieEntry) IValueFormatter(com.github.mikephil.charting.formatter.IValueFormatter) ActivityAmounts(nodomain.freeyourgadget.gadgetbridge.model.ActivityAmounts) PieDataSet(com.github.mikephil.charting.data.PieDataSet) PieData(com.github.mikephil.charting.data.PieData)

Example 9 with PieEntry

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));
}
Also used : PieEntry(com.github.mikephil.charting.data.PieEntry) PieDataSet(com.github.mikephil.charting.data.PieDataSet) ActivityAmounts(nodomain.freeyourgadget.gadgetbridge.model.ActivityAmounts) ArrayList(java.util.ArrayList) PieData(com.github.mikephil.charting.data.PieData)

Example 10 with PieEntry

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);
}
Also used : PieEntry(com.github.mikephil.charting.data.PieEntry) PieDataSet(com.github.mikephil.charting.data.PieDataSet) ArrayList(java.util.ArrayList) PieData(com.github.mikephil.charting.data.PieData)

Aggregations

PieData (com.github.mikephil.charting.data.PieData)11 PieDataSet (com.github.mikephil.charting.data.PieDataSet)11 PieEntry (com.github.mikephil.charting.data.PieEntry)11 ArrayList (java.util.ArrayList)10 PercentFormatter (com.github.mikephil.charting.formatter.PercentFormatter)3 IValueFormatter (com.github.mikephil.charting.formatter.IValueFormatter)2 MPPointF (com.github.mikephil.charting.utils.MPPointF)2 ActivityAmounts (nodomain.freeyourgadget.gadgetbridge.model.ActivityAmounts)2 Paint (android.graphics.Paint)1 Point (android.graphics.Point)1 Drawable (android.graphics.drawable.Drawable)1 RecyclerView (android.support.v7.widget.RecyclerView)1 TextPaint (android.text.TextPaint)1 View (android.view.View)1 TextView (android.widget.TextView)1 LegendEntry (com.github.mikephil.charting.components.LegendEntry)1 Entry (com.github.mikephil.charting.data.Entry)1 IPieDataSet (com.github.mikephil.charting.interfaces.datasets.IPieDataSet)1 ViewPortHandler (com.github.mikephil.charting.utils.ViewPortHandler)1 NumberFormat (java.text.NumberFormat)1