Java Code Examples for com.github.mikephil.charting.interfaces.datasets.ICandleDataSet#getEntryForIndex()

The following examples show how to use com.github.mikephil.charting.interfaces.datasets.ICandleDataSet#getEntryForIndex() . 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: MyTransformer.java    From shinny-futures-android with GNU General Public License v3.0 5 votes vote down vote up
public float[] generateTransformedValuesCandleLow(ICandleDataSet data,
                                                  float phaseX, float phaseY, int from, int to) {

    final int count = (int) ((to - from) * phaseX + 1) * 2;

    if (valuePointsForGenerateTransformedValuesCandleLow.length != count) {
        valuePointsForGenerateTransformedValuesCandleLow = new float[count];
    }
    float[] valuePoints = valuePointsForGenerateTransformedValuesCandleLow;

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

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

        if (e != null) {
            valuePoints[j] = e.getX();
            valuePoints[j + 1] = e.getLow() * phaseY;
        } else {
            valuePoints[j] = 0;
            valuePoints[j + 1] = 0;
        }
    }

    getValueToPixelMatrix().mapPoints(valuePoints);

    return valuePoints;
}
 
Example 2
Source File: Transformer.java    From StockChart-MPAndroidChart with MIT License 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 CANDLESTICKCHART.
 *
 * @param data
 * @return
 */
public float[] generateTransformedValuesCandle(ICandleDataSet data,
                                               float phaseX, float phaseY, int from, int to) {

    final int count = (int) ((to - from) * phaseX + 1) * 2;

    if (valuePointsForGenerateTransformedValuesCandle.length != count) {
        valuePointsForGenerateTransformedValuesCandle = new float[count];
    }
    float[] valuePoints = valuePointsForGenerateTransformedValuesCandle;

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

        CandleEntry e = null;
        try {
            e = data.getEntryForIndex(j / 2 + from);
        } catch (Exception e1) {
            e1.printStackTrace();
            continue;
        }

        if (e != null) {
            valuePoints[j] = e.getX();
            valuePoints[j + 1] = e.getHigh() * phaseY;
        } else {
            valuePoints[j] = 0;
            valuePoints[j + 1] = 0;
        }
    }

    getValueToPixelMatrix().mapPoints(valuePoints);

    return valuePoints;
}
 
Example 3
Source File: Transformer.java    From Ticket-Analysis with MIT License 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 CANDLESTICKCHART.
 *
 * @param data
 * @return
 */
public float[] generateTransformedValuesCandle(ICandleDataSet data,
                                               float phaseX, float phaseY, int from, int to) {

    final int count = (int) ((to - from) * phaseX + 1) * 2;

    if (valuePointsForGenerateTransformedValuesCandle.length != count) {
        valuePointsForGenerateTransformedValuesCandle = new float[count];
    }
    float[] valuePoints = valuePointsForGenerateTransformedValuesCandle;

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

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

        if (e != null) {
            valuePoints[j] = e.getX();
            valuePoints[j + 1] = e.getHigh() * phaseY;
        } else {
            valuePoints[j] = 0;
            valuePoints[j + 1] = 0;
        }
    }

    getValueToPixelMatrix().mapPoints(valuePoints);

    return valuePoints;
}
 
Example 4
Source File: Transformer.java    From android-kline 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 CANDLESTICKCHART.
 *
 * @param data
 * @return
 */
public float[] generateTransformedValuesCandle(ICandleDataSet data,
                                               float phaseX, float phaseY, int from, int to) {

    final int count = (int) ((to - from) * phaseX + 1) * 2;

    if (valuePointsForGenerateTransformedValuesCandle.length != count) {
        valuePointsForGenerateTransformedValuesCandle = new float[count];
    }
    float[] valuePoints = valuePointsForGenerateTransformedValuesCandle;

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

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

        if (e != null) {
            valuePoints[j] = e.getX();
            valuePoints[j + 1] = e.getHigh() * phaseY;
        } else {
            valuePoints[j] = 0;
            valuePoints[j + 1] = 0;
        }
    }

    getValueToPixelMatrix().mapPoints(valuePoints);

    return valuePoints;
}
 
Example 5
Source File: MyCandleStickChartRenderer.java    From shinny-futures-android with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void drawValues(Canvas c) {

    List<ICandleDataSet> dataSets = mChart.getCandleData().getDataSets();

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

        ICandleDataSet dataSet = dataSets.get(i);

        if (!shouldDrawValues(dataSet))
            continue;

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

        MyTransformer trans = ((CombinedChartKline) (mChart)).getTransformer(dataSet.getAxisDependency());

        mXBounds.set(mChart, dataSet);

        float[] positions = trans.generateTransformedValuesCandle(
                dataSet, mAnimator.getPhaseX(), mAnimator.getPhaseY(), mXBounds.min, mXBounds.max);

        float[] positionsLow = trans.generateTransformedValuesCandleLow(
                dataSet, mAnimator.getPhaseX(), mAnimator.getPhaseY(), mXBounds.min, mXBounds.max);

        float yOffset = Utils.convertDpToPixel(5f);

        MyValueFormatter formatter = (MyValueFormatter) dataSet.getValueFormatter();

        MPPointF iconsOffset = MPPointF.getInstance(dataSet.getIconsOffset());
        iconsOffset.x = Utils.convertDpToPixel(iconsOffset.x);
        iconsOffset.y = Utils.convertDpToPixel(iconsOffset.y);

        CandleEntry entryMin = dataSet.getEntryForIndex(mXBounds.min);
        float xMin = positionsLow[0];
        float yMin = positionsLow[1];

        CandleEntry entryMax = dataSet.getEntryForIndex(mXBounds.min);
        float xMax = positions[0];
        float yMax = positions[1];

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

            float xHigh = positions[j];
            float yHigh = positions[j + 1];

            float xLow = positionsLow[j];
            float yLow = positionsLow[j + 1];

            if (!mViewPortHandler.isInBoundsRight(xHigh))
                break;

            if (!mViewPortHandler.isInBoundsLeft(xHigh) || !mViewPortHandler.isInBoundsY(yHigh))
                continue;

            if (!mViewPortHandler.isInBoundsRight(xLow))
                break;

            if (!mViewPortHandler.isInBoundsLeft(xLow) || !mViewPortHandler.isInBoundsY(yLow))
                continue;

            CandleEntry entry = dataSet.getEntryForIndex(j / 2 + mXBounds.min);

            if (entry.getHigh() > entryMax.getHigh()) {
                entryMax = entry;
                xMax = xHigh;
                yMax = yHigh;
            }

            if (entry.getLow() < entryMin.getLow()) {
                entryMin = entry;
                xMin = xLow;
                yMin = yLow + yOffset;
            }

        }

        if (dataSet.isDrawValuesEnabled()) {

            drawValue(c,
                    formatter.getCandleLabel(entryMax),
                    xMax,
                    yMax,
                    ContextCompat.getColor(BaseApplication.getContext(), R.color.kline_red));

            drawValue(c,
                    formatter.getCandleLabelLow(entryMin),
                    xMin,
                    yMin,
                    ContextCompat.getColor(BaseApplication.getContext(), R.color.kline_green));

        }

        MPPointF.recycleInstance(iconsOffset);
    }
}
 
Example 6
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 CANDLESTICKCHART.
 *
 * @param data
 * @return
 */
public float[] generateTransformedValuesCandle(ICandleDataSet 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) {

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

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

    getValueToPixelMatrix().mapPoints(valuePoints);

    return valuePoints;
}
 
Example 7
Source File: Transformer.java    From NetKnight 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 CANDLESTICKCHART.
 *
 * @param data
 * @return
 */
public float[] generateTransformedValuesCandle(ICandleDataSet 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) {

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

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

    getValueToPixelMatrix().mapPoints(valuePoints);

    return valuePoints;
}
 
Example 8
Source File: CandleStickChartRenderer.java    From Stayfit with Apache License 2.0 2 votes vote down vote up
@Override
public void drawValues(Canvas c) {

    // if values are drawn
    if (mChart.getCandleData().getYValCount() < mChart.getMaxVisibleCount()
            * mViewPortHandler.getScaleX()) {

        List<ICandleDataSet> dataSets = mChart.getCandleData().getDataSets();

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

            ICandleDataSet dataSet = dataSets.get(i);

            if (!dataSet.isDrawValuesEnabled() || dataSet.getEntryCount() == 0)
                continue;

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

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

            int minx = Math.max(mMinX, 0);
            int maxx = Math.min(mMaxX + 1, dataSet.getEntryCount());

            float[] positions = trans.generateTransformedValuesCandle(
                    dataSet, mAnimator.getPhaseX(), mAnimator.getPhaseY(), minx, maxx);

            float yOffset = Utils.convertDpToPixel(5f);

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

                float x = positions[j];
                float y = positions[j + 1];

                if (!mViewPortHandler.isInBoundsRight(x))
                    break;

                if (!mViewPortHandler.isInBoundsLeft(x) || !mViewPortHandler.isInBoundsY(y))
                    continue;

                CandleEntry entry = dataSet.getEntryForIndex(j / 2 + minx);

                drawValue(c, dataSet.getValueFormatter(), entry.getHigh(), entry, i, x, y - yOffset, dataSet.getValueTextColor(j / 2));
            }
        }
    }
}
 
Example 9
Source File: CandleStickChartRenderer.java    From NetKnight with Apache License 2.0 2 votes vote down vote up
@Override
public void drawValues(Canvas c) {

    // if values are drawn
    if (mChart.getCandleData().getYValCount() < mChart.getMaxVisibleCount()
            * mViewPortHandler.getScaleX()) {

        List<ICandleDataSet> dataSets = mChart.getCandleData().getDataSets();

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

            ICandleDataSet dataSet = dataSets.get(i);

            if (!dataSet.isDrawValuesEnabled() || dataSet.getEntryCount() == 0)
                continue;

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

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

            int minx = Math.max(mMinX, 0);
            int maxx = Math.min(mMaxX + 1, dataSet.getEntryCount());

            float[] positions = trans.generateTransformedValuesCandle(
                    dataSet, mAnimator.getPhaseX(), mAnimator.getPhaseY(), minx, maxx);

            float yOffset = Utils.convertDpToPixel(5f);

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

                float x = positions[j];
                float y = positions[j + 1];

                if (!mViewPortHandler.isInBoundsRight(x))
                    break;

                if (!mViewPortHandler.isInBoundsLeft(x) || !mViewPortHandler.isInBoundsY(y))
                    continue;

                CandleEntry entry = dataSet.getEntryForIndex(j / 2 + minx);

                drawValue(c, dataSet.getValueFormatter(), entry.getHigh(), entry, i, x, y - yOffset, dataSet.getValueTextColor(j / 2));
            }
        }
    }
}