Search in sources :

Example 1 with CandleData

use of com.github.mikephil.charting.data.CandleData in project MPAndroidChart by PhilJay.

the class CombinedChartActivity method generateCandleData.

protected CandleData generateCandleData() {
    CandleData d = new CandleData();
    ArrayList<CandleEntry> entries = new ArrayList<CandleEntry>();
    for (int index = 0; index < itemcount; 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;
}
Also used : CandleEntry(com.github.mikephil.charting.data.CandleEntry) CandleData(com.github.mikephil.charting.data.CandleData) ArrayList(java.util.ArrayList) CandleDataSet(com.github.mikephil.charting.data.CandleDataSet)

Example 2 with CandleData

use of com.github.mikephil.charting.data.CandleData in project MPAndroidChart by PhilJay.

the class CandleStickChartActivity method onProgressChanged.

@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
    int prog = (mSeekBarX.getProgress() + 1);
    tvX.setText("" + prog);
    tvY.setText("" + (mSeekBarY.getProgress()));
    mChart.resetTracking();
    ArrayList<CandleEntry> yVals1 = new ArrayList<CandleEntry>();
    for (int i = 0; i < prog; i++) {
        float mult = (mSeekBarY.getProgress() + 1);
        float val = (float) (Math.random() * 40) + mult;
        float high = (float) (Math.random() * 9) + 8f;
        float low = (float) (Math.random() * 9) + 8f;
        float open = (float) (Math.random() * 6) + 1f;
        float close = (float) (Math.random() * 6) + 1f;
        boolean even = i % 2 == 0;
        yVals1.add(new CandleEntry(i, val + high, val - low, even ? val + open : val - open, even ? val - close : val + close, getResources().getDrawable(R.drawable.star)));
    }
    CandleDataSet set1 = new CandleDataSet(yVals1, "Data Set");
    set1.setDrawIcons(false);
    set1.setAxisDependency(AxisDependency.LEFT);
    //        set1.setColor(Color.rgb(80, 80, 80));
    set1.setShadowColor(Color.DKGRAY);
    set1.setShadowWidth(0.7f);
    set1.setDecreasingColor(Color.RED);
    set1.setDecreasingPaintStyle(Paint.Style.FILL);
    set1.setIncreasingColor(Color.rgb(122, 242, 84));
    set1.setIncreasingPaintStyle(Paint.Style.STROKE);
    set1.setNeutralColor(Color.BLUE);
    //set1.setHighlightLineWidth(1f);
    CandleData data = new CandleData(set1);
    mChart.setData(data);
    mChart.invalidate();
}
Also used : CandleEntry(com.github.mikephil.charting.data.CandleEntry) CandleData(com.github.mikephil.charting.data.CandleData) ArrayList(java.util.ArrayList) CandleDataSet(com.github.mikephil.charting.data.CandleDataSet) ICandleDataSet(com.github.mikephil.charting.interfaces.datasets.ICandleDataSet) Paint(android.graphics.Paint)

Example 3 with CandleData

use of com.github.mikephil.charting.data.CandleData in project MPAndroidChart by PhilJay.

the class RealmDatabaseActivityCandle method setData.

private void setData() {
    RealmResults<RealmDemoData> result = mRealm.where(RealmDemoData.class).findAll();
    RealmCandleDataSet<RealmDemoData> set = new RealmCandleDataSet<RealmDemoData>(result, "xValue", "high", "low", "open", "close");
    set.setLabel("Realm CandleDataSet");
    set.setShadowColor(Color.DKGRAY);
    set.setShadowWidth(0.7f);
    set.setDecreasingColor(Color.RED);
    set.setDecreasingPaintStyle(Paint.Style.FILL);
    set.setIncreasingColor(Color.rgb(122, 242, 84));
    set.setIncreasingPaintStyle(Paint.Style.STROKE);
    set.setNeutralColor(Color.BLUE);
    ArrayList<ICandleDataSet> dataSets = new ArrayList<ICandleDataSet>();
    // add the dataset
    dataSets.add(set);
    // create a data object with the dataset list
    CandleData data = new CandleData(dataSets);
    styleData(data);
    // set data
    mChart.setData(data);
    mChart.animateY(1400, Easing.EasingOption.EaseInOutQuart);
}
Also used : ICandleDataSet(com.github.mikephil.charting.interfaces.datasets.ICandleDataSet) CandleData(com.github.mikephil.charting.data.CandleData) ArrayList(java.util.ArrayList) RealmCandleDataSet(com.github.mikephil.charting.data.realm.implementation.RealmCandleDataSet) RealmDemoData(com.xxmassdeveloper.mpchartexample.custom.RealmDemoData)

Example 4 with CandleData

use of com.github.mikephil.charting.data.CandleData in project MPAndroidChart by PhilJay.

the class CandleStickChartRenderer method drawHighlighted.

@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();
        float y = (lowValue + highValue) / 2f;
        MPPointD pix = mChart.getTransformer(set.getAxisDependency()).getPixelForValues(e.getX(), y);
        high.setDraw((float) pix.x, (float) pix.y);
        // draw the lines
        drawHighlightLines(c, (float) pix.x, (float) pix.y, set);
    }
}
Also used : Highlight(com.github.mikephil.charting.highlight.Highlight) ICandleDataSet(com.github.mikephil.charting.interfaces.datasets.ICandleDataSet) CandleEntry(com.github.mikephil.charting.data.CandleEntry) CandleData(com.github.mikephil.charting.data.CandleData) MPPointD(com.github.mikephil.charting.utils.MPPointD)

Aggregations

CandleData (com.github.mikephil.charting.data.CandleData)4 CandleEntry (com.github.mikephil.charting.data.CandleEntry)3 ICandleDataSet (com.github.mikephil.charting.interfaces.datasets.ICandleDataSet)3 ArrayList (java.util.ArrayList)3 CandleDataSet (com.github.mikephil.charting.data.CandleDataSet)2 Paint (android.graphics.Paint)1 RealmCandleDataSet (com.github.mikephil.charting.data.realm.implementation.RealmCandleDataSet)1 Highlight (com.github.mikephil.charting.highlight.Highlight)1 MPPointD (com.github.mikephil.charting.utils.MPPointD)1 RealmDemoData (com.xxmassdeveloper.mpchartexample.custom.RealmDemoData)1