Search in sources :

Example 1 with PieData

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

use of com.github.mikephil.charting.data.PieData in project run-wallet-android by runplay.

the class NetworkNodeInfoFragment method setData.

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<>();
    colors.add(B.getColor(getActivity(), AppTheme.getPrimaryDark()));
    colors.add(B.getColor(getActivity(), R.color.colorLight));
    colors.add(B.getColor(getActivity(), R.color.white));
    // for (int c : ColorTemplate.PASTEL_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(), AppTheme.getPrimary()));
    PieData data = new PieData(dataSet);
    data.setValueFormatter(new PercentFormatter());
    data.setValueTextSize(12f);
    data.setValueTextColor(ContextCompat.getColor(getActivity(), AppTheme.getPrimary()));
    chart.setData(data);
    // undo all highlights
    chart.highlightValues(null);
    chart.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)

Example 3 with PieData

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

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

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

the class HistoryActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_history);
    calendar = (CalendarView) findViewById(R.id.calendarView);
    pie_chart = (PieChart) findViewById(R.id.pie_chart);
    title_bar_back_btn = (ImageView) findViewById(R.id.title_bar_back_btn);
    line_chart = (LineChart) findViewById(R.id.line_chart);
    xAxis = line_chart.getXAxis();
    yAxis = line_chart.getAxisLeft();
    yAxisR = line_chart.getAxisRight();
    title_bar_back_btn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent i = new Intent(HistoryActivity.this, MainActivity.class);
            startActivity(i);
        }
    });
    LineData line_data = get_line_data();
    show_chart(line_chart, line_data);
    PieData pie_data = get_pie_data();
    show_pie_chart(pie_chart, pie_data);
}
Also used : LineData(com.github.mikephil.charting.data.LineData) PieData(com.github.mikephil.charting.data.PieData) Intent(android.content.Intent) CalendarView(android.widget.CalendarView) ImageView(android.widget.ImageView) View(android.view.View)

Aggregations

PieData (com.github.mikephil.charting.data.PieData)28 PieDataSet (com.github.mikephil.charting.data.PieDataSet)24 PieEntry (com.github.mikephil.charting.data.PieEntry)20 ArrayList (java.util.ArrayList)20 PercentFormatter (com.github.mikephil.charting.formatter.PercentFormatter)7 MPPointF (com.github.mikephil.charting.utils.MPPointF)5 Entry (com.github.mikephil.charting.data.Entry)4 View (android.view.View)3 Intent (android.content.Intent)2 Paint (android.graphics.Paint)2 SpannableString (android.text.SpannableString)2 TextPaint (android.text.TextPaint)2 DisplayMetrics (android.util.DisplayMetrics)2 TextView (android.widget.TextView)2 PieChart (com.github.mikephil.charting.charts.PieChart)2 IPieDataSet (com.github.mikephil.charting.interfaces.datasets.IPieDataSet)2 Context (android.content.Context)1 SharedPreferences (android.content.SharedPreferences)1 Bitmap (android.graphics.Bitmap)1 Canvas (android.graphics.Canvas)1