Search in sources :

Example 6 with IPieDataSet

use of com.github.mikephil.charting.interfaces.datasets.IPieDataSet in project MPAndroidChart by PhilJay.

the class PieHighlighter method getClosestHighlight.

@Override
protected Highlight getClosestHighlight(int index, float x, float y) {
    IPieDataSet set = mChart.getData().getDataSet();
    final Entry entry = set.getEntryForIndex(index);
    return new Highlight(index, entry.getY(), x, y, 0, set.getAxisDependency());
}
Also used : Entry(com.github.mikephil.charting.data.Entry) IPieDataSet(com.github.mikephil.charting.interfaces.datasets.IPieDataSet)

Example 7 with IPieDataSet

use of com.github.mikephil.charting.interfaces.datasets.IPieDataSet in project MPAndroidChart by PhilJay.

the class PieChart method calcAngles.

/**
     * calculates the needed angles for the chart slices
     */
private void calcAngles() {
    int entryCount = mData.getEntryCount();
    if (mDrawAngles.length != entryCount) {
        mDrawAngles = new float[entryCount];
    } else {
        for (int i = 0; i < entryCount; i++) {
            mDrawAngles[i] = 0;
        }
    }
    if (mAbsoluteAngles.length != entryCount) {
        mAbsoluteAngles = new float[entryCount];
    } else {
        for (int i = 0; i < entryCount; i++) {
            mAbsoluteAngles[i] = 0;
        }
    }
    float yValueSum = mData.getYValueSum();
    List<IPieDataSet> dataSets = mData.getDataSets();
    int cnt = 0;
    for (int i = 0; i < mData.getDataSetCount(); i++) {
        IPieDataSet set = dataSets.get(i);
        for (int j = 0; j < set.getEntryCount(); j++) {
            mDrawAngles[cnt] = calcAngle(Math.abs(set.getEntryForIndex(j).getY()), yValueSum);
            if (cnt == 0) {
                mAbsoluteAngles[cnt] = mDrawAngles[cnt];
            } else {
                mAbsoluteAngles[cnt] = mAbsoluteAngles[cnt - 1] + mDrawAngles[cnt];
            }
            cnt++;
        }
    }
}
Also used : IPieDataSet(com.github.mikephil.charting.interfaces.datasets.IPieDataSet) Paint(android.graphics.Paint)

Aggregations

IPieDataSet (com.github.mikephil.charting.interfaces.datasets.IPieDataSet)7 Paint (android.graphics.Paint)6 TextPaint (android.text.TextPaint)4 MPPointF (com.github.mikephil.charting.utils.MPPointF)3 Entry (com.github.mikephil.charting.data.Entry)2 PieData (com.github.mikephil.charting.data.PieData)2 PieEntry (com.github.mikephil.charting.data.PieEntry)2 Bitmap (android.graphics.Bitmap)1 Canvas (android.graphics.Canvas)1 RectF (android.graphics.RectF)1 Typeface (android.graphics.Typeface)1 Drawable (android.graphics.drawable.Drawable)1 LegendEntry (com.github.mikephil.charting.components.LegendEntry)1 PieDataSet (com.github.mikephil.charting.data.PieDataSet)1 IValueFormatter (com.github.mikephil.charting.formatter.IValueFormatter)1 IBarDataSet (com.github.mikephil.charting.interfaces.datasets.IBarDataSet)1 ICandleDataSet (com.github.mikephil.charting.interfaces.datasets.ICandleDataSet)1 IDataSet (com.github.mikephil.charting.interfaces.datasets.IDataSet)1