Java Code Examples for com.github.mikephil.charting.data.PieDataSet#getYVals()

The following examples show how to use com.github.mikephil.charting.data.PieDataSet#getYVals() . 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: PieChartRenderer.java    From iMoney with Apache License 2.0 5 votes vote down vote up
protected void drawDataSet(Canvas c, PieDataSet dataSet) {

        float angle = mChart.getRotationAngle();

        List<Entry> entries = dataSet.getYVals();
        float[] drawAngles = mChart.getDrawAngles();

        for (int j = 0; j < entries.size(); j++) {

            float newangle = drawAngles[j];
            float sliceSpace = dataSet.getSliceSpace();

            Entry e = entries.get(j);

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

                if (!mChart.needsHighlight(e.getXIndex(),
                        mChart.getData().getIndexOfDataSet(dataSet))) {

                    mRenderPaint.setColor(dataSet.getColor(j));
                    mBitmapCanvas.drawArc(mChart.getCircleBox(),
                            (angle + sliceSpace / 2f) * mAnimator.getPhaseY(),
                            (newangle - sliceSpace / 2f) * mAnimator.getPhaseY(),
                            true, mRenderPaint);
                }
            }

            angle += newangle * mAnimator.getPhaseX();
        }
    }
 
Example 2
Source File: PieChartRenderer.java    From iMoney with Apache License 2.0 4 votes vote down vote up
@Override
public void drawValues(Canvas c) {

    PointF center = mChart.getCenterCircleBox();

    // get whole the radius
    float r = mChart.getRadius();
    float rotationAngle = mChart.getRotationAngle();
    float[] drawAngles = mChart.getDrawAngles();
    float[] absoluteAngles = mChart.getAbsoluteAngles();

    float off = r / 10f * 3.6f;

    if (mChart.isDrawHoleEnabled()) {
        off = (r - (r / 100f * mChart.getHoleRadius())) / 2f;
    }

    r -= off; // offset to keep things inside the chart

    PieData data = mChart.getData();
    List<PieDataSet> dataSets = data.getDataSets();
    boolean drawXVals = mChart.isDrawSliceTextEnabled();

    int cnt = 0;

    for (int i = 0; i < dataSets.size(); i++) {

        PieDataSet dataSet = dataSets.get(i);

        if (!dataSet.isDrawValuesEnabled() && !drawXVals)
            continue;

        // apply the text-styling defined by the DataSet
        applyValueTextStyle(dataSet);

        float lineHeight = Utils.calcTextHeight(mValuePaint, "Q")
                + Utils.convertDpToPixel(4f);

        List<Entry> entries = dataSet.getYVals();

        for (int j = 0, maxEntry = Math.min(
                (int) Math.ceil(entries.size() * mAnimator.getPhaseX()), entries.size()); j < maxEntry; j++) {

            Entry entry = entries.get(j);

            // offset needed to center the drawn text in the slice
            float offset = drawAngles[cnt] / 2;

            // calculate the text position
            float x = (float) (r
                    * Math.cos(Math.toRadians((rotationAngle + absoluteAngles[cnt] - offset)
                    * mAnimator.getPhaseY())) + center.x);
            float y = (float) (r
                    * Math.sin(Math.toRadians((rotationAngle + absoluteAngles[cnt] - offset)
                            * mAnimator.getPhaseY())) + center.y);

            float value = mChart.isUsePercentValuesEnabled() ? entry.getVal()
                    / data.getYValueSum() * 100f : entry.getVal();

            ValueFormatter formatter = dataSet.getValueFormatter();

            boolean drawYVals = dataSet.isDrawValuesEnabled();

            // draw everything, depending on settings
            if (drawXVals && drawYVals) {

                drawValue(c, formatter, value, entry, 0, x, y);

                if (j < data.getXValCount())
                    c.drawText(data.getXVals().get(j), x, y + lineHeight,
                            mValuePaint);

            } else if (drawXVals && !drawYVals) {
                if (j < data.getXValCount())
                    c.drawText(data.getXVals().get(j), x, y + lineHeight / 2f, mValuePaint);
            } else if (!drawXVals && drawYVals) {

                drawValue(c, formatter, value, entry, 0, x, y + lineHeight / 2f);
            }

            cnt++;
        }
    }
}
 
Example 3
Source File: PieChartRenderer.java    From iMoney 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;

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

    if (!dataSet.isVisible())
        return;
    
    PointF center = mChart.getCenterCircleBox();
    float r = mChart.getRadius();

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

    List<Entry> entries = dataSet.getYVals();
    float[] drawAngles = mChart.getDrawAngles();
    float angle = mChart.getRotationAngle();

    for (int j = 0; j < entries.size(); j++) {

        float newangle = drawAngles[j];

        Entry e = entries.get(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 + newangle)
                            * mAnimator.getPhaseY())) + center.x);
            float y = (float) ((r - circleRadius)
                    * Math.sin(Math.toRadians((angle + newangle)
                            * mAnimator.getPhaseY())) + center.y);

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

        angle += newangle * mAnimator.getPhaseX();
    }
}
 
Example 4
Source File: PieChart.java    From Notification-Analyser with MIT License 4 votes vote down vote up
@Override
protected void drawData() {

    float angle = mRotationAngle;

    ArrayList<PieDataSet> dataSets = mCurrentData.getDataSets();

    int cnt = 0;

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

        PieDataSet dataSet = dataSets.get(i);
        ArrayList<Entry> entries = dataSet.getYVals();

        for (int j = 0; j < entries.size(); j++) {

            float newangle = mDrawAngles[cnt];
            float sliceSpace = dataSet.getSliceSpace();

            Entry e = entries.get(j);

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

                if (!needsHighlight(e.getXIndex(), i)) {

                    mRenderPaint.setColor(dataSet.getColor(j));
                    mDrawCanvas.drawArc(mCircleBox, angle + sliceSpace / 2f, newangle * mPhaseY
                            - sliceSpace / 2f, true, mRenderPaint);
                }

                // if(sliceSpace > 0f) {
                //
                // PointF outer = getPosition(c, radius, angle);
                // PointF inner = getPosition(c, radius * mHoleRadiusPercent
                // / 100f, angle);
                // }
            }

            angle += newangle * mPhaseX;
            cnt++;
        }
    }
}
 
Example 5
Source File: PieChart.java    From Notification-Analyser with MIT License 4 votes vote down vote up
@Override
protected void drawValues() {

    // if neither xvals nor yvals are drawn, return
    if (!mDrawXVals && !mDrawYValues)
        return;

    PointF center = getCenterCircleBox();

    // get whole the radius
    float r = getRadius();

    float off = r / 2f;

    if (mDrawHole) {
        off = (r - (r / 100f * mHoleRadiusPercent)) / 2f;
    }

    r -= off; // offset to keep things inside the chart

    ArrayList<PieDataSet> dataSets = mCurrentData.getDataSets();

    int cnt = 0;

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

        PieDataSet dataSet = dataSets.get(i);
        ArrayList<Entry> entries = dataSet.getYVals();

        for (int j = 0; j < entries.size() * mPhaseX; j++) {

            // offset needed to center the drawn text in the slice
            float offset = mDrawAngles[cnt] / 2;

            // calculate the text position
            float x = (float) (r
                    * Math.cos(Math.toRadians((mRotationAngle + mAbsoluteAngles[cnt] - offset)
                            * mPhaseY)) + center.x);
            float y = (float) (r
                    * Math.sin(Math.toRadians((mRotationAngle + mAbsoluteAngles[cnt] - offset)
                            * mPhaseY)) + center.y);

            String val = "";
            float value = entries.get(j).getVal();

            if (mUsePercentValues)
                val = mValueFormatter.getFormattedValue(Math.abs(getPercentOfTotal(value)))
                        + " %";
            else
                val = mValueFormatter.getFormattedValue(value);

            if (mDrawUnitInChart)
                val = val + mUnit;

            // draw everything, depending on settings
            if (mDrawXVals && mDrawYValues) {

                // use ascent and descent to calculate the new line
                // position,
                // 1.6f is the line spacing
                float lineHeight = (mValuePaint.ascent() + mValuePaint.descent()) * 1.6f;
                y -= lineHeight / 2;

                mDrawCanvas.drawText(val, x, y, mValuePaint);
                if (j < mCurrentData.getXValCount())
                    mDrawCanvas.drawText(mCurrentData.getXVals().get(j), x, y + lineHeight,
                            mValuePaint);

            } else if (mDrawXVals && !mDrawYValues) {
                if (j < mCurrentData.getXValCount())
                    mDrawCanvas.drawText(mCurrentData.getXVals().get(j), x, y, mValuePaint);
            } else if (!mDrawXVals && mDrawYValues) {

                mDrawCanvas.drawText(val, x, y, mValuePaint);
            }

            cnt++;
        }
    }
}
 
Example 6
Source File: PieChart.java    From iMoney with Apache License 2.0 3 votes vote down vote up
/**
 * calculates the needed angles for the chart slices
 */
private void calcAngles() {

    mDrawAngles = new float[mData.getYValCount()];
    mAbsoluteAngles = new float[mData.getYValCount()];

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

    int cnt = 0;

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

        PieDataSet set = dataSets.get(i);
        List<Entry> entries = set.getYVals();

        for (int j = 0; j < entries.size(); j++) {

            mDrawAngles[cnt] = calcAngle(Math.abs(entries.get(j).getVal()));

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

            cnt++;
        }
    }

}
 
Example 7
Source File: PieChart.java    From Notification-Analyser with MIT License 3 votes vote down vote up
/**
 * calculates the needed angles for the chart slices
 */
private void calcAngles() {

    mDrawAngles = new float[mCurrentData.getYValCount()];
    mAbsoluteAngles = new float[mCurrentData.getYValCount()];

    ArrayList<PieDataSet> dataSets = mCurrentData.getDataSets();

    int cnt = 0;

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

        PieDataSet set = dataSets.get(i);
        ArrayList<Entry> entries = set.getYVals();

        for (int j = 0; j < entries.size(); j++) {

            mDrawAngles[cnt] = calcAngle(Math.abs(entries.get(j).getVal()));

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

            cnt++;
        }
    }

}