Search in sources :

Example 1 with CandleDataSet

use of com.github.mikephil.charting.data.CandleDataSet in project carat by amplab.

the class CandleStickChart method drawData.

@Override
protected void drawData() {
    ArrayList<CandleDataSet> dataSets = mData.getDataSets();
    // pre allocate
    float[] shadowPoints = new float[4];
    float[] bodyPoints = new float[4];
    for (int i = 0; i < mData.getDataSetCount(); i++) {
        CandleDataSet dataSet = dataSets.get(i);
        ArrayList<CandleEntry> entries = dataSet.getYVals();
        mRenderPaint.setStrokeWidth(dataSet.getShadowWidth());
        for (int j = 0; j < entries.size() * mPhaseX; j++) {
            // get the color that is specified for this position from
            // the DataSet, this will reuse colors, if the index is out
            // of bounds
            mRenderPaint.setColor(dataSet.getColor(j));
            // get the entry
            CandleEntry e = entries.get(j);
            // transform the entries values for shadow and body
            transformShadow(shadowPoints, e);
            transformBody(bodyPoints, e, dataSet.getBodySpace());
            float xShadow = shadowPoints[0];
            float leftBody = bodyPoints[0];
            float rightBody = bodyPoints[2];
            float high = shadowPoints[1];
            float low = shadowPoints[3];
            float open = bodyPoints[1];
            float close = bodyPoints[3];
            if (isOffContentRight(leftBody))
                break;
            // make sure the lines don't do shitty things outside bounds
            if (isOffContentLeft(rightBody) && isOffContentTop(low) && isOffContentBottom(high))
                continue;
            // draw the shadow
            mDrawCanvas.drawLine(xShadow, low, xShadow, high, mRenderPaint);
            // decide weather the body is hollow or filled
            if (open > close) {
                mRenderPaint.setStyle(Paint.Style.FILL);
                // draw the body
                mDrawCanvas.drawRect(leftBody, close, rightBody, open, mRenderPaint);
            } else {
                mRenderPaint.setStyle(Paint.Style.STROKE);
                // draw the body
                mDrawCanvas.drawRect(leftBody, open, rightBody, close, mRenderPaint);
            }
        }
    }
}
Also used : CandleEntry(com.github.mikephil.charting.data.CandleEntry) CandleDataSet(com.github.mikephil.charting.data.CandleDataSet) Paint(android.graphics.Paint)

Example 2 with CandleDataSet

use of com.github.mikephil.charting.data.CandleDataSet 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 3 with CandleDataSet

use of com.github.mikephil.charting.data.CandleDataSet in project carat by amplab.

the class CandleStickChart method drawHighlights.

@Override
protected void drawHighlights() {
    for (int i = 0; i < mIndicesToHightlight.length; i++) {
        // get the
        int xIndex = mIndicesToHightlight[i].getXIndex();
        // x-position
        CandleDataSet set = mData.getDataSetByIndex(mIndicesToHightlight[i].getDataSetIndex());
        if (set == null)
            continue;
        mHighlightPaint.setColor(set.getHighLightColor());
        CandleEntry e = set.getEntryForXIndex(xIndex);
        if (e == null)
            continue;
        float low = e.getLow() * mPhaseY;
        float high = e.getHigh() * mPhaseY;
        float[] vertPts = new float[] { xIndex, mYChartMax, xIndex, mYChartMin, xIndex + 1f, mYChartMax, xIndex + 1f, mYChartMin };
        float[] horPts = new float[] { 0, low, mDeltaX, low, 0, high, mDeltaX, high };
        mTrans.pointValuesToPixel(vertPts);
        mTrans.pointValuesToPixel(horPts);
        // draw the vertical highlight lines
        mDrawCanvas.drawLines(vertPts, mHighlightPaint);
        // draw the horizontal highlight lines
        mDrawCanvas.drawLines(horPts, mHighlightPaint);
    }
}
Also used : CandleEntry(com.github.mikephil.charting.data.CandleEntry) CandleDataSet(com.github.mikephil.charting.data.CandleDataSet) Paint(android.graphics.Paint)

Example 4 with CandleDataSet

use of com.github.mikephil.charting.data.CandleDataSet 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)

Aggregations

CandleDataSet (com.github.mikephil.charting.data.CandleDataSet)4 CandleEntry (com.github.mikephil.charting.data.CandleEntry)4 Paint (android.graphics.Paint)3 CandleData (com.github.mikephil.charting.data.CandleData)2 ArrayList (java.util.ArrayList)2 ICandleDataSet (com.github.mikephil.charting.interfaces.datasets.ICandleDataSet)1