Search in sources :

Example 6 with PieData

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

the class PieActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_pie);
    pie_chart = (PieChart) findViewById(R.id.pie_chart);
    PieData pie_data = get_pie_data();
    show_pie_chart(pie_chart, pie_data);
}
Also used : PieData(com.github.mikephil.charting.data.PieData)

Example 7 with PieData

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

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

Example 9 with PieData

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

the class PiePolylineChartActivity 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]));
    }
    PieDataSet dataSet = new PieDataSet(entries, "Election Results");
    dataSet.setSliceSpace(3f);
    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);
    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);
    data.setValueTypeface(tf);
    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 10 with PieData

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

the class PieChartRenderer method drawData.

@Override
public void drawData(Canvas c) {
    int width = (int) mViewPortHandler.getChartWidth();
    int height = (int) mViewPortHandler.getChartHeight();
    Bitmap drawBitmap = mDrawBitmap == null ? null : mDrawBitmap.get();
    if (drawBitmap == null || (drawBitmap.getWidth() != width) || (drawBitmap.getHeight() != height)) {
        if (width > 0 && height > 0) {
            drawBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_4444);
            mDrawBitmap = new WeakReference<>(drawBitmap);
            mBitmapCanvas = new Canvas(drawBitmap);
        } else
            return;
    }
    drawBitmap.eraseColor(Color.TRANSPARENT);
    PieData pieData = mChart.getData();
    for (IPieDataSet set : pieData.getDataSets()) {
        if (set.isVisible() && set.getEntryCount() > 0)
            drawDataSet(c, set);
    }
}
Also used : Bitmap(android.graphics.Bitmap) IPieDataSet(com.github.mikephil.charting.interfaces.datasets.IPieDataSet) Canvas(android.graphics.Canvas) PieData(com.github.mikephil.charting.data.PieData) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

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