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

The following examples show how to use com.github.mikephil.charting.interfaces.datasets.ICandleDataSet#getEntryCount() . 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: CandleStickChartRenderer.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
@Override
public void drawData(Canvas c) {

    CandleData candleData = mChart.getCandleData();

    for (ICandleDataSet set : candleData.getDataSets()) {

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

    CandleData candleData = mChart.getCandleData();

    for (ICandleDataSet set : candleData.getDataSets()) {

        if (set.isVisible() && set.getEntryCount() > 0)
            drawDataSet(c, set);
    }
}
 
Example 3
Source File: KLineView.java    From android-kline with Apache License 2.0 4 votes vote down vote up
public void addData(HisData hisData) {
    hisData = DataUtils.calculateHisData(hisData, mData);
    CombinedData combinedData = mChartPrice.getData();
    LineData priceData = combinedData.getLineData();
    ILineDataSet ma5Set = priceData.getDataSetByIndex(1);
    ILineDataSet ma10Set = priceData.getDataSetByIndex(2);
    ILineDataSet ma20Set = priceData.getDataSetByIndex(3);
    ILineDataSet ma30Set = priceData.getDataSetByIndex(4);
    CandleData kData = combinedData.getCandleData();
    ICandleDataSet klineSet = kData.getDataSetByIndex(0);
    IBarDataSet volSet = mChartVolume.getData().getBarData().getDataSetByIndex(0);
    IBarDataSet macdSet = mChartMacd.getData().getBarData().getDataSetByIndex(0);
    ILineDataSet difSet = mChartMacd.getData().getLineData().getDataSetByIndex(0);
    ILineDataSet deaSet = mChartMacd.getData().getLineData().getDataSetByIndex(1);
    LineData kdjData = mChartKdj.getData().getLineData();
    ILineDataSet kSet = kdjData.getDataSetByIndex(0);
    ILineDataSet dSet = kdjData.getDataSetByIndex(1);
    ILineDataSet jSet = kdjData.getDataSetByIndex(2);

    if (mData.contains(hisData)) {
        int index = mData.indexOf(hisData);
        klineSet.removeEntry(index);
        // ma比较特殊,entry数量和k线的不一致,移除最后一个
        ma5Set.removeLast();
        ma10Set.removeLast();
        ma20Set.removeLast();
        ma30Set.removeLast();
        volSet.removeEntry(index);
        macdSet.removeEntry(index);
        difSet.removeEntry(index);
        deaSet.removeEntry(index);
        kSet.removeEntry(index);
        dSet.removeEntry(index);
        jSet.removeEntry(index);
        mData.remove(index);
    }
    mData.add(hisData);
    int klineCount = klineSet.getEntryCount();
    klineSet.addEntry(new CandleEntry(klineCount, (float) hisData.getHigh(), (float) hisData.getLow(), (float) hisData.getOpen(), (float) hisData.getClose()));
    volSet.addEntry(new BarEntry(volSet.getEntryCount(), hisData.getVol(), hisData));

    macdSet.addEntry(new BarEntry(macdSet.getEntryCount(), (float) hisData.getMacd()));
    difSet.addEntry(new Entry(difSet.getEntryCount(), (float) hisData.getDif()));
    deaSet.addEntry(new Entry(deaSet.getEntryCount(), (float) hisData.getDea()));

    kSet.addEntry(new Entry(kSet.getEntryCount(), (float) hisData.getK()));
    dSet.addEntry(new Entry(dSet.getEntryCount(), (float) hisData.getD()));
    jSet.addEntry(new Entry(jSet.getEntryCount(), (float) hisData.getJ()));

    // 因为ma的数量会少,所以这里用kline的set数量作为x
    if (!Double.isNaN(hisData.getMa5())) {
        ma5Set.addEntry(new Entry(klineCount, (float) hisData.getMa5()));
    }
    if (!Double.isNaN(hisData.getMa10())) {
        ma10Set.addEntry(new Entry(klineCount, (float) hisData.getMa10()));
    }
    if (!Double.isNaN(hisData.getMa20())) {
        ma20Set.addEntry(new Entry(klineCount, (float) hisData.getMa20()));
    }
    if (!Double.isNaN(hisData.getMa30())) {
        ma30Set.addEntry(new Entry(klineCount, (float) hisData.getMa30()));
    }


    mChartPrice.getXAxis().setAxisMaximum(combinedData.getXMax() + 1.5f);
    mChartVolume.getXAxis().setAxisMaximum(mChartVolume.getData().getXMax() + 1.5f);
    mChartMacd.getXAxis().setAxisMaximum(mChartMacd.getData().getXMax() + 1.5f);
    mChartKdj.getXAxis().setAxisMaximum(mChartKdj.getData().getXMax() + 1.5f);


    mChartPrice.setVisibleXRange(MAX_COUNT, MIN_COUNT);
    mChartVolume.setVisibleXRange(MAX_COUNT, MIN_COUNT);
    mChartMacd.setVisibleXRange(MAX_COUNT, MIN_COUNT);
    mChartKdj.setVisibleXRange(MAX_COUNT, MIN_COUNT);

    mChartPrice.notifyDataSetChanged();
    mChartPrice.invalidate();
    mChartVolume.notifyDataSetChanged();
    mChartVolume.invalidate();
    mChartMacd.notifyDataSetChanged();
    mChartMacd.invalidate();
    mChartKdj.notifyDataSetChanged();
    mChartKdj.invalidate();


    setDescription(mChartPrice, String.format(Locale.getDefault(), "MA5:%.2f  MA10:%.2f  MA20:%.2f  MA30:%.2f",
            hisData.getMa5(), hisData.getMa10(), hisData.getMa20(), hisData.getMa30()));
    setDescription(mChartVolume, "成交量 " + hisData.getVol());
    setDescription(mChartMacd, String.format(Locale.getDefault(), "MACD:%.2f  DEA:%.2f  DIF:%.2f",
            hisData.getMacd(), hisData.getDea(), hisData.getDif()));
    setDescription(mChartKdj, String.format(Locale.getDefault(), "K:%.2f  D:%.2f  J:%.2f",
            hisData.getK(), hisData.getD(), hisData.getJ()));

}
 
Example 4
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 5
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));
            }
        }
    }
}