Java Code Examples for com.github.mikephil.charting.interfaces.datasets.ILineDataSet#removeEntry()

The following examples show how to use com.github.mikephil.charting.interfaces.datasets.ILineDataSet#removeEntry() . 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: OneDayChart.java    From StockChart-MPAndroidChart with MIT License 5 votes vote down vote up
/**
 * 动态更新最后一点数据
 * @param timeDatamodel
 * @param length
 */
public void dynamicsUpdateOne(TimeDataModel timeDatamodel, int length) {
    int index = length - 1;
    LineData lineData = lineChart.getData();
    ILineDataSet d1 = lineData.getDataSetByIndex(0);
    Entry e = d1.getEntryForIndex(index);
    d1.removeEntry(e);
    d1.addEntry(new Entry(index, (float) timeDatamodel.getNowPrice()));

    ILineDataSet d2 = lineData.getDataSetByIndex(1);
    Entry e2 = d2.getEntryForIndex(index);
    d2.removeEntry(e2);
    d2.addEntry(new Entry(index, (float) timeDatamodel.getAveragePrice()));

    BarData barData = barChart.getData();
    IBarDataSet barDataSet = barData.getDataSetByIndex(0);
    barDataSet.removeEntry(index);
    float color = timeDatamodel.getNowPrice() == d1.getEntryForIndex(index - 1).getY() ? 0f : timeDatamodel.getNowPrice() > d1.getEntryForIndex(index - 1).getY() ? 1f : -1f;
    barDataSet.addEntry(new BarEntry(index, timeDatamodel.getVolume(),color));

    lineData.notifyDataChanged();
    lineChart.notifyDataSetChanged();
    lineChart.moveViewToX(index);

    barData.notifyDataChanged();
    barChart.notifyDataSetChanged();
    barChart.moveViewToX(index);
}
 
Example 2
Source File: FiveDayChart.java    From StockChart-MPAndroidChart with MIT License 5 votes vote down vote up
/**
 * 动态更新最后一点数据
 * @param timeDatamodel
 * @param length
 */
public void dynamicsUpdateOne(TimeDataModel timeDatamodel, int length) {
    int index = length - 1;
    LineData lineData = lineChart.getData();
    ILineDataSet d1 = lineData.getDataSetByIndex(0);
    Entry e = d1.getEntryForIndex(index);
    d1.removeEntry(e);
    d1.addEntry(new Entry( index, (float) timeDatamodel.getNowPrice()));

    ILineDataSet d2 = lineData.getDataSetByIndex(1);
    Entry e2 = d2.getEntryForIndex(index);
    d2.removeEntry(e2);
    d2.addEntry(new Entry( index, (float) timeDatamodel.getAveragePrice()));

    BarData barData = barChart.getData();
    IBarDataSet barDataSet = barData.getDataSetByIndex(0);
    barDataSet.removeEntry(index);
    float color = timeDatamodel.getNowPrice() == d1.getEntryForIndex(index - 1).getY() ? 0f : timeDatamodel.getNowPrice() > d1.getEntryForIndex(index - 1).getY() ? 1f : -1f;
    barDataSet.addEntry(new BarEntry( index, timeDatamodel.getVolume(),color));

    lineData.notifyDataChanged();
    lineChart.notifyDataSetChanged();
    lineChart.moveViewToX(index);

    barData.notifyDataChanged();
    barChart.notifyDataSetChanged();
    barChart.moveViewToX(index);
}
 
Example 3
Source File: TimeLineView.java    From android-kline with Apache License 2.0 5 votes vote down vote up
public void addData(HisData hisData) {
    hisData = DataUtils.calculateHisData(hisData, mData);
    CombinedData combinedData = mChartPrice.getData();
    LineData priceData = combinedData.getLineData();
    ILineDataSet priceSet = priceData.getDataSetByIndex(0);
    ILineDataSet aveSet = priceData.getDataSetByIndex(1);
    IBarDataSet volSet = mChartVolume.getData().getBarData().getDataSetByIndex(0);
    if (mData.contains(hisData)) {
        int index = mData.indexOf(hisData);
        priceSet.removeEntry(index);
        aveSet.removeEntry(index);
        volSet.removeEntry(index);
        mData.remove(index);
    }
    mData.add(hisData);
    priceSet.addEntry(new Entry(priceSet.getEntryCount(), (float) hisData.getClose()));
    aveSet.addEntry(new Entry(aveSet.getEntryCount(), (float) hisData.getAvePrice()));
    volSet.addEntry(new BarEntry(volSet.getEntryCount(), hisData.getVol(), hisData));

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

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

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

    setDescription(mChartVolume, "成交量 " + hisData.getVol());
}
 
Example 4
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()));

}