com.github.mikephil.charting.data.CandleEntry Java Examples

The following examples show how to use com.github.mikephil.charting.data.CandleEntry. 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: CombinedChartActivity.java    From Stayfit with Apache License 2.0 6 votes vote down vote up
protected CandleData generateCandleData() {

        CandleData d = new CandleData();

        ArrayList<CandleEntry> entries = new ArrayList<CandleEntry>();

        for (int index = 0; index < itemcount; index++)
            entries.add(new CandleEntry(index, 20f, 10f, 13f, 17f));

        CandleDataSet set = new CandleDataSet(entries, "Candle DataSet");
        set.setColor(Color.rgb(80, 80, 80));
        set.setBarSpace(0.3f);
        set.setValueTextSize(10f);
        set.setDrawValues(false);
        d.addDataSet(set);

        return d;
    }
 
Example #2
Source File: MyMarkerView.java    From Liapp with Apache License 2.0 6 votes vote down vote up
@Override
public void refreshContent(Entry e, Highlight highlight) {
    SharedPreferences sharedPrefs = PreferenceManager
            .getDefaultSharedPreferences(tvContent.getContext().getApplicationContext());

    if (e instanceof CandleEntry) {

        CandleEntry ce = (CandleEntry) e;

        tvContent.setText("" + Utils.formatNumber(ce.getHigh(), 0, true));
    } else {
        if(sharedPrefs.getString("pref_unit", "mg/dl").equals("mg/dl")) {
            tvContent.setText("" + Utils.formatNumber(e.getVal(), 0, true));
        }else{
            tvContent.setText("" + Utils.formatNumber(e.getVal(), 1, true));
        }
    }
}
 
Example #3
Source File: KlineFragment.java    From shinny-futures-android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * date: 6/1/18
 * author: chenli
 * description: K线图刷新时生成单个数据
 */
private void generateCandleAndLineDataEntry(int left_index, int index) {
    Map<String, KlineEntity.DataEntity> dataEntities = mKlineEntity.getData();
    KlineEntity.DataEntity dataEntity = dataEntities.get(String.valueOf(index));
    if (dataEntity == null) return;
    mCalendar.setTimeInMillis(Long.valueOf(dataEntity.getDatetime()) / 1000000);
    xVals.put(index - mBaseIndex, mSimpleDateFormat.format(mCalendar.getTime()));

    List<Entry> entries = generateMultiDataEntry(index, dataEntity, left_index);
    mTopChartViewBase.getCandleData().getDataSetByIndex(0).addEntryOrdered((CandleEntry) entries.get(0));
    mMiddleChartViewBase.getLineData().getDataSetByIndex(0).addEntryOrdered(entries.get(1));
    mMiddleChartViewBase.getBarData().getDataSetByIndex(0).addEntryOrdered((BarEntry) entries.get(2));
    mBottomChartViewBase.getLineData().getDataSetByIndex(0).addEntryOrdered(entries.get(3));
    mBottomChartViewBase.getLineData().getDataSetByIndex(1).addEntryOrdered(entries.get(4));
    mBottomChartViewBase.getBarData().getDataSetByIndex(0).addEntryOrdered((BarEntry) entries.get(5));

    for (int i = 0; i < mas.size(); i++) {
        int para = mas.get(i);
        if (index >= left_index + para - 1) {
            Entry entry = generateMALineDataEntry(index, para - 1);
            mLineData.getDataSetByIndex(i).addEntryOrdered(entry);
        }
    }
}
 
Example #4
Source File: KlineFragment.java    From shinny-futures-android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * date: 7/9/17
 * author: chenli
 * description: 生成蜡烛图数据
 */
private CandleData generateCandleData(List<CandleEntry> candleEntries) {
    CandleDataSet set = new CandleDataSet(candleEntries, "");
    set.setAxisDependency(YAxis.AxisDependency.LEFT);
    set.setShadowWidth(0.7f);
    set.setDecreasingColor(mDecreasingColor);
    set.setDecreasingPaintStyle(Paint.Style.FILL);
    set.setIncreasingColor(mIncreasingColor);
    set.setIncreasingPaintStyle(Paint.Style.STROKE);
    set.setNeutralColor(mHighlightColor);
    set.setShadowColorSameAsCandle(true);
    set.setHighlightLineWidth(0.7f);
    set.setHighLightColor(mHighlightColor);
    set.setDrawValues(true);
    set.setValueTextColor(Color.RED);
    set.setValueTextSize(9f);
    set.setDrawIcons(false);
    set.setValueFormatter(new TopChartLeftYAxisValueFormatter());
    CandleData candleData = new CandleData();
    candleData.addDataSet(set);
    return candleData;
}
 
Example #5
Source File: CombinedChartActivity.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
private CandleData generateCandleData() {

        CandleData d = new CandleData();

        ArrayList<CandleEntry> entries = new ArrayList<>();

        for (int index = 0; index < count; index += 2)
            entries.add(new CandleEntry(index + 1f, 90, 70, 85, 75f));

        CandleDataSet set = new CandleDataSet(entries, "Candle DataSet");
        set.setDecreasingColor(Color.rgb(142, 150, 175));
        set.setShadowColor(Color.DKGRAY);
        set.setBarSpace(0.3f);
        set.setValueTextSize(10f);
        set.setDrawValues(false);
        d.addDataSet(set);

        return d;
    }
 
Example #6
Source File: KLineChart.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
/**
 * 动态更新最后一点数据 最新数据集
 *
 * @param kLineData
 */
public void dynamicsUpdateOne(KLineDataManage kLineData) {
    int size = kLineData.getKLineDatas().size();
    int i = size - 1;
    CombinedData candleChartData = candleChart.getData();
    CandleData candleData = candleChartData.getCandleData();
    ICandleDataSet candleDataSet = candleData.getDataSetByIndex(0);
    candleDataSet.removeEntry(i);

    candleDataSet.addEntry(new CandleEntry(i + kLineData.getOffSet(), (float) kLineData.getKLineDatas().get(i).getHigh(), (float) kLineData.getKLineDatas().get(i).getLow(), (float) kLineData.getKLineDatas().get(i).getOpen(), (float) kLineData.getKLineDatas().get(i).getClose()));
    if (chartType1 == 1) {//副图是成交量
        CombinedData barChartData = barChart.getData();
        IBarDataSet barDataSet = barChartData.getBarData().getDataSetByIndex(0);
        barDataSet.removeEntry(i);
        float color = kLineData.getKLineDatas().get(i).getOpen() == kLineData.getKLineDatas().get(i).getClose()?0f:kLineData.getKLineDatas().get(i).getOpen() > kLineData.getKLineDatas().get(i).getClose() ? -1f : 1f;
        BarEntry barEntry = new BarEntry(i + kLineData.getOffSet(), (float) kLineData.getKLineDatas().get(i).getVolume(), color);
        barDataSet.addEntry(barEntry);
    } else {//副图是其他技术指标
        doBarChartSwitch(chartType1);
    }

    candleChart.notifyDataSetChanged();
    barChart.notifyDataSetChanged();
    candleChart.invalidate();
    barChart.invalidate();
}
 
Example #7
Source File: CandleStickChartManager.java    From react-native-mp-android-chart with MIT License 6 votes vote down vote up
@Override
CandleEntry createEntry(ReadableArray yValues, int index) {
    if (!ReadableType.Map.equals(yValues.getType(index))) {
        throw new IllegalArgumentException();
    }

    ReadableMap entryData = yValues.getMap(index);
    if (!BridgeUtils.validate(entryData, ReadableType.Number, "shadowH") ||
            !BridgeUtils.validate(entryData, ReadableType.Number, "shadowL") ||
            !BridgeUtils.validate(entryData, ReadableType.Number, "open") ||
            !BridgeUtils.validate(entryData, ReadableType.Number, "close")) {
        throw new IllegalArgumentException("CandleStick data must contain: shadowH, shadowL, open and close values");
    }

    float shadowH = (float) entryData.getDouble("shadowH");
    float shadowL = (float) entryData.getDouble("shadowL");
    float open = (float) entryData.getDouble("open");
    float close = (float) entryData.getDouble("close");

    return new CandleEntry(index, shadowH, shadowL, open, close);
}
 
Example #8
Source File: KLineView.java    From android-kline with Apache License 2.0 6 votes vote down vote up
@android.support.annotation.NonNull
public CandleDataSet setKLine(int type, ArrayList<CandleEntry> lineEntries) {
    CandleDataSet set = new CandleDataSet(lineEntries, "KLine" + type);
    set.setDrawIcons(false);
    set.setAxisDependency(YAxis.AxisDependency.LEFT);
    set.setShadowColor(Color.DKGRAY);
    set.setShadowWidth(0.75f);
    set.setDecreasingColor(mDecreasingColor);
    set.setDecreasingPaintStyle(Paint.Style.FILL);
    set.setShadowColorSameAsCandle(true);
    set.setIncreasingColor(mIncreasingColor);
    set.setIncreasingPaintStyle(Paint.Style.FILL);
    set.setNeutralColor(ContextCompat.getColor(getContext(), R.color.increasing_color));
    set.setDrawValues(true);
    set.setValueTextSize(10);
    set.setHighlightEnabled(true);
    if (type != NORMAL_LINE) {
        set.setVisible(false);
    }
    return set;
}
 
Example #9
Source File: KLineDataManage.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
private CandleDataSet setBOLLCandle(ArrayList<CandleEntry> candleEntries) {
    CandleDataSet candleDataSet = new CandleDataSet(candleEntries, "BOLL叠加蜡烛线");
    candleDataSet.setDrawHorizontalHighlightIndicator(false);
    candleDataSet.setHighlightEnabled(true);
    candleDataSet.setHighLightColor(ContextCompat.getColor(mContext, R.color.highLight_Color));
    candleDataSet.setAxisDependency(YAxis.AxisDependency.LEFT);
    candleDataSet.setDecreasingColor(ContextCompat.getColor(mContext, R.color.down_color));
    candleDataSet.setDecreasingPaintStyle(Paint.Style.FILL);
    candleDataSet.setIncreasingColor(ContextCompat.getColor(mContext, R.color.up_color));
    candleDataSet.setIncreasingPaintStyle(Paint.Style.FILL);
    candleDataSet.setNeutralColor(ContextCompat.getColor(mContext, R.color.equal_color));
    candleDataSet.setDrawValues(false);
    candleDataSet.setDrawIcons(false);
    candleDataSet.setShowCandleBar(false);
    return candleDataSet;
}
 
Example #10
Source File: KLineDataManage.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
private CandleDataSet setACandle(ArrayList<CandleEntry> candleEntries) {
    CandleDataSet candleDataSet = new CandleDataSet(candleEntries, "蜡烛线");
    candleDataSet.setDrawHorizontalHighlightIndicator(true);
    candleDataSet.setHighlightEnabled(true);
    candleDataSet.setHighLightColor(ContextCompat.getColor(mContext, R.color.highLight_Color));
    candleDataSet.setAxisDependency(YAxis.AxisDependency.LEFT);
    candleDataSet.setDecreasingColor(ContextCompat.getColor(mContext, R.color.down_color));
    candleDataSet.setDecreasingPaintStyle(Paint.Style.FILL);
    candleDataSet.setIncreasingColor(ContextCompat.getColor(mContext, R.color.up_color));
    candleDataSet.setIncreasingPaintStyle(Paint.Style.FILL);
    candleDataSet.setNeutralColor(ContextCompat.getColor(mContext, R.color.equal_color));
    candleDataSet.setShadowColorSameAsCandle(true);
    candleDataSet.setValueTextSize(10);
    candleDataSet.setDrawValues(true);

    return candleDataSet;
}
 
Example #11
Source File: RNMarkerView.java    From react-native-mp-android-chart with MIT License 5 votes vote down vote up
@Override
public void refreshContent(Entry e, Highlight highlight) {
    if (e instanceof CandleEntry) {
        CandleEntry ce = (CandleEntry) e;
        tvContent.setText(Utils.formatNumber(ce.getClose(), 2, true));
    } else {
        tvContent.setText(Utils.formatNumber(e.getVal(), 0, true));
    }
}
 
Example #12
Source File: RealmCandleDataSet.java    From MPAndroidChart-Realm with Apache License 2.0 5 votes vote down vote up
@Override
public CandleEntry buildEntryFromResultObject(T realmObject, float x) {
    DynamicRealmObject dynamicObject = new DynamicRealmObject(realmObject);

    return new CandleEntry(
            mXValuesField == null ? x : dynamicObject.getFloat(mXValuesField),
            dynamicObject.getFloat(mHighField),
            dynamicObject.getFloat(mLowField),
            dynamicObject.getFloat(mOpenField),
            dynamicObject.getFloat(mCloseField));
}
 
Example #13
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 #14
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 #15
Source File: CandleStickChartManager.java    From react-native-mp-android-chart with MIT License 5 votes vote down vote up
@Override
void dataSetConfig(IDataSet<CandleEntry> dataSet, ReadableMap config) {
    CandleDataSet candleDataSet = (CandleDataSet) dataSet;

    ChartDataSetConfigUtils.commonConfig(candleDataSet, config);
    ChartDataSetConfigUtils.commonBarLineScatterCandleBubbleConfig(candleDataSet, config);
    ChartDataSetConfigUtils.commonLineScatterCandleRadarConfig(candleDataSet, config);

    // CandleDataSet only config
    if (BridgeUtils.validate(config, ReadableType.Number, "barSpace")) {
        candleDataSet.setBarSpace((float) config.getDouble("barSpace"));
    }
    if (BridgeUtils.validate(config, ReadableType.Number, "shadowWidth")) {
        candleDataSet.setShadowWidth((float) config.getDouble("shadowWidth"));
    }
    if (BridgeUtils.validate(config, ReadableType.String, "shadowColor")) {
        candleDataSet.setShadowColor(Color.parseColor(config.getString("shadowColor")));
    }
    if (BridgeUtils.validate(config, ReadableType.Boolean, "shadowColorSameAsCandle")) {
        candleDataSet.setShadowColorSameAsCandle(config.getBoolean("shadowColorSameAsCandle"));
    }
    if (BridgeUtils.validate(config, ReadableType.String, "neutralColor")) {
        candleDataSet.setNeutralColor(Color.parseColor(config.getString("neutralColor")));
    }
    if (BridgeUtils.validate(config, ReadableType.String, "decreasingColor")) {
        candleDataSet.setDecreasingColor(Color.parseColor(config.getString("decreasingColor")));
    }
    if (BridgeUtils.validate(config, ReadableType.String, "decreasingPaintStyle")) {
        candleDataSet.setDecreasingPaintStyle(Paint.Style.valueOf(config.getString("decreasingPaintStyle").toUpperCase()));
    }
    if (BridgeUtils.validate(config, ReadableType.String, "increasingColor")) {
        candleDataSet.setIncreasingColor(Color.parseColor(config.getString("increasingColor")));
    }
    if (BridgeUtils.validate(config, ReadableType.String, "increasingPaintStyle")) {
        candleDataSet.setIncreasingPaintStyle(Paint.Style.valueOf(config.getString("increasingPaintStyle").toUpperCase()));
    }
}
 
Example #16
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 #17
Source File: RealmCandleDataSet.java    From NetKnight with Apache License 2.0 5 votes vote down vote up
@Override
public void calcMinMax(int start, int end) {

    if (mValues == null)
        return;

    if (mValues.size() == 0)
        return;

    int endValue;

    if (end == 0 || end >= mValues.size())
        endValue = mValues.size() - 1;
    else
        endValue = end;

    mYMin = Float.MAX_VALUE;
    mYMax = -Float.MAX_VALUE;

    for (int i = start; i <= endValue; i++) {

        CandleEntry e = mValues.get(i);

        if (e.getLow() < mYMin)
            mYMin = e.getLow();

        if (e.getHigh() > mYMax)
            mYMax = e.getHigh();
    }
}
 
Example #18
Source File: RealmCandleDataSet.java    From NetKnight with Apache License 2.0 5 votes vote down vote up
public CandleEntry buildEntryFromResultObject(T realmObject, int xIndex) {
    DynamicRealmObject dynamicObject = new DynamicRealmObject(realmObject);

    return new CandleEntry(
            mIndexField == null ? xIndex : dynamicObject.getInt(mIndexField),
            dynamicObject.getFloat(mHighField),
            dynamicObject.getFloat(mLowField),
            dynamicObject.getFloat(mOpenField),
            dynamicObject.getFloat(mCloseField));
}
 
Example #19
Source File: RealmCandleDataSet.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
@Override
public void calcMinMax(int start, int end) {

    if (mValues == null)
        return;

    if (mValues.size() == 0)
        return;

    int endValue;

    if (end == 0 || end >= mValues.size())
        endValue = mValues.size() - 1;
    else
        endValue = end;

    mYMin = Float.MAX_VALUE;
    mYMax = -Float.MAX_VALUE;

    for (int i = start; i <= endValue; i++) {

        CandleEntry e = mValues.get(i);

        if (e.getLow() < mYMin)
            mYMin = e.getLow();

        if (e.getHigh() > mYMax)
            mYMax = e.getHigh();
    }
}
 
Example #20
Source File: BeesMarkerView.java    From go-bees with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void refreshContent(Entry e, Highlight highlight) {
    if (e instanceof CandleEntry) {
        CandleEntry ce = (CandleEntry) e;
        tvContent.setText("" + Utils.formatNumber(ce.getHigh(), 0, true));
    } else {
        tvContent.setText("" + Utils.formatNumber(e.getY(), 0, true));
    }
    super.refreshContent(e, highlight);
}
 
Example #21
Source File: KLineChart.java    From StockChart-MPAndroidChart with MIT License 5 votes vote down vote up
/**
 * 动态增加一个点数据
 *
 * @param kLineData 最新数据集
 */
public void dynamicsAddOne(KLineDataManage kLineData) {
    int size = kLineData.getKLineDatas().size();
    CombinedData candleChartData = candleChart.getData();
    CandleData candleData = candleChartData.getCandleData();
    ICandleDataSet candleDataSet = candleData.getDataSetByIndex(0);
    int i = size - 1;
    candleDataSet.addEntry(new CandleEntry(i + kLineData.getOffSet(), (float) kLineData.getKLineDatas().get(i).getHigh(), (float) kLineData.getKLineDatas().get(i).getLow(), (float) kLineData.getKLineDatas().get(i).getOpen(), (float) kLineData.getKLineDatas().get(i).getClose()));
    kLineData.getxVals().add(DataTimeUtil.secToDate(kLineData.getKLineDatas().get(i).getDateMills()));
    candleChart.getXAxis().setAxisMaximum(kLineData.getKLineDatas().size() < 70 ? 70 : candleChartData.getXMax() + kLineData.getOffSet());

    if (chartType1 == 1) {//副图是成交量
        CombinedData barChartData = barChart.getData();
        IBarDataSet barDataSet = barChartData.getBarData().getDataSetByIndex(0);
        if (barDataSet == null) {//当没有数据时
            return;
        }
        float color = kLineData.getKLineDatas().get(i).getOpen() == kLineData.getKLineDatas().get(i).getClose()?0f:kLineData.getKLineDatas().get(i).getOpen() > kLineData.getKLineDatas().get(i).getClose() ? -1f : 1f;
        BarEntry barEntry = new BarEntry(i + kLineData.getOffSet(), (float) kLineData.getKLineDatas().get(i).getVolume(), color);

        barDataSet.addEntry(barEntry);
        barChart.getXAxis().setAxisMaximum(kLineData.getKLineDatas().size() < 70 ? 70 : barChartData.getXMax() + kLineData.getOffSet());
    } else {//副图是其他技术指标
        doBarChartSwitch(chartType1);
    }

    candleChart.notifyDataSetChanged();
    barChart.notifyDataSetChanged();
    if (kLineData.getKLineDatas().size() > 70) {
        //moveViewTo(...) 方法会自动调用 invalidate()
        candleChart.moveViewToX(kLineData.getKLineDatas().size() - 1);
        barChart.moveViewToX(kLineData.getKLineDatas().size() - 1);
    } else {
        candleChart.invalidate();
        barChart.invalidate();
    }
}
 
Example #22
Source File: RealmCandleDataSet.java    From MPAndroidChart-Realm with Apache License 2.0 5 votes vote down vote up
@Override
protected void calcMinMax(CandleEntry e) {

    if (e.getLow() < mYMin)
        mYMin = e.getLow();

    if (e.getHigh() > mYMax)
        mYMax = e.getHigh();

    calcMinMaxX(e);
}
 
Example #23
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 #24
Source File: RealmCandleDataSet.java    From MPAndroidChart-Realm with Apache License 2.0 5 votes vote down vote up
@Override
protected void calcMinMaxY(CandleEntry e) {

    if (e.getHigh() < mYMin)
        mYMin = e.getHigh();

    if (e.getHigh() > mYMax)
        mYMax = e.getHigh();

    if (e.getLow() < mYMin)
        mYMin = e.getLow();

    if (e.getLow() > mYMax)
        mYMax = e.getLow();
}
 
Example #25
Source File: CandleStickChart.java    From Notification-Analyser with MIT License 5 votes vote down vote up
/**
 * Transforms the values of an entry in order to draw the candle-body.
 * 
 * @param bodyPoints
 * @param e
 * @param bodySpace
 */
private void transformBody(float[] bodyPoints, CandleEntry e, float bodySpace) {

    bodyPoints[0] = e.getXIndex() + bodySpace;
    bodyPoints[1] = e.getClose() * mPhaseY;
    bodyPoints[2] = e.getXIndex() + (1f - bodySpace);
    bodyPoints[3] = e.getOpen() * mPhaseY;

    transformPointArray(bodyPoints);
}
 
Example #26
Source File: KlineFragment.java    From shinny-futures-android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * date: 6/1/18
 * author: chenli
 * description: K线图初始化时生成单个数据
 */
private List<Entry> generateMultiDataEntry(int i, KlineEntity.DataEntity dataEntity, int left_index) {
    List<Entry> entries = new ArrayList<>();
    mCalendar.setTimeInMillis(Long.valueOf(dataEntity.getDatetime()) / 1000000);
    xVals.put(i - mBaseIndex, mSimpleDateFormat.format(mCalendar.getTime()));
    float high = Float.valueOf(dataEntity.getHigh());
    float low = Float.valueOf(dataEntity.getLow());
    float open = Float.valueOf(dataEntity.getOpen());
    float close = Float.valueOf(dataEntity.getClose());
    float volume = Float.valueOf(dataEntity.getVolume());
    float oi = Float.valueOf(dataEntity.getClose_oi());
    float sub = open - close;
    float emas = close;
    float emal = close;
    float dif = 0;
    float dea = 0;
    float macd = 0;
    if (i != left_index && mEMAs.get(i - mBaseIndex - 1) != null) {
        emas = mEMAs.get(i - mBaseIndex - 1) * (mS - 1) / (mS + 1) + close * 2 / (mS + 1);
        emal = mEMAl.get(i - mBaseIndex - 1) * (mL - 1) / (mL + 1) + close * 2 / (mL + 1);
        dif = emas - emal;
        dea = mDEA.get(i - mBaseIndex - 1) * (mN - 1) / (mN + 1) + dif * 2 / (mN + 1);
        macd = (dif - dea) * 2;
    }
    mEMAs.put(i - mBaseIndex, emas);
    mEMAl.put(i - mBaseIndex, emal);
    mDEA.put(i - mBaseIndex, dea);
    entries.add(new CandleEntry(i - mBaseIndex, high, low, open, close));
    entries.add(new Entry(i - mBaseIndex, oi));
    entries.add(new BarEntry(i - mBaseIndex, volume, sub));
    entries.add(new Entry(i - mBaseIndex, dif));
    entries.add(new Entry(i - mBaseIndex, dea));
    entries.add(new BarEntry(i - mBaseIndex, macd, macd));
    return entries;
}
 
Example #27
Source File: MyCandleStickChartRenderer.java    From shinny-futures-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {

    CandleData candleData = mChart.getCandleData();

    for (Highlight high : indices) {

        ICandleDataSet set = candleData.getDataSetByIndex(high.getDataSetIndex());

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

        CandleEntry e = set.getEntryForXValue(high.getX(), high.getY());

        if (!isInBoundsX(e, set))
            continue;


        float lowValue = e.getLow() * mAnimator.getPhaseY();
        float highValue = e.getHigh() * mAnimator.getPhaseY();
        MPPointD pix = mChart.getTransformer(set.getAxisDependency())
                .getPixelForValues(e.getX(), (lowValue + highValue) / 2f);
        float xp = (float) pix.x;

        mHighlightPaint.setColor(set.getHighLightColor());
        mHighlightPaint.setStrokeWidth(set.getHighlightLineWidth());

        float xMax = mViewPortHandler.contentRight();
        float contentBottom = mViewPortHandler.contentBottom();
        //绘制竖线
        c.drawLine(xp, 1, xp, mChart.getHeight(), mHighlightPaint);

        //判断是否画横线
        float y = high.getDrawY();
        if (y >= 0 && y <= contentBottom) {//在区域内即绘制横线
            //绘制横线
            c.drawLine(0, y, xMax, y, mHighlightPaint);
        }
    }
}
 
Example #28
Source File: CandleStickChart.java    From Notification-Analyser with MIT License 5 votes vote down vote up
/**
 * Transforms the values of an entry in order to draw the candle-shadow.
 * 
 * @param shadowPoints
 * @param e
 */
private void transformShadow(float[] shadowPoints, CandleEntry e) {

    shadowPoints[0] = e.getXIndex() + 0.5f;
    shadowPoints[1] = e.getHigh() * mPhaseY;
    shadowPoints[2] = e.getXIndex() + 0.5f;
    shadowPoints[3] = e.getLow() * mPhaseY;

    transformPointArray(shadowPoints);
}
 
Example #29
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 CANDLESTICKCHART.
 * 
 * @param entries
 * @return
 */
public float[] generateTransformedValuesCandle(List<CandleEntry> 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) {

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

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

    getValueToPixelMatrix().mapPoints(valuePoints);

    return valuePoints;
}
 
Example #30
Source File: CandleStickChartManager.java    From react-native-mp-android-chart with MIT License 4 votes vote down vote up
@Override
IDataSet createDataSet(ArrayList<CandleEntry> entries, String label) {
    return new CandleDataSet(entries, label);
}