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

The following examples show how to use com.github.mikephil.charting.data.Entry#getXIndex() . 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 Stayfit 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 6 votes vote down vote up
/**
 * calculate the distance between a line between two entries and an entry
 * (point)
 * 
 * @param startEntry line startpoint
 * @param endEntry line endpoint
 * @param entryPoint the point to which the distance is measured from the
 *            line
 * @return
 */
public double calcPointToLineDistance(Entry startEntry, Entry endEntry, Entry entryPoint) {

    float xDiffEndStart = (float) endEntry.getXIndex() - (float) startEntry.getXIndex();
    float xDiffEntryStart = (float) entryPoint.getXIndex() - (float) startEntry.getXIndex();

    double normalLength = Math.sqrt((xDiffEndStart)
            * (xDiffEndStart)
            + (endEntry.getVal() - startEntry.getVal())
            * (endEntry.getVal() - startEntry.getVal()));
    return Math.abs((xDiffEntryStart)
            * (endEntry.getVal() - startEntry.getVal())
            - (entryPoint.getVal() - startEntry.getVal())
            * (xDiffEndStart))
            / normalLength;
}
 
Example 3
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 4
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 5
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 6
Source File: PieChart.java    From NetKnight with Apache License 2.0 5 votes vote down vote up
@Override
protected float[] getMarkerPosition(Entry e, Highlight highlight) {

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

    float off = r / 10f * 3.6f;

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

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

    float rotationAngle = getRotationAngle();

    int i = e.getXIndex();

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

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

    return new float[]{x, y};
}
 
Example 7
Source File: Transformer.java    From NetKnight 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: RecordingList.java    From voice-pitch-analyzer with GNU Affero General Public License v3.0 5 votes vote down vote up
/***
 * check if Entry with given index value is already in list
 *
 * @param list
 * @param index
 * @return
 */
private boolean containsIndex(List<Entry> list, int index)
{
    for (Entry entry : list)
    {
        if (entry.getXIndex() == index)
        {
            return true;
        }
    }

    return false;
}
 
Example 9
Source File: Results.java    From NoiseCapture with GNU General Public License v3.0 5 votes vote down vote up
@Override
public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
    if(!sChart.valuesToHighlight()) {
        return "";
    }
    Highlight[] highlights = sChart.getHighlighted();
    for (final Highlight highlight : highlights) {
        int xIndex = highlight.getXIndex();
        if (xIndex == entry.getXIndex()) {
            return String.format(Locale.getDefault(), "%.1f dB(A)", value);
        }
    }
    return "";
}
 
Example 10
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
 * 
 * @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 11
Source File: LineChartRenderer.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
protected void drawCubicFill(Canvas c, ILineDataSet dataSet, Path spline, Transformer trans,
                             int from, int to) {

    if (to - from <= 1)
        return;

    float fillMin = dataSet.getFillFormatter()
            .getFillLinePosition(dataSet, mChart);
    
    // Take the from/to xIndex from the entries themselves,
    // so missing entries won't screw up the filling.
    // What we need to draw is line from points of the xIndexes - not arbitrary entry indexes!

    final Entry toEntry = dataSet.getEntryForIndex(to - 1);
    final Entry fromEntry = dataSet.getEntryForIndex(from);
    final float xTo = toEntry == null ? 0 : toEntry.getXIndex();
    final float xFrom = fromEntry == null ? 0 : fromEntry.getXIndex();

    spline.lineTo(xTo, fillMin);
    spline.lineTo(xFrom, fillMin);
    spline.close();

    trans.pathValueToPixel(spline);

    final Drawable drawable = dataSet.getFillDrawable();
    if (drawable != null) {

        drawFilledPath(c, spline, drawable);
    } else {

        drawFilledPath(c, spline, dataSet.getFillColor(), dataSet.getFillAlpha());
    }
}
 
Example 12
Source File: BarLineChartBase.java    From iMoney 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 13
Source File: Transformer.java    From NetKnight 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 dataSetIndex the dataset index
 * @param bd
 * @param phaseY
 * @return
 */
public float[] generateTransformedValuesBarChart(IBarDataSet data,
                                                 int dataSetIndex, 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 = e.getXIndex() + i * (setCount - 1) + dataSetIndex + space * i
                + space / 2f;
        float y = e.getVal();

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

    getValueToPixelMatrix().mapPoints(valuePoints);

    return valuePoints;
}
 
Example 14
Source File: RealmBaseDataSet.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
@Override
public float getYValForXIndex(int xIndex) {
    //return new DynamicRealmObject(results.where().greaterThanOrEqualTo(mIndexField, xIndex).findFirst()).getFloat(mValuesField);
    Entry e = getEntryForXIndex(xIndex);

    if (e != null && e.getXIndex() == xIndex)
        return e.getVal();
    else
        return Float.NaN;
}
 
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 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 16
Source File: RadarChartRenderer.java    From Stayfit with Apache License 2.0 4 votes vote down vote up
@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {

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

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

    PointF center = mChart.getCenterOffsets();

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

        IRadarDataSet set = mChart.getData()
                .getDataSetByIndex(indices[i]
                        .getDataSetIndex());

        if (set == null || !set.isHighlightEnabled())
            continue;

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

        Entry e = set.getEntryForXIndex(xIndex);
        if (e == null || e.getXIndex() != xIndex)
            continue;

        int j = set.getEntryIndex(e);
        float y = (e.getVal() - mChart.getYChartMin());

        if (Float.isNaN(y))
            continue;

        PointF p = Utils.getPosition(
                center,
                y * factor * phaseY,
                sliceangle * j * phaseX + mChart.getRotationAngle());

        float[] pts = new float[]{
                p.x, p.y
        };

        // draw the lines
        drawHighlightLines(c, pts, set);
    }
}
 
Example 17
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 BUBBLECHART.
 *
 * @param entries
 * @return
 */
public float[] generateTransformedValuesBubble(List<? extends Entry> entries,
                                             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 = entries.get(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 18
Source File: EntryComparator.java    From voice-pitch-analyzer with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public int compare(Entry lhs, Entry rhs)
{
    return (lhs.getXIndex() > rhs.getXIndex() ? 1 : -1);
}
 
Example 19
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 20
Source File: EntryXIndexComparator.java    From NetKnight with Apache License 2.0 4 votes vote down vote up
@Override
public int compare(Entry entry1, Entry entry2) {
    return entry1.getXIndex() - entry2.getXIndex();
}