Search in sources :

Example 11 with PieDataSet

use of com.github.mikephil.charting.data.PieDataSet 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 12 with PieDataSet

use of com.github.mikephil.charting.data.PieDataSet 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)

Example 13 with PieDataSet

use of com.github.mikephil.charting.data.PieDataSet in project AdMoney by ErnestoGonAr.

the class Reporte_Ingresos 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.setUsePercentValues(true);
    pieChart.setCenterText("%");
    pieChart.setCenterTextSize(30);
    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)

Example 14 with PieDataSet

use of com.github.mikephil.charting.data.PieDataSet in project MPAndroidChart by PhilJay.

the class HalfPieChartActivity method setData.

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();
}
Also used : PercentFormatter(com.github.mikephil.charting.formatter.PercentFormatter) 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) Point(android.graphics.Point)

Example 15 with PieDataSet

use of com.github.mikephil.charting.data.PieDataSet in project MPAndroidChart by PhilJay.

the class PieChartActivity method setData.

private void setData(int count, float range) {
    float mult = range;
    ArrayList<PieEntry> entries = new ArrayList<PieEntry>();
    // the chart.
    for (int i = 0; i < count; i++) {
        entries.add(new PieEntry((float) ((Math.random() * mult) + mult / 5), mParties[i % mParties.length], getResources().getDrawable(R.drawable.star)));
    }
    PieDataSet dataSet = new PieDataSet(entries, "Election 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>();
    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);
    colors.add(ColorTemplate.getHoloBlue());
    dataSet.setColors(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);
    // undo all highlights
    mChart.highlightValues(null);
    mChart.invalidate();
}
Also used : PercentFormatter(com.github.mikephil.charting.formatter.PercentFormatter) PieEntry(com.github.mikephil.charting.data.PieEntry) PieDataSet(com.github.mikephil.charting.data.PieDataSet) MPPointF(com.github.mikephil.charting.utils.MPPointF) ArrayList(java.util.ArrayList) PieData(com.github.mikephil.charting.data.PieData)

Aggregations

PieDataSet (com.github.mikephil.charting.data.PieDataSet)17 ArrayList (java.util.ArrayList)13 PieData (com.github.mikephil.charting.data.PieData)12 PieEntry (com.github.mikephil.charting.data.PieEntry)11 Paint (android.graphics.Paint)5 Entry (com.github.mikephil.charting.data.Entry)5 PercentFormatter (com.github.mikephil.charting.formatter.PercentFormatter)4 ActivityAmounts (nodomain.freeyourgadget.gadgetbridge.model.ActivityAmounts)2 Point (android.graphics.Point)1 PointF (android.graphics.PointF)1 RectF (android.graphics.RectF)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 TextView (android.widget.TextView)1 LegendEntry (com.github.mikephil.charting.components.LegendEntry)1 BarDataSet (com.github.mikephil.charting.data.BarDataSet)1 IValueFormatter (com.github.mikephil.charting.formatter.IValueFormatter)1 Legend (com.github.mikephil.charting.utils.Legend)1 MPPointF (com.github.mikephil.charting.utils.MPPointF)1 ViewPortHandler (com.github.mikephil.charting.utils.ViewPortHandler)1