Java Code Examples for com.github.mikephil.charting.data.Entry#getVal()

The following examples show how to use com.github.mikephil.charting.data.Entry#getVal() . 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: Transformer.java    From NetKnight with Apache License 2.0 6 votes vote down vote up
/**
 * Transforms an List of Entry into a float array containing the x and
 * y values transformed with all matrices for the SCATTERCHART.
 *
 * @param data
 * @return
 */
public float[] generateTransformedValuesScatter(IScatterDataSet data,
                                                float phaseY) {

    float[] valuePoints = new float[data.getEntryCount() * 2];

    for (int j = 0; j < valuePoints.length; j += 2) {

        Entry e = data.getEntryForIndex(j / 2);

        if (e != null) {
            valuePoints[j] = e.getXIndex();
            valuePoints[j + 1] = e.getVal() * phaseY;
        }
    }

    getValueToPixelMatrix().mapPoints(valuePoints);

    return valuePoints;
}
 
Example 2
Source File: Approximator.java    From NetKnight with Apache License 2.0 5 votes vote down vote up
/**
 * calculates the angle between two Entries (points) in the chart taking
 * ratios into consideration
 * 
 * @param p1
 * @param p2
 * @return
 */
public double calcAngleWithRatios(Entry p1, Entry p2) {

    float dx = p2.getXIndex() * mDeltaRatio - p1.getXIndex() * mDeltaRatio;
    float dy = p2.getVal() * mScaleRatio - p1.getVal() * mScaleRatio;
    double angle = Math.atan2(dy, dx) * 180.0 / Math.PI;

    return angle;
}
 
Example 3
Source File: BarLineChartBase.java    From NetKnight with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the position (in pixels) the provided Entry has inside the chart
 * view or null, if the provided Entry is null.
 *
 * @param e
 * @return
 */
public PointF getPosition(Entry e, AxisDependency axis) {

    if (e == null)
        return null;

    float[] vals = new float[]{
            e.getXIndex(), e.getVal()
    };

    getTransformer(axis).pointValuesToPixel(vals);

    return new PointF(vals[0], vals[1]);
}
 
Example 4
Source File: Approximator.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
/**
 * calculates the angle between two Entries (points) in the chart taking
 * ratios into consideration
 * 
 * @param p1
 * @param p2
 * @return
 */
public double calcAngleWithRatios(Entry p1, Entry p2) {

    float dx = p2.getXIndex() * mDeltaRatio - p1.getXIndex() * mDeltaRatio;
    float dy = p2.getVal() * mScaleRatio - p1.getVal() * mScaleRatio;
    double angle = Math.atan2(dy, dx) * 180.0 / Math.PI;

    return angle;
}
 
Example 5
Source File: Approximator.java    From Notification-Analyser with MIT License 5 votes vote down vote up
/**
 * calculates the angle between two Entries (points) in the chart
 * 
 * @param p1
 * @param p2
 * @return
 */
public double calcAngle(Entry p1, Entry p2) {

    float dx = p2.getXIndex() - p1.getXIndex();
    float dy = p2.getVal() - p1.getVal();
    double angle = Math.atan2(dy, dx) * 180.0 / Math.PI;

    return angle;
}
 
Example 6
Source File: Chart.java    From Notification-Analyser with MIT License 5 votes vote down vote up
/**
 * Transforms an arraylist of Entry into a float array containing the x and
 * y values transformed with all matrices for the BARCHART.
 * 
 * @param entries
 * @param dataSet the dataset index
 * @return
 */
protected float[] generateTransformedValuesBarChart(ArrayList<? extends Entry> entries,
        int dataSet) {

    float[] valuePoints = new float[entries.size() * 2];

    int setCount = mOriginalData.getDataSetCount();
    BarData bd = (BarData) mOriginalData;
    float space = bd.getGroupSpace();

    for (int j = 0; j < valuePoints.length; j += 2) {

        Entry e = entries.get(j / 2);

        // calculate the x-position, depending on datasetcount
        float x = e.getXIndex() + (j / 2 * (setCount - 1)) + dataSet + 0.5f + space * (j / 2)
                + space / 2f;
        float y = e.getVal();

        valuePoints[j] = x;
        valuePoints[j + 1] = y * mPhaseY;
    }

    transformPointArray(valuePoints);

    return valuePoints;
}
 
Example 7
Source File: Transformer.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
/**
 * Transforms an List of Entry into a float array containing the x and
 * y values transformed with all matrices for the BARCHART.
 *
 * @param data
 * @param dataSet the dataset index
 * @return
 */
public float[] generateTransformedValuesHorizontalBarChart(IBarDataSet data,
                                                           int dataSet, BarData bd, float phaseY) {

    float[] valuePoints = new float[data.getEntryCount() * 2];

    int setCount = bd.getDataSetCount();
    float space = bd.getGroupSpace();

    for (int j = 0; j < valuePoints.length; j += 2) {

        Entry e = data.getEntryForIndex(j / 2);
        int i = e.getXIndex();

        // calculate the x-position, depending on datasetcount
        float x = i + i * (setCount - 1) + dataSet + space * i
                + space / 2f;
        float y = e.getVal();

        valuePoints[j] = y * phaseY;
        valuePoints[j + 1] = x;
    }

    getValueToPixelMatrix().mapPoints(valuePoints);

    return valuePoints;
}
 
Example 8
Source File: Transformer.java    From iMoney with Apache License 2.0 5 votes vote down vote up
/**
 * Transforms an List of Entry into a float array containing the x and
 * y values transformed with all matrices for the BARCHART.
 * 
 * @param entries
 * @param dataSet the dataset index
 * @return
 */
public float[] generateTransformedValuesBarChart(List<? extends Entry> entries,
        int dataSet, BarData bd, float phaseY) {

    float[] valuePoints = new float[entries.size() * 2];

    int setCount = bd.getDataSetCount();
    float space = bd.getGroupSpace();

    for (int j = 0; j < valuePoints.length; j += 2) {

        Entry e = entries.get(j / 2);
        int i = e.getXIndex();

        // calculate the x-position, depending on datasetcount
        float x = e.getXIndex() + i * (setCount - 1) + dataSet + space * i
                + space / 2f;
        float y = e.getVal();

        valuePoints[j] = x;
        valuePoints[j + 1] = y * phaseY;
    }

    getValueToPixelMatrix().mapPoints(valuePoints);

    return valuePoints;
}
 
Example 9
Source File: Approximator.java    From NetKnight with Apache License 2.0 5 votes vote down vote up
/**
 * calculates the angle between two Entries (points) in the chart
 * 
 * @param p1
 * @param p2
 * @return
 */
public double calcAngle(Entry p1, Entry p2) {

    float dx = p2.getXIndex() - p1.getXIndex();
    float dy = p2.getVal() - p1.getVal();
    double angle = Math.atan2(dy, dx) * 180.0 / Math.PI;

    return angle;
}
 
Example 10
Source File: Approximator.java    From Notification-Analyser with MIT License 5 votes vote down vote up
/**
 * calculates the angle between two Entries (points) in the chart taking
 * ratios into consideration
 * 
 * @param p1
 * @param p2
 * @return
 */
public double calcAngleWithRatios(Entry p1, Entry p2) {

    float dx = p2.getXIndex() * mDeltaRatio - p1.getXIndex() * mDeltaRatio;
    float dy = p2.getVal() * mScaleRatio - p1.getVal() * mScaleRatio;
    double angle = Math.atan2(dy, dx) * 180.0 / Math.PI;

    return angle;
}
 
Example 11
Source File: RadarChart.java    From Notification-Analyser with MIT License 5 votes vote down vote up
@Override
protected void drawHighlights() {

    // if there are values to highlight and highlighnting is enabled, do it
    if (mHighlightEnabled && valuesToHighlight()) {

        float sliceangle = getSliceAngle();
        float factor = getFactor();

        PointF c = getCenterOffsets();

        for (int i = 0; i < mIndicesToHightlight.length; i++) {

            RadarDataSet set = mCurrentData
                    .getDataSetByIndex(mIndicesToHightlight[i]
                            .getDataSetIndex());

            if (set == null)
                continue;

            mHighlightPaint.setColor(set.getHighLightColor());

            // get the index to highlight
            int xIndex = mIndicesToHightlight[i].getXIndex();

            Entry e = set.getEntryForXIndex(xIndex);
            int j = set.getEntryPosition(e);
            float y = e.getVal();

            PointF p = getPosition(c, y * factor, sliceangle * j + mRotationAngle);

            float[] pts = new float[] {
                    p.x, 0, p.x, getHeight(), 0, p.y, getWidth(), p.y
            };

            mDrawCanvas.drawLines(pts, mHighlightPaint);
        }
    }
}
 
Example 12
Source File: Approximator.java    From iMoney with Apache License 2.0 5 votes vote down vote up
/**
 * calculates the angle between two Entries (points) in the chart taking
 * ratios into consideration
 * 
 * @param p1
 * @param p2
 * @return
 */
public double calcAngleWithRatios(Entry p1, Entry p2) {

    float dx = p2.getXIndex() * mDeltaRatio - p1.getXIndex() * mDeltaRatio;
    float dy = p2.getVal() * mScaleRatio - p1.getVal() * mScaleRatio;
    double angle = Math.atan2(dy, dx) * 180.0 / Math.PI;

    return angle;
}
 
Example 13
Source File: RadarChart.java    From iMoney with Apache License 2.0 5 votes vote down vote up
@Override
protected float[] getMarkerPosition(Entry e, Highlight highlight) {

    float angle = getSliceAngle() * e.getXIndex() + getRotationAngle();
    float val = e.getVal() * getFactor();
    PointF c = getCenterOffsets();

    PointF p = new PointF((float) (c.x + val * Math.cos(Math.toRadians(angle))),
            (float) (c.y + val * Math.sin(Math.toRadians(angle))));

    return new float[]{
            p.x, p.y
    };
}
 
Example 14
Source File: Transformer.java    From iMoney with Apache License 2.0 4 votes vote down vote up
/**
 * Transforms an List of Entry into a float array containing the x and
 * y values transformed with all matrices for the LINECHART.
 * 
 * @param entries
 * @return
 */
public float[] generateTransformedValuesLine(List<? extends Entry> entries,
        float phaseX, float phaseY, int from, int to) {

    final int count = (int)Math.ceil((to - from) * phaseX) * 2;

    float[] valuePoints = new float[count];

    for (int j = 0; j < count; j += 2) {

        Entry e = entries.get(j / 2 + from);

        if (e != null) {
            valuePoints[j] = e.getXIndex();
            valuePoints[j + 1] = e.getVal() * phaseY;
        }
    }

    getValueToPixelMatrix().mapPoints(valuePoints);

    return valuePoints;
}
 
Example 15
Source File: Transformer.java    From Stayfit with Apache License 2.0 4 votes vote down vote up
/**
 * Transforms an List of Entry into a float array containing the x and
 * y values transformed with all matrices for the LINECHART.
 *
 * @param data
 * @return
 */
public float[] generateTransformedValuesLine(ILineDataSet data,
                                             float phaseX, float phaseY, int from, int to) {

    final int count = (int) Math.ceil((to - from) * phaseX) * 2;

    float[] valuePoints = new float[count];

    for (int j = 0; j < count; j += 2) {

        Entry e = data.getEntryForIndex(j / 2 + from);

        if (e != null) {
            valuePoints[j] = e.getXIndex();
            valuePoints[j + 1] = e.getVal() * phaseY;
        }
    }

    getValueToPixelMatrix().mapPoints(valuePoints);

    return valuePoints;
}
 
Example 16
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 17
Source File: LineChartRenderer.java    From NetKnight with Apache License 2.0 4 votes vote down vote up
protected void drawCubicBezier(Canvas c, ILineDataSet dataSet) {

        Transformer trans = mChart.getTransformer(dataSet.getAxisDependency());

        int entryCount = dataSet.getEntryCount();

        Entry entryFrom = dataSet.getEntryForXIndex((mMinX < 0) ? 0 : mMinX, DataSet.Rounding.DOWN);
        Entry entryTo = dataSet.getEntryForXIndex(mMaxX, DataSet.Rounding.UP);

        int diff = (entryFrom == entryTo) ? 1 : 0;
        int minx = Math.max(dataSet.getEntryIndex(entryFrom) - diff - 1, 0);
        int maxx = Math.min(Math.max(minx + 2, dataSet.getEntryIndex(entryTo) + 1), entryCount);

        float phaseX = Math.max(0.f, Math.min(1.f, mAnimator.getPhaseX()));
        float phaseY = mAnimator.getPhaseY();

        float intensity = dataSet.getCubicIntensity();

        cubicPath.reset();

        int size = (int) Math.ceil((maxx - minx) * phaseX + minx);

        if (size - minx >= 2) {

            float prevDx = 0f;
            float prevDy = 0f;
            float curDx = 0f;
            float curDy = 0f;

            Entry prevPrev = dataSet.getEntryForIndex(minx);
            Entry prev = prevPrev;
            Entry cur = prev;
            Entry next = dataSet.getEntryForIndex(minx + 1);

            // let the spline start
            cubicPath.moveTo(cur.getXIndex(), cur.getVal() * phaseY);

            for (int j = minx + 1, count = Math.min(size, entryCount); j < count; j++) {

                prevPrev = dataSet.getEntryForIndex(j == 1 ? 0 : j - 2);
                prev = dataSet.getEntryForIndex(j - 1);
                cur = dataSet.getEntryForIndex(j);
                next = entryCount > j + 1 ? dataSet.getEntryForIndex(j + 1) : cur;

                prevDx = (cur.getXIndex() - prevPrev.getXIndex()) * intensity;
                prevDy = (cur.getVal() - prevPrev.getVal()) * intensity;
                curDx = (next.getXIndex() - prev.getXIndex()) * intensity;
                curDy = (next.getVal() - prev.getVal()) * intensity;

                cubicPath.cubicTo(prev.getXIndex() + prevDx, (prev.getVal() + prevDy) * phaseY,
                        cur.getXIndex() - curDx,
                        (cur.getVal() - curDy) * phaseY, cur.getXIndex(), cur.getVal() * phaseY);
            }
        }

        // if filled is enabled, close the path
        if (dataSet.isDrawFilledEnabled()) {

            cubicFillPath.reset();
            cubicFillPath.addPath(cubicPath);
            // create a new path, this is bad for performance
            drawCubicFill(mBitmapCanvas, dataSet, cubicFillPath, trans,
                    minx, size);
        }

        mRenderPaint.setColor(dataSet.getColor());

        mRenderPaint.setStyle(Paint.Style.STROKE);

        trans.pathValueToPixel(cubicPath);

        mBitmapCanvas.drawPath(cubicPath, mRenderPaint);

        mRenderPaint.setPathEffect(null);
    }
 
Example 18
Source File: Transformer.java    From Stayfit with Apache License 2.0 4 votes vote down vote up
/**
 * Transforms an List of Entry into a float array containing the x and
 * y values transformed with all matrices for the BUBBLECHART.
 *
 * @param data
 * @return
 */
public float[] generateTransformedValuesBubble(IBubbleDataSet data,
                                               float phaseX, float phaseY, int from, int to) {

    final int count = (int) Math.ceil(to - from) * 2; // (int) Math.ceil((to - from) * phaseX) * 2;

    float[] valuePoints = new float[count];

    for (int j = 0; j < count; j += 2) {

        Entry e = data.getEntryForIndex(j / 2 + from);

        if (e != null) {
            valuePoints[j] = (float) (e.getXIndex() - from) * phaseX + from;
            valuePoints[j + 1] = e.getVal() * phaseY;
        }
    }

    getValueToPixelMatrix().mapPoints(valuePoints);

    return valuePoints;
}
 
Example 19
Source File: HorizontalBarChart.java    From Stayfit with Apache License 2.0 3 votes vote down vote up
@Override
public PointF getPosition(Entry e, AxisDependency axis) {

	if (e == null)
		return null;

	float[] vals = new float[] { e.getVal(), e.getXIndex() };

	getTransformer(axis).pointValuesToPixel(vals);

	return new PointF(vals[0], vals[1]);
}
 
Example 20
Source File: HorizontalBarChart.java    From iMoney with Apache License 2.0 3 votes vote down vote up
@Override
public PointF getPosition(Entry e, AxisDependency axis) {

	if (e == null)
		return null;

	float[] vals = new float[] { e.getVal(), e.getXIndex() };

	getTransformer(axis).pointValuesToPixel(vals);

	return new PointF(vals[0], vals[1]);
}