com.github.mikephil.charting.interfaces.datasets.IPieDataSet Java Examples

The following examples show how to use com.github.mikephil.charting.interfaces.datasets.IPieDataSet. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FragmentPieChart.java    From fingen with Apache License 2.0 6 votes vote down vote up
@Override
public void onValueSelected(Entry e, int dataSetIndex, Highlight h) {
    ReportBuilder reportBuilder = ReportBuilder.getInstance(getActivity());
    IAbstractModel model = (IAbstractModel) e.getData();
    if (reportBuilder.getParentID() != model.getID() && AbstractModelManager.getAllChildren(model, getActivity()).size() > 0) {
        reportBuilder.setParentID(model.getID());
        updateChart(true);
        return;
    }
    CabbageFormatter cabbageFormatter = null;
    try {
        cabbageFormatter = new CabbageFormatter(reportBuilder.getActiveCabbage());
    } catch (Exception e1) {
        e1.printStackTrace();
    }
    String s = String.format("%s %s", e.getData().toString(), cabbageFormatter.format(new BigDecimal(e.getVal())));
    GradientDrawable bgShape = (GradientDrawable) mImageViewColor.getBackground();
    IPieDataSet dataSet = mPieChart.getData().getDataSet();
    bgShape.setColor(dataSet.getColor(dataSet.getEntryIndex(e)));
    mTextViewSelected.setText(s);

    mFabLayout.setVisibility(View.VISIBLE);
    mImageViewColor.setVisibility(View.VISIBLE);
    mTextViewSelected.setVisibility(View.VISIBLE);
}
 
Example #2
Source File: PieChartRenderer.java    From StockChart-MPAndroidChart with MIT License 5 votes vote down vote up
/**
 * Calculates the sliceSpace to use based on visible values and their size compared to the set sliceSpace.
 *
 * @param dataSet
 * @return
 */
protected float getSliceSpace(IPieDataSet dataSet) {

    if (!dataSet.isAutomaticallyDisableSliceSpacingEnabled()) {
        return dataSet.getSliceSpace();
    }

    float spaceSizeRatio = dataSet.getSliceSpace() / mViewPortHandler.getSmallestContentExtension();
    float minValueRatio = dataSet.getYMin() / mChart.getData().getYValueSum() * 2;

    float sliceSpace = spaceSizeRatio > minValueRatio ? 0f : dataSet.getSliceSpace();

    return sliceSpace;
}
 
Example #3
Source File: PieChartRenderer.java    From Ticket-Analysis with MIT License 5 votes vote down vote up
@Override
public void drawData(Canvas c) {

    int width = (int) mViewPortHandler.getChartWidth();
    int height = (int) mViewPortHandler.getChartHeight();

    if (mDrawBitmap == null
            || (mDrawBitmap.get().getWidth() != width)
            || (mDrawBitmap.get().getHeight() != height)) {

        if (width > 0 && height > 0) {

            mDrawBitmap = new WeakReference<Bitmap>(Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_4444));
            mBitmapCanvas = new Canvas(mDrawBitmap.get());
        } else
            return;
    }

    mDrawBitmap.get().eraseColor(Color.TRANSPARENT);

    PieData pieData = mChart.getData();

    for (IPieDataSet set : pieData.getDataSets()) {

        if (set.isVisible() && set.getEntryCount() > 0)
            drawDataSet(c, set);
    }
}
 
Example #4
Source File: PieChartRenderer.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
@Override
public void drawData(Canvas c) {

    int width = (int) mViewPortHandler.getChartWidth();
    int height = (int) mViewPortHandler.getChartHeight();

    if (mDrawBitmap == null
            || (mDrawBitmap.get().getWidth() != width)
            || (mDrawBitmap.get().getHeight() != height)) {

        if (width > 0 && height > 0) {

            mDrawBitmap = new WeakReference<Bitmap>(Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_4444));
            mBitmapCanvas = new Canvas(mDrawBitmap.get());
        } else
            return;
    }

    mDrawBitmap.get().eraseColor(Color.TRANSPARENT);

    PieData pieData = mChart.getData();

    for (IPieDataSet set : pieData.getDataSets()) {

        if (set.isVisible() && set.getEntryCount() > 0)
            drawDataSet(c, set);
    }
}
 
Example #5
Source File: PieChart.java    From Ticket-Analysis with MIT License 5 votes vote down vote up
/**
 * Returns the index of the DataSet this x-index belongs to.
 *
 * @param xIndex
 * @return
 */
public int getDataSetIndexForIndex(int xIndex) {

    List<IPieDataSet> dataSets = mData.getDataSets();

    for (int i = 0; i < dataSets.size(); i++) {
        if (dataSets.get(i).getEntryForXValue(xIndex, Float.NaN) != null)
            return i;
    }

    return -1;
}
 
Example #6
Source File: PieChart.java    From NetKnight with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the index of the DataSet this x-index belongs to.
 *
 * @param xIndex
 * @return
 */
public int getDataSetIndexForIndex(int xIndex) {

    List<IPieDataSet> dataSets = mData.getDataSets();

    for (int i = 0; i < dataSets.size(); i++) {
        if (dataSets.get(i).getEntryForXIndex(xIndex) != null)
            return i;
    }

    return -1;
}
 
Example #7
Source File: PieChartRenderer.java    From StockChart-MPAndroidChart with MIT License 5 votes vote down vote up
@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);
        }
    }
}
 
Example #8
Source File: PieChart.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the index of the DataSet this x-index belongs to.
 *
 * @param xIndex
 * @return
 */
public int getDataSetIndexForIndex(int xIndex) {

    List<IPieDataSet> dataSets = mData.getDataSets();

    for (int i = 0; i < dataSets.size(); i++) {
        if (dataSets.get(i).getEntryForXIndex(xIndex) != null)
            return i;
    }

    return -1;
}
 
Example #9
Source File: PieChart.java    From android-kline with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the index of the DataSet this x-index belongs to.
 *
 * @param xIndex
 * @return
 */
public int getDataSetIndexForIndex(int xIndex) {

    List<IPieDataSet> dataSets = mData.getDataSets();

    for (int i = 0; i < dataSets.size(); i++) {
        if (dataSets.get(i).getEntryForXValue(xIndex, Float.NaN) != null)
            return i;
    }

    return -1;
}
 
Example #10
Source File: PieChartRenderer.java    From android-kline with Apache License 2.0 5 votes vote down vote up
@Override
public void drawData(Canvas c) {

    int width = (int) mViewPortHandler.getChartWidth();
    int height = (int) mViewPortHandler.getChartHeight();

    if (mDrawBitmap == null
            || (mDrawBitmap.get().getWidth() != width)
            || (mDrawBitmap.get().getHeight() != height)) {

        if (width > 0 && height > 0) {

            mDrawBitmap = new WeakReference<Bitmap>(Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_4444));
            mBitmapCanvas = new Canvas(mDrawBitmap.get());
        } else
            return;
    }

    mDrawBitmap.get().eraseColor(Color.TRANSPARENT);

    PieData pieData = mChart.getData();

    for (IPieDataSet set : pieData.getDataSets()) {

        if (set.isVisible() && set.getEntryCount() > 0)
            drawDataSet(c, set);
    }
}
 
Example #11
Source File: PieChartRenderer.java    From NetKnight with Apache License 2.0 5 votes vote down vote up
@Override
public void drawData(Canvas c) {

    int width = (int) mViewPortHandler.getChartWidth();
    int height = (int) mViewPortHandler.getChartHeight();

    if (mDrawBitmap == null
            || (mDrawBitmap.get().getWidth() != width)
            || (mDrawBitmap.get().getHeight() != height)) {

        if (width > 0 && height > 0) {

            mDrawBitmap = new WeakReference<Bitmap>(Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_4444));
            mBitmapCanvas = new Canvas(mDrawBitmap.get());
        } else
            return;
    }

    mDrawBitmap.get().eraseColor(Color.TRANSPARENT);

    PieData pieData = mChart.getData();

    for (IPieDataSet set : pieData.getDataSets()) {

        if (set.isVisible() && set.getEntryCount() > 0)
            drawDataSet(c, set);
    }
}
 
Example #12
Source File: PieChart.java    From StockChart-MPAndroidChart with MIT License 5 votes vote down vote up
/**
 * Returns the index of the DataSet this x-index belongs to.
 *
 * @param xIndex
 * @return
 */
public int getDataSetIndexForIndex(int xIndex) {

    List<IPieDataSet> dataSets = mData.getDataSets();

    for (int i = 0; i < dataSets.size(); i++) {
        if (dataSets.get(i).getEntryForXValue(xIndex, Float.NaN) != null) {
            return i;
        }
    }

    return -1;
}
 
Example #13
Source File: PieChartRenderer.java    From Stayfit with Apache License 2.0 4 votes vote down vote up
/**
 * This gives all pie-slices a rounded edge.
 *
 * @param c
 */
protected void drawRoundedSlices(Canvas c) {

    if (!mChart.isDrawRoundedSlicesEnabled())
        return;

    IPieDataSet dataSet = mChart.getData().getDataSet();

    if (!dataSet.isVisible())
        return;

    float phaseX = mAnimator.getPhaseX();
    float phaseY = mAnimator.getPhaseY();

    PointF center = mChart.getCenterCircleBox();
    float r = mChart.getRadius();

    // calculate the radius of the "slice-circle"
    float circleRadius = (r - (r * mChart.getHoleRadius() / 100f)) / 2f;

    float[] drawAngles = mChart.getDrawAngles();
    float angle = mChart.getRotationAngle();

    for (int j = 0; j < dataSet.getEntryCount(); j++) {

        float sliceAngle = drawAngles[j];

        Entry e = dataSet.getEntryForIndex(j);

        // draw only if the value is greater than zero
        if ((Math.abs(e.getVal()) > 0.000001)) {

            float x = (float) ((r - circleRadius)
                    * Math.cos(Math.toRadians((angle + sliceAngle)
                    * phaseY)) + center.x);
            float y = (float) ((r - circleRadius)
                    * Math.sin(Math.toRadians((angle + sliceAngle)
                    * phaseY)) + center.y);

            mRenderPaint.setColor(dataSet.getColor(j));
            mBitmapCanvas.drawCircle(x, y, circleRadius, mRenderPaint);
        }

        angle += sliceAngle * phaseX;
    }
}
 
Example #14
Source File: RealmPieData.java    From Stayfit with Apache License 2.0 4 votes vote down vote up
public RealmPieData(RealmResults<? extends RealmObject> result, String xValuesField, IPieDataSet dataSet) {
    super(RealmUtils.toXVals(result, xValuesField), dataSet);
}
 
Example #15
Source File: PieData.java    From Stayfit with Apache License 2.0 4 votes vote down vote up
public PieData(List<String> xVals, IPieDataSet dataSet) {
    super(xVals, toList(dataSet));
}
 
Example #16
Source File: PieChartRenderer.java    From android-kline with Apache License 2.0 4 votes vote down vote up
/**
 * This gives all pie-slices a rounded edge.
 *
 * @param c
 */
protected void drawRoundedSlices(Canvas c) {

    if (!mChart.isDrawRoundedSlicesEnabled())
        return;

    IPieDataSet dataSet = mChart.getData().getDataSet();

    if (!dataSet.isVisible())
        return;

    float phaseX = mAnimator.getPhaseX();
    float phaseY = mAnimator.getPhaseY();

    MPPointF center = mChart.getCenterCircleBox();
    float r = mChart.getRadius();

    // calculate the radius of the "slice-circle"
    float circleRadius = (r - (r * mChart.getHoleRadius() / 100f)) / 2f;

    float[] drawAngles = mChart.getDrawAngles();
    float angle = mChart.getRotationAngle();

    for (int j = 0; j < dataSet.getEntryCount(); j++) {

        float sliceAngle = drawAngles[j];

        Entry e = dataSet.getEntryForIndex(j);

        // draw only if the value is greater than zero
        if ((Math.abs(e.getY()) > Utils.FLOAT_EPSILON)) {

            float x = (float) ((r - circleRadius)
                    * Math.cos(Math.toRadians((angle + sliceAngle)
                    * phaseY)) + center.x);
            float y = (float) ((r - circleRadius)
                    * Math.sin(Math.toRadians((angle + sliceAngle)
                    * phaseY)) + center.y);

            mRenderPaint.setColor(dataSet.getColor(j));
            mBitmapCanvas.drawCircle(x, y, circleRadius, mRenderPaint);
        }

        angle += sliceAngle * phaseX;
    }
    MPPointF.recycleInstance(center);
}
 
Example #17
Source File: PieData.java    From Stayfit with Apache License 2.0 4 votes vote down vote up
public PieData(String[] xVals, IPieDataSet dataSet) {
    super(xVals, toList(dataSet));
}
 
Example #18
Source File: PieData.java    From Stayfit with Apache License 2.0 4 votes vote down vote up
private static List<IPieDataSet> toList(IPieDataSet dataSet) {
    List<IPieDataSet> sets = new ArrayList<IPieDataSet>();
    sets.add(dataSet);
    return sets;
}
 
Example #19
Source File: PieData.java    From Stayfit with Apache License 2.0 4 votes vote down vote up
/**
 * Sets the PieDataSet this data object should represent.
 *
 * @param dataSet
 */
public void setDataSet(IPieDataSet dataSet) {
    mDataSets.clear();
    mDataSets.add(dataSet);
    init();
}
 
Example #20
Source File: PieData.java    From Stayfit with Apache License 2.0 4 votes vote down vote up
@Override
public IPieDataSet getDataSetByLabel(String label, boolean ignorecase) {
    return ignorecase ? label.equalsIgnoreCase(mDataSets.get(0).getLabel()) ? mDataSets.get(0)
            : null : label.equals(mDataSets.get(0).getLabel()) ? mDataSets.get(0) : null;
}
 
Example #21
Source File: PieData.java    From android-kline with Apache License 2.0 4 votes vote down vote up
@Override
public IPieDataSet getDataSetByLabel(String label, boolean ignorecase) {
    return ignorecase ? label.equalsIgnoreCase(mDataSets.get(0).getLabel()) ? mDataSets.get(0)
            : null : label.equals(mDataSets.get(0).getLabel()) ? mDataSets.get(0) : null;
}
 
Example #22
Source File: RealmPieData.java    From NetKnight with Apache License 2.0 4 votes vote down vote up
public RealmPieData(RealmResults<? extends RealmObject> result, String xValuesField, IPieDataSet dataSet) {
    super(RealmUtils.toXVals(result, xValuesField), dataSet);
}
 
Example #23
Source File: PieData.java    From NetKnight with Apache License 2.0 4 votes vote down vote up
public PieData(List<String> xVals, IPieDataSet dataSet) {
    super(xVals, toList(dataSet));
}
 
Example #24
Source File: PieData.java    From NetKnight with Apache License 2.0 4 votes vote down vote up
public PieData(String[] xVals, IPieDataSet dataSet) {
    super(xVals, toList(dataSet));
}
 
Example #25
Source File: PieData.java    From NetKnight with Apache License 2.0 4 votes vote down vote up
private static List<IPieDataSet> toList(IPieDataSet dataSet) {
    List<IPieDataSet> sets = new ArrayList<IPieDataSet>();
    sets.add(dataSet);
    return sets;
}
 
Example #26
Source File: PieData.java    From NetKnight with Apache License 2.0 4 votes vote down vote up
/**
 * Sets the PieDataSet this data object should represent.
 *
 * @param dataSet
 */
public void setDataSet(IPieDataSet dataSet) {
    mDataSets.clear();
    mDataSets.add(dataSet);
    init();
}
 
Example #27
Source File: PieData.java    From NetKnight with Apache License 2.0 4 votes vote down vote up
@Override
public IPieDataSet getDataSetByLabel(String label, boolean ignorecase) {
    return ignorecase ? label.equalsIgnoreCase(mDataSets.get(0).getLabel()) ? mDataSets.get(0)
            : null : label.equals(mDataSets.get(0).getLabel()) ? mDataSets.get(0) : null;
}
 
Example #28
Source File: PieChartRenderer.java    From NetKnight with Apache License 2.0 4 votes vote down vote up
/**
 * This gives all pie-slices a rounded edge.
 *
 * @param c
 */
protected void drawRoundedSlices(Canvas c) {

    if (!mChart.isDrawRoundedSlicesEnabled())
        return;

    IPieDataSet dataSet = mChart.getData().getDataSet();

    if (!dataSet.isVisible())
        return;

    float phaseX = mAnimator.getPhaseX();
    float phaseY = mAnimator.getPhaseY();

    PointF center = mChart.getCenterCircleBox();
    float r = mChart.getRadius();

    // calculate the radius of the "slice-circle"
    float circleRadius = (r - (r * mChart.getHoleRadius() / 100f)) / 2f;

    float[] drawAngles = mChart.getDrawAngles();
    float angle = mChart.getRotationAngle();

    for (int j = 0; j < dataSet.getEntryCount(); j++) {

        float sliceAngle = drawAngles[j];

        Entry e = dataSet.getEntryForIndex(j);

        // draw only if the value is greater than zero
        if ((Math.abs(e.getVal()) > 0.000001)) {

            float x = (float) ((r - circleRadius)
                    * Math.cos(Math.toRadians((angle + sliceAngle)
                    * phaseY)) + center.x);
            float y = (float) ((r - circleRadius)
                    * Math.sin(Math.toRadians((angle + sliceAngle)
                    * phaseY)) + center.y);

            mRenderPaint.setColor(dataSet.getColor(j));
            mBitmapCanvas.drawCircle(x, y, circleRadius, mRenderPaint);
        }

        angle += sliceAngle * phaseX;
    }
}
 
Example #29
Source File: PieChart.java    From StockChart-MPAndroidChart with MIT License 4 votes vote down vote up
/**
 * 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();

    boolean hasMinAngle = mMinAngleForSlices != 0f && entryCount * mMinAngleForSlices <= mMaxAngle;
    float[] minAngles = new float[entryCount];

    int cnt = 0;
    float offset = 0f;
    float diff = 0f;

    for (int i = 0; i < mData.getDataSetCount(); i++) {

        IPieDataSet set = dataSets.get(i);

        for (int j = 0; j < set.getEntryCount(); j++) {

            float drawAngle = calcAngle(Math.abs(set.getEntryForIndex(j).getY()), yValueSum);

            if (hasMinAngle) {
                float temp = drawAngle - mMinAngleForSlices;
                if (temp <= 0) {
                    minAngles[cnt] = mMinAngleForSlices;
                    offset += -temp;
                } else {
                    minAngles[cnt] = drawAngle;
                    diff += temp;
                }
            }

            mDrawAngles[cnt] = drawAngle;

            if (cnt == 0) {
                mAbsoluteAngles[cnt] = mDrawAngles[cnt];
            } else {
                mAbsoluteAngles[cnt] = mAbsoluteAngles[cnt - 1] + mDrawAngles[cnt];
            }

            cnt++;
        }
    }

    if (hasMinAngle) {
        // Correct bigger slices by relatively reducing their angles based on the total angle needed to subtract
        // This requires that `entryCount * mMinAngleForSlices <= mMaxAngle` be true to properly work!
        for (int i = 0; i < entryCount; i++) {
            minAngles[i] -= (minAngles[i] - mMinAngleForSlices) / diff * offset;
            if (i == 0) {
                mAbsoluteAngles[0] = minAngles[0];
            } else {
                mAbsoluteAngles[i] = mAbsoluteAngles[i - 1] + minAngles[i];
            }
        }

        mDrawAngles = minAngles;
    }
}
 
Example #30
Source File: PieData.java    From StockChart-MPAndroidChart with MIT License 4 votes vote down vote up
@Override
public IPieDataSet getDataSetByLabel(String label, boolean ignorecase) {
    return ignorecase ? label.equalsIgnoreCase(mDataSets.get(0).getLabel()) ? mDataSets.get(0)
            : null : label.equals(mDataSets.get(0).getLabel()) ? mDataSets.get(0) : null;
}