Search in sources :

Example 21 with PieData

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

the class SimpleFragment method generatePieData.

/**
 * generates less data (1 DataSet, 4 values)
 * @return PieData
 */
protected PieData generatePieData() {
    int count = 4;
    ArrayList<PieEntry> entries1 = new ArrayList<>();
    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 22 with PieData

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

the class HalfPieChartActivity method setData.

private void setData(int count, float range) {
    ArrayList<PieEntry> values = new ArrayList<>();
    for (int i = 0; i < count; i++) {
        values.add(new PieEntry((float) ((Math.random() * range) + range / 5), parties[i % parties.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(tfLight);
    chart.setData(data);
    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 23 with PieData

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

the class PieChartActivity method setData.

private void setData(int count, float range) {
    ArrayList<PieEntry> entries = new ArrayList<>();
    // the chart.
    for (int i = 0; i < count; i++) {
        entries.add(new PieEntry((float) ((Math.random() * range) + range / 5), parties[i % parties.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<>();
    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(tfLight);
    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) MPPointF(com.github.mikephil.charting.utils.MPPointF) ArrayList(java.util.ArrayList) PieData(com.github.mikephil.charting.data.PieData)

Example 24 with PieData

use of com.github.mikephil.charting.data.PieData in project carat by amplab.

the class SummaryFragment method generatePieData.

protected PieData generatePieData() {
    ArrayList<Entry> entries = new ArrayList<Entry>();
    ArrayList<String> xVals = new ArrayList<String>();
    xVals.add(getString(R.string.chart_wellbehaved));
    xVals.add(getString(R.string.chart_hogs));
    xVals.add(getString(R.string.chart_bugs));
    int wellbehaved = mMainActivity.mWellbehaved;
    int hogs = mMainActivity.mHogs;
    int bugs = mMainActivity.mBugs;
    entries.add(new Entry((float) (wellbehaved), 1));
    entries.add(new Entry((float) (hogs), 2));
    entries.add(new Entry((float) (bugs), 3));
    PieDataSet ds1 = new PieDataSet(entries, getString(R.string.summary_chart_center_text));
    ds1.setColors(Constants.CARAT_COLORS);
    ds1.setSliceSpace(2f);
    PieData d = new PieData(xVals, ds1);
    return d;
}
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)

Example 25 with PieData

use of com.github.mikephil.charting.data.PieData in project anitrend-app by AniTrend.

the class MediaStatsFragment method showStatusDistribution.

private void showStatusDistribution() {
    if (model.getStats() != null && model.getStats().getStatusDistribution() != null) {
        configureSeriesStats();
        List<PieEntry> pieEntries = getPresenter().getMediaStats(model.getStats().getStatusDistribution());
        PieDataSet pieDataSet = new PieDataSet(pieEntries, getString(R.string.title_series_stats));
        pieDataSet.setSliceSpace(3f);
        pieDataSet.setColors(Color.parseColor("#6fc1ea"), Color.parseColor("#48c76d"), Color.parseColor("#f7464a"), Color.parseColor("#46bfbd"), Color.parseColor("#fba640"));
        PieData pieData = new PieData(pieDataSet);
        pieData.setValueTextColor(CompatUtil.getColorFromAttr(getContext(), R.attr.titleColor));
        pieData.setValueTextSize(10f);
        pieData.setValueFormatter(new PercentFormatter());
        binding.seriesStats.setData(pieData);
        binding.seriesStats.highlightValues(null);
        binding.seriesStats.invalidate();
    }
}
Also used : PercentFormatter(com.github.mikephil.charting.formatter.PercentFormatter) PieEntry(com.github.mikephil.charting.data.PieEntry) PieDataSet(com.github.mikephil.charting.data.PieDataSet) PieData(com.github.mikephil.charting.data.PieData)

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