Search in sources :

Example 1 with PieDataSet

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

the class Saldo method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View rootView = inflater.inflate(R.layout.fragment_saldo, container, false);
    // Texts
    ingresosT = (TextView) rootView.findViewById(R.id.cantIngreso);
    egresosT = (TextView) rootView.findViewById(R.id.cantGasto);
    saldoT = (TextView) rootView.findViewById(R.id.saldo);
    try {
        Double monto = Double.parseDouble(ingresos);
        Double monto2 = Double.parseDouble(egresos);
        Double monto3 = Double.parseDouble(saldo);
        NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.getDefault());
        ingresosT.setText(nf.format(monto));
        egresosT.setText(nf.format(monto2));
        saldoT.setText(nf.format(monto3));
    } catch (NumberFormatException e) {
    }
    // Piechart de ingresos egresos
    pieChart = (PieChart) rootView.findViewById(R.id.din);
    ArrayList<PieEntry> yEntrys = new ArrayList<PieEntry>();
    yEntrys.add(new PieEntry(Float.parseFloat(ingresos)));
    yEntrys.add(new PieEntry(Float.parseFloat(egresos)));
    PieDataSet pieDataSet = new PieDataSet(yEntrys, "");
    pieDataSet.setSliceSpace(2);
    pieDataSet.setColors(ColorTemplate.MATERIAL_COLORS[0], ColorTemplate.MATERIAL_COLORS[2]);
    pieChart.getDescription().setText("");
    pieChart.setUsePercentValues(true);
    pieChart.setHoleRadius(0);
    pieDataSet.setLabel("");
    pieDataSet.setValueTextSize(15);
    pieChart.getLegend().setFormSize(0);
    PieData pieData = new PieData(pieDataSet);
    pieChart.setData(pieData);
    pieChart.setDrawEntryLabels(false);
    pieChart.setTransparentCircleAlpha(0);
    /*pieChart.setHoleRadius(50);
        pieChart.setCenterText("%");
        pieChart.setCenterTextSize(25);
        */
    pieChart.invalidate();
    pieChart.animateXY(2000, 2000);
    pieChart.requestFocus();
    return rootView;
}
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) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) NumberFormat(java.text.NumberFormat)

Example 2 with PieDataSet

use of com.github.mikephil.charting.data.PieDataSet in project AmazeFileManager by TeamAmaze.

the class LoadFolderSpaceDataTask method updateChart.

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);
}
Also used : SpannableString(android.text.SpannableString) PieDataSet(com.github.mikephil.charting.data.PieDataSet) PieData(com.github.mikephil.charting.data.PieData) GeneralDialogCreation(com.amaze.filemanager.ui.dialogs.GeneralDialogCreation)

Example 3 with PieDataSet

use of com.github.mikephil.charting.data.PieDataSet in project HAR-Android by linw7.

the class HistoryActivity method get_pie_data.

private PieData get_pie_data() {
    // xVals用来表示每个饼块上的内容
    ArrayList<String> xValues = new ArrayList<String>();
    // 饼块上显示成Quarterly1, Quarterly2, Quarterly3, Quarterly4
    xValues.add("Jog");
    xValues.add("Walk");
    xValues.add("Sit");
    xValues.add("Stand");
    // yVals用来表示封装每个饼块的实际数据
    ArrayList<Entry> yValues = new ArrayList<Entry>();
    yValues.add(new Entry(14, 0));
    yValues.add(new Entry(14, 1));
    yValues.add(new Entry(34, 2));
    yValues.add(new Entry(38, 3));
    PieDataSet pieDataSet = new PieDataSet(yValues, "s");
    // 设置个饼状图之间的距离
    pieDataSet.setSliceSpace(0f);
    ArrayList<Integer> colors = new ArrayList<Integer>();
    colors.add(Color.rgb(205, 205, 205));
    colors.add(Color.rgb(114, 188, 223));
    colors.add(Color.rgb(255, 123, 124));
    colors.add(Color.rgb(57, 135, 200));
    pieDataSet.setColors(colors);
    DisplayMetrics metrics = getResources().getDisplayMetrics();
    float px = 5 * (metrics.densityDpi / 160f);
    // 选中态多出的长度
    pieDataSet.setSelectionShift(px);
    PieData pieData = new PieData(xValues, pieDataSet);
    return pieData;
}
Also used : Entry(com.github.mikephil.charting.data.Entry) PieDataSet(com.github.mikephil.charting.data.PieDataSet) ArrayList(java.util.ArrayList) PieData(com.github.mikephil.charting.data.PieData) DisplayMetrics(android.util.DisplayMetrics)

Example 4 with PieDataSet

use of com.github.mikephil.charting.data.PieDataSet in project Dxditor by kimi2009.

the class MainActivity method setGjxxData.

/**
 * 设置告警信息的数据
 *
 * @param gjxxlist
 */
@Override
public void setGjxxData(List<GjxxBean> gjxxlist) {
    ArrayList<PieEntry> entries = new ArrayList<PieEntry>();
    // the chart.
    for (int i = 0; i < gjxxlist.size(); i++) {
        entries.add(new PieEntry(gjxxlist.get(i).getTypeProportion() * 100, gjxxlist.get(i).getTypeName()));
    }
    PieDataSet dataSet = new PieDataSet(entries, "");
    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());
    // 26个颜色
    dataSet.setColors(colors);
    // dataSet.setSelectionShift(0f);
    dataSet.setValueLinePart1OffsetPercentage(80.f);
    dataSet.setValueLinePart1Length(0.2f);
    dataSet.setValueLinePart2Length(0.4f);
    // dataSet.setXValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);
    dataSet.setYValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);
    PieData data = new PieData(dataSet);
    data.setValueFormatter(new PercentFormatter());
    data.setValueTextSize(11f);
    data.setValueTextColor(Color.BLACK);
    gjpiechart.setData(data);
    // undo all highlights
    gjpiechart.highlightValues(null);
    gjpiechart.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)

Example 5 with PieDataSet

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

the class ListViewMultiChartActivity method generateDataPie.

/**
 * 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);
}
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

PieDataSet (com.github.mikephil.charting.data.PieDataSet)28 PieData (com.github.mikephil.charting.data.PieData)23 ArrayList (java.util.ArrayList)21 PieEntry (com.github.mikephil.charting.data.PieEntry)19 Entry (com.github.mikephil.charting.data.Entry)7 PercentFormatter (com.github.mikephil.charting.formatter.PercentFormatter)7 Paint (android.graphics.Paint)5 MPPointF (com.github.mikephil.charting.utils.MPPointF)4 SpannableString (android.text.SpannableString)2 DisplayMetrics (android.util.DisplayMetrics)2 View (android.view.View)2 TextView (android.widget.TextView)2 PieChart (com.github.mikephil.charting.charts.PieChart)2 Context (android.content.Context)1 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 Color (android.graphics.Color)1 PointF (android.graphics.PointF)1 RectF (android.graphics.RectF)1 Typeface (android.graphics.Typeface)1